public ImagePixel GetPSFFit(int x, int y, int fitMatrixSize, PSFFittingMethod method, out PSFFit psfFit) { psfFit = new PSFFit(x, y); psfFit.FittingMethod = method; int dimention = 2 * (fitMatrixSize / 2) + 1; uint[,] data = new uint[dimention, dimention]; int halfWidth = dimention / 2; #if ASTROMETRY_DEBUG Trace.Assert(2 * halfWidth + 1 == dimention); #endif PixelAreaOperation2(x, y, halfWidth, delegate(int x1, int y1, uint z) { data[x1 - x + halfWidth, y1 - y + halfWidth] = z; }); psfFit.Fit(data); if (psfFit.IsSolved) { ImagePixel psfPixel = new ImagePixel((int)Math.Min(m_Pixelmap.MaxSignalValue, (uint)Math.Round(psfFit.IMax)), psfFit.XCenter, psfFit.YCenter); psfPixel.SignalNoise = psfFit.Certainty; return(psfPixel); } return(null); }
public ImagePixel GetPSFFit(int x, int y, PSFFittingMethod method, out PSFFit psfFit) { StarMapFeature feature = GetFeatureInRadius(x, y, 5); int dimention = 9; if (CoreAstrometrySettings.Default.SearchAreaAuto) { if (feature != null) { if (feature.PixelCount > 25) { dimention = 9; } if (feature.PixelCount > 40) { dimention = 11; } if (feature.PixelCount > 60) { dimention = 13; } if (feature.PixelCount > 80) { dimention = 15; } } } else { dimention = 2 * ((int)Math.Round(CoreAstrometrySettings.Default.SearchArea) / 2) + 1; } return(GetPSFFit(x, y, dimention, method, out psfFit)); }
private void picTarget1Pixels_MouseMove(object sender, MouseEventArgs e) { if (m_AutoStarsInArea != null && m_AutoStarsInArea.Count > 1) { float x = e.X / 7.0f; float y = e.Y / 7.0f; PSFFit star = m_AutoStarsInArea.Find( s => { return(Math.Abs(s.XCenter - x + 0.5f) < 2.0f && Math.Abs(s.YCenter - y + 0.5) < 2.0f); } ); if (star != null && m_Gaussian.UniqueId != star.UniqueId) { newStar = star; Cursor = Cursors.Hand; } else { Cursor = Cursors.Default; } } }
private void HandleHotPixelDefinitionClick(MouseEventArgs e) { var pixels = frmFullSizePreview.CurrFrame.GetPixelsArea(e.X, e.Y, 35); PSFFit fit = new PSFFit(e.X, e.Y); fit.Fit(pixels); if (fit.IsSolved && fit.Certainty > 1 && fit.IMax > frmFullSizePreview.CurrFrame.MaxSignalValue / 2.0) { var sample = frmFullSizePreview.CurrFrame.GetPixelsArea((int)Math.Round(fit.XCenter), (int)Math.Round(fit.YCenter), 7); HotPixelCorrector.RegisterHotPixelSample(sample, frmFullSizePreview.CurrFrame.Pixelmap.MaxSignalValue); m_ExpectHotPixelDefinition = false; FrameAdjustmentsPreview.Instance.ExpectHotPixelClick(false, true); pnlHotPixelControls.Enabled = true; HotPixelCorrector.LocateHotPixels(frmFullSizePreview.CurrFrame, Math.Max(0, tbDepth.Value)); FrameAdjustmentsPreview.Instance.Update(); } else { MessageBox.Show( ParentForm, "The location you clicked doesn't appear to contain a hot pixel. Please try again.\r\n\r\nIf necessary adjust the brightness and contrast of the image first.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void PSFPhotometry(FitInfo astrometricFit, List <IStar> catalogueStars, AstroImage currentAstroImage, Rectangle osdRectToExclude, Rectangle rectToInclude, bool limitByInclusion) { StringBuilder output = new StringBuilder(); foreach (PlateConstStarPair pair in astrometricFit.AllStarPairs) { uint[,] data = currentAstroImage.GetMeasurableAreaPixels( (int)Math.Round(pair.x), (int)Math.Round(pair.y), 9); if (limitByInclusion && !rectToInclude.Contains((int)pair.x, (int)pair.y)) { continue; } if (!limitByInclusion && osdRectToExclude.Contains((int)pair.x, (int)pair.y)) { continue; } PSFFit gaussian = new PSFFit((int)Math.Round(pair.x), (int)Math.Round(pair.y)); gaussian.Fit(data); if (gaussian.IsSolved) { IStar star = catalogueStars.Find(s => s.StarNo == pair.StarNo); if (star != null && !double.IsNaN(star.MagR)) { output.AppendLine(string.Format("{0}, {1}, {2}, {3}, {4}", pair.StarNo, star.MagR, gaussian.R0, gaussian.IMax, gaussian.I0)); } } } File.WriteAllText(@"C:\PSF_Photo.csv", output.ToString()); }
public frmTargetPSFViewerForm(VideoController videoController) { InitializeComponent(); m_VideoController = videoController; m_PSFFit = null; cbMeaMethod.SelectedIndex = 0; }
public ObjectClickEventArgs(ImagePixel pixel, PSFFit gausian, Point location, bool shiftHeld, bool ctrlHeld, MouseEventArgs mouseEventArgs) { ClickLocation = location; Pixel = pixel; Gausian = gausian; Shift = shiftHeld; Control = ctrlHeld; MouseEventArgs = mouseEventArgs; }
internal static TrackedObjectConfig Load(BinaryReader reader) { TrackedObjectConfig instance = new TrackedObjectConfig(); byte version = reader.ReadByte(); if (version > 0) { instance.TrackingType = (TrackingType)reader.ReadInt32(); instance.MeasureThisObject = reader.ReadBoolean(); instance.ApertureInPixels = reader.ReadSingle(); instance.PsfFitMatrixSize = reader.ReadInt32(); instance.ApertureStartingX = reader.ReadSingle(); instance.ApertureStartingY = reader.ReadSingle(); instance.OriginalFieldCenterX = reader.ReadInt32(); instance.OriginalFieldCenterY = reader.ReadInt32(); bool hasGaussian = reader.ReadBoolean(); if (hasGaussian) { instance.Gaussian = PSFFit.Load(reader); } instance.PositionTolerance = reader.ReadSingle(); instance.IsWeakSignalObject = reader.ReadBoolean(); instance.ApertureMatrixX0 = reader.ReadSingle(); instance.ApertureMatrixY0 = reader.ReadSingle(); instance.ApertureDX = reader.ReadSingle(); instance.ApertureDY = reader.ReadSingle(); instance.AutoStarsInArea = new List <PSFFit>(); int autoStarsInArea = reader.ReadInt32(); for (int i = 0; i < autoStarsInArea; i++) { instance.AutoStarsInArea.Add(PSFFit.Load(reader)); } if (version > 1) { instance.RefinedFWHM = reader.ReadSingle(); if (version > 2) { instance.IsFixedAperture = reader.ReadBoolean(); if (version > 3) { instance.GroupId = reader.ReadInt32(); } } } } return(instance); }
public static double DistanceTo(this PSFFit psf1, PSFFit psf2) { if (psf2 == null) { return(double.NaN); } else { return(Math.Sqrt(Math.Pow(psf1.XCenter - psf2.XCenter, 2) + Math.Pow(psf1.YCenter - psf2.YCenter, 2))); } }
internal bool IdentifyBrightObject(PSFFit fit1, PSFFit fit2, float minStarCertainty, out TrackedObjectLight obj1, out TrackedObjectLight obj2, out IImagePixel center1, out IImagePixel center2) { double brightness1 = (fit1.Certainty > minStarCertainty ? fit1.Brightness : 1); double brightness2 = (fit2.Certainty > minStarCertainty ? fit2.Brightness : 1); double bDiff = Math.Abs(brightness1 - brightness2); double bRatio = bDiff / Math.Max(brightness1, brightness2); if (bRatio > 0.5) { bool fit1Brighter = brightness1 > brightness2; bool oldFit1Brighter = LastCenterObject1.Brightness > LastCenterObject2.Brightness; double oldDeltaXBrightFaint = oldFit1Brighter ? LastCenterObject1.XDouble - LastCenterObject2.XDouble : LastCenterObject2.XDouble - LastCenterObject1.XDouble; double oldDeltaYBrightFaint = oldFit1Brighter ? LastCenterObject1.YDouble - LastCenterObject2.YDouble : LastCenterObject2.YDouble - LastCenterObject1.YDouble; if (!(fit1Brighter ^ oldFit1Brighter)) { // 1 == 1; 2 == 2 if (fit1Brighter) { center1 = new ImagePixel((int)brightness1, fit1.XCenter, fit1.YCenter); center2 = new ImagePixel((int)brightness2, fit1.XCenter - oldDeltaXBrightFaint, fit1.YCenter - oldDeltaYBrightFaint); return(Match1122(out obj1, out obj2)); } else { center1 = new ImagePixel((int)brightness2, fit2.XCenter, fit2.YCenter); center2 = new ImagePixel((int)brightness1, fit2.XCenter - oldDeltaXBrightFaint, fit2.YCenter - oldDeltaYBrightFaint); return(Match1122(out obj1, out obj2)); } } else { // 1 == 2; 2 == 1 if (fit1Brighter) { center2 = new ImagePixel((int)brightness1, fit1.XCenter, fit1.YCenter); center1 = new ImagePixel((int)brightness2, fit1.XCenter - oldDeltaXBrightFaint, fit1.YCenter - oldDeltaYBrightFaint); return(Match1212(out obj1, out obj2)); } else { center2 = new ImagePixel((int)brightness2, fit2.XCenter, fit2.YCenter); center1 = new ImagePixel((int)brightness1, fit2.XCenter - oldDeltaXBrightFaint, fit2.YCenter - oldDeltaYBrightFaint); return(Match1212(out obj1, out obj2)); } } } center1 = null; center2 = null; return(NoMatch(out obj1, out obj2)); }
public void SetTrackedObjectMatch(PSFFit psfFitMatched) { PSFFit = psfFitMatched; Center = new ImagePixel((int)psfFitMatched.IMax, psfFitMatched.XCenter, psfFitMatched.YCenter); IsLocated = true; NotMeasuredReasons = NotMeasuredReasons.TrackedSuccessfully; if (PSFFit != null && PSFFit.IsSolved) { LastKnownGoodPosition = new ImagePixel(Center.Brightness, Center.XDouble, Center.YDouble); LastKnownGoodPsfCertainty = PSFFit.Certainty; } }
public PSFFit GetGaussian2() { using (MemoryStream memStr = new MemoryStream()) { var wrt = new BinaryWriter(memStr); BinarySerialize2(wrt); memStr.Position = 0; var rdr = new BinaryReader(memStr); return(PSFFit.Load(rdr)); } }
public override void MouseClick(ObjectClickEventArgs e) { if (m_OperationState == SpectroscopyState.ChoosingStar && e.Gausian != null && e.Gausian.IsSolved && e.Gausian.Certainty > 0.2) { float bestAngle = m_SpectroscopyController.LocateSpectraAngle(e.Gausian); if (float.IsNaN(bestAngle)) { SelectedStar = new ImagePixel(e.Gausian.XCenter, e.Gausian.YCenter); SelectedStarFWHM = e.Gausian.FWHM; m_SelectedStarGaussian = e.Gausian; MeasurementAreaWing = (int)(2 * Math.Ceiling(SelectedStarFWHM)); BackgroundAreaWing = MeasurementAreaWing; BackgroundAreaGap = 5; SelectedAnglePoint = Point.Empty; m_ControlPanel.ClearSpectra(); m_OperationState = SpectroscopyState.ChoosingAngleManually; } else { SelectedStar = new ImagePixel(e.Gausian.XCenter, e.Gausian.YCenter); SelectedStarFWHM = e.Gausian.FWHM; m_SelectedStarGaussian = e.Gausian; MeasurementAreaWing = (int)(2 * Math.Ceiling(SelectedStarFWHM)); BackgroundAreaWing = MeasurementAreaWing; BackgroundAreaGap = 5; SetBestAngle(bestAngle); } m_VideoController.RedrawCurrentFrame(false, true); } else if (m_OperationState == SpectroscopyState.ChoosingAngleManually && SelectedStar != null) { double atanAgnle = 180 * Math.Atan((SelectedStar.YDouble - e.Pixel.YDouble) / (e.Pixel.XDouble - SelectedStar.XDouble)) / Math.PI; if (atanAgnle < 0) { atanAgnle = 360 + atanAgnle; } int roughAngle = (int)atanAgnle; float bestAngle = m_SpectroscopyController.LocateSpectraAngle(e.Gausian, roughAngle); if (!float.IsNaN(bestAngle)) { SetBestAngle(bestAngle); m_VideoController.RedrawCurrentFrame(false, true); } } }
internal frmAddOrEditSingleTarget(int objectId, ImagePixel center, PSFFit gaussian, LCStateMachine state, VideoController videoController) { InitializeComponent(); m_VideoController = videoController; m_AutocenteredApertureAvailable = true; Text = "Add Object"; btnAdd.Text = "Add"; btnDontAdd.Text = "Don't Add"; btnDelete.Visible = false; m_IsEdit = false; nudFitMatrixSize.Value = 11; nudFitMatrixSize.Maximum = 15; m_ObjectId = objectId; m_State = state; m_AstroImage = m_State.VideoOperation.m_StackedAstroImage; ObjectToAdd = new TrackedObjectConfig(); m_Center = new ImagePixel(center); Initialize(); if (rbOccultedStar.Enabled) { SelectedObjectType = TrackingType.OccultedStar; } else { SelectedObjectType = TrackingType.GuidingStar; } // Apply filtering to the processing pixels according to the configured default filter value int matirxSize = (int)nudFitMatrixSize.Value; GetFitInMatrix(gaussian, ref matirxSize); nudFitMatrixSize.Maximum = matirxSize; if (SelectedObjectType != TrackingType.OccultedStar) { SetHeightAndType(); } }
internal void OpenSpectraFile(string fileName) { if (File.Exists(fileName)) { SpectraFile spectraFile = SpectraFile.Load(fileName); if (spectraFile != null) { DisplaySpectra(spectraFile.Data, null, m_DisplaySettings, fileName); string videoFile = m_VideoController.GetVideoFileMatchingLcFile(spectraFile.Header.PathToVideoFile, fileName); if (!string.IsNullOrEmpty(videoFile) && File.Exists(videoFile)) { if (m_VideoController.OpenVideoFile(videoFile)) { TangraContext.Current.CanPlayVideo = false; } } else { // NOTE: No video file found, just show the saved averaged frame TangraContext.Current.Reset(); if (spectraFile.Data.MeasurementInfo.FrameBitmapPixels != null && spectraFile.Data.MeasurementInfo.FrameBitmapPixels.Length > 0) { if (m_VideoController.SingleBitmapFile(spectraFile.Data.MeasurementInfo.FrameBitmapPixels, spectraFile.Header.Width, spectraFile.Header.Height)) { TangraContext.Current.CanPlayVideo = false; m_VideoController.UpdateViews(); PSFFit.SetDataRange(spectraFile.Header.BitPix, spectraFile.Header.DataAav16NormVal); } } TangraContext.Current.CanPlayVideo = false; TangraContext.Current.CanScrollFrames = false; } TangraContext.Current.FileName = Path.GetFileName(fileName); TangraContext.Current.FileFormat = spectraFile.Header.SourceInfo; m_VideoController.UpdateViews(); } RegisterRecentSpectraFile(fileName); } }
private void CalculateSingleObjectPSF() { m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_OriginalCenter.X, m_OriginalCenter.Y, 35); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_OriginalCenter.X, m_OriginalCenter.Y, 35); var psfFit = new PSFFit(m_OriginalCenter.X, m_OriginalCenter.Y); psfFit.Fit(m_ProcessingPixels); if (psfFit.IsSolved) { m_Gaussian = psfFit; m_FWHM = (float)m_Gaussian.FWHM; m_X0 = m_Gaussian.X0_Matrix; m_Y0 = m_Gaussian.Y0_Matrix; m_X0Center = (float)psfFit.XCenter; m_Y0Center = (float)psfFit.YCenter; if (m_Aperture == null) { if (TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM) { m_Aperture = (float)(m_Gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture); } else { m_Aperture = (float)(TangraConfig.Settings.Photometry.DefaultSignalAperture); } } else if ( TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM && m_Aperture < (float)(psfFit.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture)) { // When the default aperture size is in FWHM we always use the largest aperture so far m_Aperture = (float)(psfFit.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture); } nudAperture1.SetNUDValue(m_Aperture.Value); m_Aperture1 = null; m_Aperture2 = null; m_DoubleGaussian = null; } }
internal NotMeasuredReasons DoNonLinearProfileFittingPhotometry( PSFFit fit, uint[,] matrix, int x0Int, int y0Int, float x0, float y0, float aperture, int matrixSize, bool useNumericalQadrature, bool isFullyDisappearingOccultedStar, uint[,] backgroundArea, bool mayBeOcculted /* Some magic based on a pure guess */, double refinedFWHM, float bgAnnulusFactor) { double distance = ImagePixel.ComputeDistance(fit.XCenter, x0, fit.YCenter, y0); double tolerance = isFullyDisappearingOccultedStar ? m_TimesHigherPositionToleranceForFullyOccultedStars * m_PositionTolerance : m_PositionTolerance; if (fit.IsSolved) { SetPsfFitReading(fit, aperture, useNumericalQadrature, backgroundArea, bgAnnulusFactor); } else { m_Aperture = aperture; m_XCenter = (float)fit.X0_Matrix; m_YCenter = (float)fit.Y0_Matrix; m_TotalReading = 0; m_TotalBackground = 0; } if (!fit.IsSolved || // The PSF solution failed, mark the reading invalid (distance > tolerance && !mayBeOcculted) || // If this doesn't look like a full disappearance, then make the reading invalid (fit.FWHM < 0.5 * refinedFWHM || fit.FWHM > 1.5 * refinedFWHM) // The FWHM is too small or too large, make the reading invalid ) { return(!fit.IsSolved ? NotMeasuredReasons.MeasurementPSFFittingFailed : (distance > tolerance && !mayBeOcculted) ? NotMeasuredReasons.DistanceToleranceTooHighForNonFullDisappearingOccultedStar : NotMeasuredReasons.FWHMOutOfRange); } else { return(NotMeasuredReasons.MeasuredSuccessfully); } }
public double GetIntencity(ImagePixel center, out bool isSaturated) { isSaturated = false; uint[,] data = m_CurrentAstroImage.GetMeasurableAreaPixels(center.X, center.Y, 17); PSFFit fit = new PSFFit(center.X, center.Y); fit.Fit(data, PSF_FIT_AREA_SIZE); if (!fit.IsSolved) { return(double.NaN); } int areaSize = m_Filter == TangraConfig.PreProcessingFilter.NoFilter ? 17 : 19; int centerX = (int)Math.Round(center.XDouble); int centerY = (int)Math.Round(center.YDouble); data = m_CurrentAstroImage.GetMeasurableAreaPixels(centerX, centerY, areaSize); uint[,] backgroundPixels = m_CurrentAstroImage.GetMeasurableAreaPixels(centerX, centerY, 35); m_Measurer.MeasureObject( center, data, backgroundPixels, m_CurrentAstroImage.Pixelmap.BitPixCamera, m_Filter, m_PhotometryReductionMethod, m_PsfQuadrature, m_PsfFittingMethod, m_MeasurementAperture ?? (float)Aperture(fit.FWHM), fit.FWHM, (float)m_EmpericalFWHM, new FakeIMeasuredObject(fit), null, null, false); isSaturated = m_Measurer.HasSaturatedPixels; return(m_Measurer.TotalReading - m_Measurer.TotalBackground); }
internal NotMeasuredReasons DoLinearProfileFittingOfAveragedMoodelPhotometry( PSFFit fit, uint[,] matrix, int x0Int, int y0Int, float x0, float y0, float modelFWHM, float aperture, int matrixSize, bool useNumericalQadrature, bool isFullyDisappearingOccultedStar, uint[,] backgroundArea, bool mayBeOcculted /* Some magic based on a pure guess */, float bgAnnulusFactor, IBackgroundModelProvider backgroundModel) { double distance = ImagePixel.ComputeDistance(fit.XCenter, x0, fit.YCenter, y0); double tolerance = isFullyDisappearingOccultedStar ? m_TimesHigherPositionToleranceForFullyOccultedStars * m_PositionTolerance : m_PositionTolerance; // We first go and do the measurement anyway if (fit.IsSolved) { SetPsfFitReading(fit, aperture, useNumericalQadrature, backgroundArea, bgAnnulusFactor, backgroundModel); } else { m_Aperture = aperture; m_XCenter = (float)fit.X0_Matrix; m_YCenter = (float)fit.Y0_Matrix; m_TotalReading = 0; m_TotalBackground = 0; } if (!fit.IsSolved || // The PSF solution failed, mark the reading invalid (distance > tolerance && !mayBeOcculted) // If this doesn't look like a full disappearance, then make the reading invalid ) { return(!fit.IsSolved ? NotMeasuredReasons.MeasurementPSFFittingFailed : NotMeasuredReasons.DistanceToleranceTooHighForNonFullDisappearingOccultedStar); } else { return(NotMeasuredReasons.MeasuredSuccessfully); } }
private void PlotAperturePreview() { if (m_MeasurementContext.ObjectToMeasure != null) { float x0 = m_MeasurementContext.ObjectToMeasure.X0; float y0 = m_MeasurementContext.ObjectToMeasure.Y0; // x0 and y0 were measured on the first frame but we may have moved to a different frame due to positioning to the first frame of integration period // so we determine the position of the object on the current frame in order to draw the aperture nicely centered var fit = new PSFFit((int)x0, (int)y0); fit.Fit(m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaPixels((int)x0, (int)y0)); if (fit.IsSolved) { x0 = (float)fit.XCenter; y0 = (float)fit.YCenter; } byte[,] bmpPixels = m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaDisplayBitmapPixels((int)x0, (int)y0, 85); Bitmap bmp = Pixelmap.ConstructBitmapFromBitmapPixels(bmpPixels, 85, 85); using (Graphics g = Graphics.FromImage(pboxAperturePreview.Image)) { g.DrawImage(bmp, 0, 0); float xCenter = (x0 - (int)x0) + 42; float yCenter = (y0 - (int)y0) + 42; float radius = (float)nudAperture.Value; g.DrawEllipse(Pens.YellowGreen, xCenter - radius, yCenter - radius, 2 * radius, 2 * radius); radius = (float)(nudAperture.Value + nudGap.Value); g.DrawEllipse(Pens.YellowGreen, xCenter - radius, yCenter - radius, 2 * radius, 2 * radius); radius = (float)(nudAperture.Value + nudGap.Value + nudAnnulus.Value); g.DrawEllipse(Pens.YellowGreen, xCenter - radius, yCenter - radius, 2 * radius, 2 * radius); g.Save(); } pboxAperturePreview.Invalidate(); } }
private void frmRunMultiFrameSpectroscopy_Load(object sender, EventArgs e) { IImagePixel starCenter = m_VideoOperation.SelectedStar; m_SpectraReader = new SpectraReader(m_AstroImage, m_VideoOperation.SelectedStarBestAngle, 1); m_Spectra = m_SpectraReader.ReadSpectra((float)starCenter.XDouble, (float)starCenter.YDouble, (int)nudAreaWing.Value, (int)nudBackgroundWing.Value, (int)nudBackgroundGap.Value, PixelCombineMethod.Average); m_Mapper = new RotationMapper(m_AstroImage.Width, m_AstroImage.Height, m_VideoOperation.SelectedStarBestAngle); uint[,] pixels = m_AstroImage.GetMeasurableAreaPixels(starCenter.X, starCenter.Y, 35); m_ZeroOrderPsf = new PSFFit(starCenter.X, starCenter.Y); m_ZeroOrderPsf.Fit(pixels); m_Spectra.ZeroOrderFWHM = (float)m_ZeroOrderPsf.FWHM; PlotMeasurementAreas(); PlotAlignTarget(); nudDivisor.SetNUDValue((decimal)m_AstroImage.Pixelmap.MaxSignalValue); nudMultiplier.Value = 1024; }
public void Fit(uint[,] pixels, PSFFit star1, PSFFit star2) { int dataMatrixSize = pixels.GetLength(0); int offset = (dataMatrixSize - star1.MatrixSize) / 2; m_Star1Center = new ImagePixel(star1.Brightness, star1.X0_Matrix + offset, star1.Y0_Matrix + offset); m_Star1MinDistance = star1.FWHM * 2.0; if (star2 != null) { offset = (dataMatrixSize - star2.MatrixSize) / 2; m_Star2Center = new ImagePixel(star2.Brightness, star2.X0_Matrix + offset, star2.Y0_Matrix + offset); m_Star2MinDistance = star2.FWHM * 2.0; } else { m_Star2Center = null; } Fit(pixels); }
internal void SelectStar(PlateConstStarPair selectedPair, PSFFit psfFit) { if (selectedPair != null) { lblStarNo.Text = selectedPair.StarNo.ToString(); lblRA.Text = AstroConvert.ToStringValue(selectedPair.RADeg / 15.0, "HH MM SS.TT"); lblDE.Text = AstroConvert.ToStringValue(selectedPair.DEDeg, "+DD MM SS.T"); lblX.Text = selectedPair.x.ToString("0.00"); lblY.Text = selectedPair.y.ToString("0.00"); lblResRA.Text = string.Format("{0}\"", selectedPair.FitInfo.ResidualRAArcSec.ToString("0.00")); lblResDE.Text = string.Format("{0}\"", selectedPair.FitInfo.ResidualDEArcSec.ToString("0.00")); m_SelectedPSF = psfFit; } else { m_SelectedPSF = null; } pnlSelectedStar.Visible = selectedPair != null; }
private void picTarget1Pixels_Click(object sender, EventArgs e) { if (newStar != null) { m_Gaussian = newStar; m_X0 = (float)newStar.XCenter; m_Y0 = (float)newStar.YCenter; m_FWHM = (float)newStar.FWHM; nudFitMatrixSize.ValueChanged -= nudFitMatrixSize_ValueChanged; try { nudFitMatrixSize.SetNUDValue(newStar.MatrixSize); } finally { nudFitMatrixSize.ValueChanged += nudFitMatrixSize_ValueChanged; } PlotSingleTargetPixels(); PlotGaussian(); } }
private void TrackSingleStar(int frameNo, IAstroImage astroImage) { TrackedStar.NewFrame(); float expectedX; float expectedY; GetExpectedXY(out expectedX, out expectedY); uint[,] pixels = astroImage.GetPixelsArea((int)expectedX, (int)expectedY, FIT_AREA); // There is only one object in the area, just do a wide fit followed by a fit with the selected matrix size PSFFit gaussian = new PSFFit((int)expectedX, (int)expectedY); gaussian.Fit(pixels, FIT_AREA); IImagePixel firstCenter = new ImagePixel((int)gaussian.XCenter, (int)gaussian.YCenter); pixels = astroImage.GetPixelsArea(firstCenter.X, firstCenter.Y, FIT_AREA); gaussian = new PSFFit(firstCenter.X, firstCenter.Y); gaussian.Fit(pixels, TrackedStar.PsfFitMatrixSize); if (gaussian.IsSolved) { TrackedStar.PSFFit = gaussian; TrackedStar.ThisFrameX = (float)gaussian.XCenter; TrackedStar.ThisFrameY = (float)gaussian.YCenter; TrackedStar.ThisSignalLevel = (float)(gaussian.IMax - gaussian.I0); TrackedStar.ThisFrameCertainty = (float)gaussian.Certainty; TrackedStar.SetIsLocated(true, NotMeasuredReasons.TrackedSuccessfully); } else { TrackedStar.ThisFrameX = expectedX; TrackedStar.ThisFrameY = expectedY; TrackedStar.ThisFrameCertainty = (float)gaussian.Certainty; Trace.WriteLine(string.Format("Frame {0}: Cannot confirm target {1} [SingleStar]. Cannot solve second PSF", m_FrameNo, TrackedStar.TargetNo)); TrackedStar.SetIsLocated(false, NotMeasuredReasons.PSFFittingFailed); } }
public void Test12BitData() { string DATA_SER = "EQAAABEAAABqAQAAkAEAABgBAACuAQAAnQEAAMgBAABfAQAAbQEAALYBAAAJAQAAcAEAACMBAAA5AQAAWAEAAFMBAADVAQAAkQEAAFABAAAbAQAAYgEAAFwBAABTAQAAMgEAAH8BAABSAQAA1AEAAGoBAAC6AQAAnAEAAN4BAACKAQAAswEAAKUBAABhAQAAvwEAAE0BAABLAQAA9QAAAIoBAABWAQAAkwEAAOwBAACCAQAAxQEAAJYBAAD1AQAApgEAAPcBAACuAQAAawEAAEgBAAAZAQAAXAEAAF4BAAD0AQAA1QEAAH8BAADbAQAARwEAALkBAAAhAgAASgIAAMMBAAANAgAApgEAAGgBAAAWAQAADQEAAB4BAABiAQAAagEAABsBAABYAQAAuQEAAPgBAACgAgAAdgIAAMsCAAAKAwAABQMAALkCAAD9AQAAdgEAAKABAABoAQAAdwEAAD4BAABqAQAAaAEAAKUBAAC2AQAApgEAAFgDAACAAwAA6gMAALgEAACbBAAAMwMAAMMCAAAEAgAAoAEAAJYBAAAyAQAAWQEAADkBAABbAQAAdgEAAHwBAACpAQAAewIAACcEAABiBQAATgYAAL8FAABIBAAAkgMAALkBAAClAQAA2wEAANgAAAB8AQAAfAEAAO8AAABEAQAAjgEAAPcBAABEAgAASAMAAE0FAABLBgAADwYAACoEAAArAwAAugEAAEsBAACfAQAAfwEAABgBAABSAQAALQEAABABAADVAQAAWwEAANIBAACOAgAA8AMAANIFAAAuBQAAUwMAACQCAADaAQAAogEAAKMBAABFAQAA/gAAALMBAABNAQAAAQEAAG4BAAAyAQAAcwEAAE8CAAC8AgAA0wMAANoDAADDAgAAGgIAAOUBAAC/AQAAUwEAADUBAACsAQAADwEAACEBAADxAAAAYgEAABABAACrAQAApgEAANcBAAD6AQAAwwIAABACAABtAQAAEAEAAF4BAAB0AQAAWAEAAA8BAABkAQAAzwAAAD4BAABuAQAABgEAAOsBAACjAQAA9wAAAJEBAABiAQAAOwEAAJcBAADxAAAAXwEAAIsBAACvAQAAQQEAAGoBAABFAQAAeQEAALMBAAApAQAAbgEAAFYBAABtAQAA5gEAAJEBAAAkAQAA3gAAADMBAACzAQAAEwEAABkBAABLAQAAQQEAAE0BAACvAAAAzAAAACkBAABeAQAADwEAAFMBAACIAQAAUgEAANIBAACjAQAAEwEAADgBAAD+AAAAMwEAAEEBAAAqAQAAPAEAAF8BAABnAQAAdwEAAGoBAAAAAQAAOAEAAKUBAAAMAQAArAAAAAEBAABlAQAA4wAAADMBAACiAQAAHgEAACkBAAAqAQAAGAEAACcBAAADAQAAlwEAAEIBAAA8AQAA3gAAADMBAACoAQAAegEAAGEBAAApAQAAlgEAAHwBAABZAQAAIQEAAGIBAADaAAAAPgEAADIBAAA/AQAAZwEAAIoBAAA5AQAAywAAAGoBAACBAQAAIQEAAEgBAAA8AQAA"; uint[,] data = DATA_SER.FromBase64String(); int width = data.GetLength(0); int height = data.GetLength(1); int MAX = 255; uint[,] data_8bit = new uint[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { data_8bit[x, y] = (uint)Math.Max(0, Math.Min(MAX, Math.Round(data[x, y] * MAX * 1.0f / 4095))); } } PSFFit.DataRange = PSFFittingDataRange.DataRange12Bit; var psfFit8bit = new PSFFit(100, 100); psfFit8bit.Fit(data_8bit); Console.WriteLine(string.Format("8Bit: ({0}, {1})", psfFit8bit.XCenter, psfFit8bit.YCenter)); PSFFit.DataRange = PSFFittingDataRange.DataRange12Bit; var psfFit = new PSFFit(100, 100); psfFit.Fit(data); Console.WriteLine(string.Format("12Bit: ({0}, {1})", psfFit.XCenter, psfFit.YCenter)); Assert.AreEqual(psfFit8bit.XCenter, psfFit.XCenter, 0.01); Assert.AreEqual(psfFit8bit.YCenter, psfFit.YCenter, 0.01); }
internal static PSFFit GetPSFFitForPeakPixel( uint[,] data, PotentialStarStruct starToTest, float aboveNoiseLevelRequired, double minFWHM, double maxFWHM) { int STAR_MATRIX_FIT = TangraConfig.Settings.Special.StarFinderFitArea; double MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER = TangraConfig.Settings.Special.StarFinderMinDistanceOfPeakPixelFromCenter; PSFFit fit = new PSFFit(starToTest.X, starToTest.Y); int fitMatrix = (int)Math.Min(data.GetLength(0), STAR_MATRIX_FIT + 2); // Get a matrix with 1 pixel larger each way and set the border pixels to zero fit.Fit(data, fitMatrix, starToTest.X, starToTest.Y, true); if (fit.IsSolved) { double distanceFromCenter = ImagePixel.ComputeDistance(fit.X0_Matrix, fitMatrix / 2, fit.Y0_Matrix, fitMatrix / 2); if (fit.Certainty > 0 && fit.FWHM >= minFWHM && fit.FWHM <= maxFWHM && distanceFromCenter < MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER && fit.IMax > aboveNoiseLevelRequired) { //not good for lost tracking allow higher FWHM // This object passes all tests to be furhter considered as a star return(fit); } } return(null); }
internal frmAddOrEditMutualEventsTarget(int objectId, ImagePixel center, PSFFit gaussian, LCStateMachine state, VideoController videoController, bool tryAutoDoubleFind) { InitializeComponent(); m_VideoController = videoController; m_TryAutoDoubleFind = tryAutoDoubleFind; Text = "Add 'Mutual Event' Target"; btnAdd.Text = "Add"; btnDontAdd.Text = "Don't Add"; btnDelete.Visible = false; m_IsEdit = false; m_ObjectId = objectId; m_GroupId = objectId; // For Group Id we use the next object id m_State = state; m_AstroImage = m_VideoController.GetCurrentAstroImage(false); ObjectToAdd = null; ObjectToAdd2 = null; float?commonAperture = m_State.MeasuringApertures.Count > 0 ? m_State.MeasuringApertures[0] : (float?)null; m_Aperture = commonAperture; m_Aperture1 = commonAperture; m_Aperture2 = commonAperture; m_Center = new ImagePixel(center); m_OriginalCenter = new ImagePixel(center); m_EditingOccultedStar = false; Initialise(); }
public bool InitializeNewTracking(IAstroImage astroImage) { m_StarMapConfig = new StarMapInternalConfig(StarMapInternalConfig.Default); m_StarMapConfig.CustomMaxSignalValue = astroImage.GetPixelmapPixels().Max(); m_StarMapConfig.CustomOptimumStarsValue = 25; m_StarMapConfig.IsFITSFile = true; StarMap starMap = new StarMap(); starMap.FindBestMap( m_StarMapConfig, (AstroImage)astroImage, Rectangle.Empty, new Rectangle(0, 0, astroImage.Width, astroImage.Height), AstrometryContext.Current.LimitByInclusion); if (starMap.Features.Count < 10) { MessageBox.Show("Cannot initialize object tracking as less than 10 stars can be identified in the field"); return(false); } // Build a signature of the largest 10 features (pivots) m_PivotDistances.Clear(); for (int i = 0; i < 10; i++) { m_PivotDistances.Add(new List <double>(UNINITIALIZED_DISTANCES)); } double fwhmSum = 0; int fwhmCount = 0; starMap.Features.Sort((x, y) => y.PixelCount.CompareTo(x.PixelCount)); for (int i = 0; i < 10; i++) { var feature_i = starMap.Features[i]; for (int j = i + 1; j < 10; j++) { var feature_j = starMap.Features[j]; double distance = feature_j.GetCenter().DistanceTo(feature_i.GetCenter()); m_PivotDistances[i][j] = distance; m_PivotDistances[j][i] = distance; } int x0 = feature_i.GetCenter().X; int y0 = feature_i.GetCenter().Y; PSFFit fit = new PSFFit((int)x0, (int)y0); uint[,] data = ((AstroImage)astroImage).GetMeasurableAreaPixels((int)x0, (int)y0); fit.Fit(data); if (fit.IsSolved) { fwhmSum += fit.FWHM; fwhmCount++; } } m_FWHMAverage = (float)(fwhmSum / fwhmCount); for (int i = 0; i < m_TrackedObjects.Count; i++) { m_TrackedObjectsPivotDistancesX[i] = new List <double>(); m_TrackedObjectsPivotDistancesY[i] = new List <double>(); for (int j = 0; j < 10; j++) { m_TrackedObjectsPivotDistancesX[i].Add(m_TrackedObjects[i].Center.XDouble - starMap.Features[j].GetCenter().XDouble); m_TrackedObjectsPivotDistancesY[i].Add(m_TrackedObjects[i].Center.YDouble - starMap.Features[j].GetCenter().YDouble); } int x0 = m_TrackedObjects[i].Center.X; int y0 = m_TrackedObjects[i].Center.Y; PSFFit fit = new PSFFit((int)x0, (int)y0); uint[,] data = ((AstroImage)astroImage).GetMeasurableAreaPixels((int)x0, (int)y0); fit.Fit(data); if (fit.IsSolved) { SetTargetFWHM(i, (float)fit.FWHM); } } m_TargetPivotDistancesListX.Clear(); m_TargetPivotDistancesListY.Clear(); return(true); }
public void NextFrame(int frameNo, IAstroImage astroImage) { m_IsTrackedSuccessfully = false; StarMap starMap = new StarMap(); starMap.FindBestMap( m_StarMapConfig, (AstroImage)astroImage, Rectangle.Empty, new Rectangle(0, 0, astroImage.Width, astroImage.Height), AstrometryContext.Current.LimitByInclusion); if (starMap.Features.Count >= 5) { starMap.Features.Sort((x, y) => y.PixelCount.CompareTo(x.PixelCount)); int featuresToConsider = Math.Min(10, starMap.Features.Count); var featureDistances = new List <List <double> >(); for (int i = 0; i < featuresToConsider; i++) { var dist = new List <double>(); for (int j = 0; j < featuresToConsider; j++) { dist.Add(double.NaN); } featureDistances.Add(dist); } var pivotDistances = new List <List <double> >(); for (int i = 0; i < featuresToConsider; i++) { pivotDistances.Add(new List <double>(UNINITIALIZED_DISTANCES)); } for (int i = 0; i < featuresToConsider; i++) { var feature_i = starMap.Features[i]; for (int j = i + 1; j < featuresToConsider; j++) { var feature_j = starMap.Features[j]; double distance = feature_j.GetCenter().DistanceTo(feature_i.GetCenter()); pivotDistances[i][j] = distance; pivotDistances[j][i] = distance; } } Dictionary <int, int> pivotMap = IdentifyPivots(pivotDistances); int identifiedObjects = 0; for (int i = 0; i < m_TrackedObjects.Count; i++) { ((TrackedObject)m_TrackedObjects[i]).NewFrame(); var xVals = new List <double>(); var yVals = new List <double>(); foreach (int key in pivotMap.Keys) { int mapsToSourceFeatureId = pivotMap[key]; xVals.Add(starMap.Features[key].GetCenter().XDouble + m_TrackedObjectsPivotDistancesX[i][mapsToSourceFeatureId]); yVals.Add(starMap.Features[key].GetCenter().YDouble + m_TrackedObjectsPivotDistancesY[i][mapsToSourceFeatureId]); } double x0 = xVals.Median(); double y0 = yVals.Median(); double sigmaX = Math.Sqrt(xVals.Select(x => (x - x0) * (x - x0)).Sum()) / (xVals.Count - 1); double sigmaY = Math.Sqrt(yVals.Select(y => (y - y0) * (y - y0)).Sum()) / (yVals.Count - 1); if (!double.IsNaN(x0) && !double.IsNaN(y0) && xVals.Count > 1 && (sigmaX > m_FWHMAverage || sigmaY > m_FWHMAverage)) { // Some of the pivots may have been misidentified. Remove all entries with too large residuals and try again xVals.RemoveAll(x => Math.Abs(x - x0) > sigmaX); yVals.RemoveAll(y => Math.Abs(y - y0) > sigmaY); if (xVals.Count > 1) { x0 = xVals.Median(); y0 = yVals.Median(); sigmaX = Math.Sqrt(xVals.Select(x => (x - x0) * (x - x0)).Sum()) / (xVals.Count - 1); sigmaY = Math.Sqrt(yVals.Select(y => (y - y0) * (y - y0)).Sum()) / (yVals.Count - 1); } } if (!double.IsNaN(x0) && !double.IsNaN(y0) && xVals.Count > 1 && (sigmaX > m_FWHMAverage || sigmaY > m_FWHMAverage)) { // There is something really wrong about this. Reject the position and fail the frame m_TrackedObjects[i].SetIsTracked(false, NotMeasuredReasons.FoundObjectNotWithInExpectedPositionTolerance, null, null); } else { PSFFit fit = new PSFFit((int)x0, (int)y0); uint[,] data = ((AstroImage)astroImage).GetMeasurableAreaPixels((int)x0, (int)y0); fit.Fit(data); if (fit.IsSolved) { m_TrackedObjects[i].SetIsTracked(true, NotMeasuredReasons.TrackedSuccessfully, new ImagePixel(fit.XCenter, fit.YCenter), fit.Certainty); ((TrackedObject)m_TrackedObjects[i]).ThisFrameX = (float)fit.XCenter; ((TrackedObject)m_TrackedObjects[i]).ThisFrameY = (float)fit.YCenter; ((TrackedObjectBase)m_TrackedObjects[i]).PSFFit = fit; identifiedObjects++; } else { m_TrackedObjects[i].SetIsTracked(false, NotMeasuredReasons.PSFFittingFailed, null, null); } } } m_IsTrackedSuccessfully = identifiedObjects == m_TrackedObjects.Count; if (m_IsTrackedSuccessfully) { UpdatePivotDistances(starMap, pivotMap); } } }