private bool GetFitInMatrix(ITrackedObjectPsfFit gaussian, ref int matirxSize, float preselectedAperture) { rbGuidingStar.Text = "Guiding/Comparison Star"; m_IsBrightEnoughForAutoGuidingStar = false; if (m_Aperture == null) { if (gaussian != null && !double.IsNaN(gaussian.FWHM) && TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM) { m_Aperture = (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture); } else { m_Aperture = (float)(TangraConfig.Settings.Photometry.DefaultSignalAperture); } } else if ( gaussian != null && !double.IsNaN(gaussian.FWHM) && TangraConfig.Settings.Photometry.SignalApertureUnitDefault == TangraConfig.SignalApertureUnit.FWHM && m_Aperture < (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture)) { m_Aperture = (float)(gaussian.FWHM * TangraConfig.Settings.Photometry.DefaultSignalAperture); } nudFitMatrixSize.ValueChanged -= nudFitMatrixSize_ValueChanged; try { uint[,] autoStarsPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35); m_AutoStarsInLargerArea = StarFinder.GetStarsInArea( ref autoStarsPixels, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, m_AstroImage.MedianNoise, LightCurveReductionContext.Instance.DigitalFilter); m_ProcessingPixels = ImageFilters.CutArrayEdges(autoStarsPixels, 9); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 17); m_AutoStarsInArea = new List <PSFFit>(); foreach (PSFFit autoStar in m_AutoStarsInLargerArea) { if (autoStar.XCenter > 9 && autoStar.XCenter < 9 + 17 && autoStar.YCenter > 9 && autoStar.YCenter < 9 + 17) { // Don't change original star so use a clone PSFFit clone = autoStar.Clone(); clone.SetNewFieldCenterFrom35PixMatrix(8, 8); m_AutoStarsInArea.Add(clone); } } int oldMatirxSize = matirxSize; if (m_AutoStarsInArea.Count == 0) { rbGuidingStar.Text = "Guiding/Comparison Star"; // There are no stars that are bright enough. Simply let the user do what they want, but still try to default to a sensible aperture size MeasurementsHelper measurement = ReduceLightCurveOperation.DoConfiguredMeasurement(m_ProcessingPixels, m_Aperture.Value, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, 3.0, ref matirxSize); if (measurement.FoundBestPSFFit != null && measurement.FoundBestPSFFit.IsSolved && measurement.FoundBestPSFFit.Certainty > 0.1) { m_X0 = measurement.XCenter; m_Y0 = measurement.YCenter; m_FWHM = (float)measurement.FoundBestPSFFit.FWHM; } else { m_X0 = 8; m_Y0 = 8; m_FWHM = 6; } m_Gaussian = null; nudFitMatrixSize.SetNUDValue(11); } else if (m_AutoStarsInArea.Count == 1) { // There is exactly one good star found. Go and do a fit in a wider area double bestFindTolerance = 3.0; for (int i = 0; i < 2; i++) { MeasurementsHelper measurement = ReduceLightCurveOperation.DoConfiguredMeasurement(m_ProcessingPixels, m_Aperture.Value, m_AstroImage.Pixelmap.BitPixCamera, m_AstroImage.Pixelmap.MaxSignalValue, bestFindTolerance, ref matirxSize); if (measurement != null && matirxSize != -1) { if (matirxSize < 5) { // Do a centroid in the full area, and get another matix centered at the centroid ImagePixel centroid = new ImagePixel(m_Center.X, m_Center.Y); m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(centroid); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(centroid); m_X0 = centroid.X; m_Y0 = centroid.Y; m_FWHM = 6; m_Gaussian = null; nudFitMatrixSize.SetNUDValue(11); } else { m_X0 = measurement.XCenter; m_Y0 = measurement.YCenter; if (measurement.FoundBestPSFFit != null) { m_FWHM = (float)measurement.FoundBestPSFFit.FWHM; m_Gaussian = measurement.FoundBestPSFFit; } else { m_FWHM = 6; m_Gaussian = null; } m_ProcessingPixels = measurement.PixelData; nudFitMatrixSize.SetNUDValue(matirxSize); } } else { matirxSize = oldMatirxSize; return(false); } if (m_Gaussian != null) { if (IsBrightEnoughtForGuidingStar()) { rbGuidingStar.Text = "Guiding/Comparison Star"; m_IsBrightEnoughForAutoGuidingStar = true; } break; } } } else if (m_AutoStarsInArea.Count > 1) { rbGuidingStar.Text = "Guiding/Comparison Star"; // There are more stars found. double xBest = m_Gaussian != null ? m_Gaussian.XCenter : m_IsEdit ? ObjectToAdd.ApertureMatrixX0 : 8.5; double yBest = m_Gaussian != null ? m_Gaussian.YCenter : m_IsEdit ? ObjectToAdd.ApertureMatrixY0 : 8.5; // by default use the one closest to the original location PSFFit closestFit = m_AutoStarsInArea[0]; double closestDist = double.MaxValue; foreach (PSFFit star in m_AutoStarsInArea) { double dist = Math.Sqrt((star.XCenter - xBest) * (star.XCenter - xBest) + (star.YCenter - yBest) * (star.YCenter - yBest)); if (closestDist > dist) { closestDist = dist; closestFit = star; } } m_X0 = (float)closestFit.XCenter; m_Y0 = (float)closestFit.YCenter; m_FWHM = (float)closestFit.FWHM; m_Gaussian = closestFit; nudFitMatrixSize.SetNUDValue(m_IsEdit ? ObjectToAdd.PsfFitMatrixSize : closestFit.MatrixSize); } //if (m_Gaussian == null && gaussian.Certainty > 0.1 && ImagePixel.ComputeDistance(gaussian.X0_Matrix, 8, gaussian.Y0_Matrix, 8) < 3) //{ // // Id we failed to locate a bright enough autostar, but the default Gaussian is still certain enough and close enought to the center, we present it as a starting point // m_X0 = (float)gaussian.X0_Matrix; // m_Y0 = (float)gaussian.Y0_Matrix; // m_FWHM = (float)gaussian.FWHM; // m_Gaussian = gaussian; //} decimal appVal; if (float.IsNaN(preselectedAperture)) { if (float.IsNaN(m_Aperture.Value)) { appVal = Convert.ToDecimal(TangraConfig.Settings.Photometry.DefaultSignalAperture); } else { appVal = Convert.ToDecimal(m_Aperture.Value); if (nudAperture1.Maximum < appVal) { nudAperture1.Maximum = appVal + 1; } } } else { appVal = (decimal)preselectedAperture; } if ((float)appVal > m_Aperture) { m_Aperture = (float)appVal; } nudAperture1.SetNUDValue(Math.Round(appVal, 2)); PlotSingleTargetPixels(); PlotGaussian(); return(true); } finally { nudFitMatrixSize.ValueChanged += nudFitMatrixSize_ValueChanged; } }
internal frmAddOrEditSingleTarget(int objectId, TrackedObjectConfig selectedObject, LCStateMachine state, VideoController videoController) { InitializeComponent(); m_VideoController = videoController; m_AutocenteredApertureAvailable = true; Text = "Edit Object"; btnAdd.Text = "Save"; btnDontAdd.Text = "Cancel"; btnDelete.Visible = true; m_IsEdit = true; m_ObjectId = objectId; m_State = state; m_AstroImage = m_State.VideoOperation.m_StackedAstroImage; ObjectToAdd = selectedObject; if (selectedObject.TrackingType != TrackingType.ComparisonStar) { nudFitMatrixSize.SetNUDValue(selectedObject.PsfFitMatrixSize); } m_Center = new ImagePixel( selectedObject.OriginalFieldCenterX, selectedObject.OriginalFieldCenterY); if (ObjectToAdd.PositionTolerance > 0) { nudPositionTolerance.SetNUDValue((decimal)ObjectToAdd.PositionTolerance); } Initialize(); if (!selectedObject.IsWeakSignalObject && !selectedObject.IsFixedAperture) { int matrixSize = selectedObject.PsfFitMatrixSize; GetFitInMatrix(selectedObject.Gaussian, ref matrixSize, selectedObject.ApertureInPixels); selectedObject.PsfFitMatrixSize = matrixSize; } else { m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center); m_FWHM = 6; m_Gaussian = null; m_X0 = selectedObject.ApertureMatrixX0; m_Y0 = selectedObject.ApertureMatrixY0; dx = selectedObject.ApertureDX; dy = selectedObject.ApertureDY; PlotSingleTargetPixels(); nudAperture1.SetNUDValue((decimal)Math.Round(ObjectToAdd.ApertureInPixels, 2)); } SetHeightAndType(); if (selectedObject.TrackingType == TrackingType.GuidingStar) { SelectedObjectType = TrackingType.GuidingStar; } else if (selectedObject.TrackingType == TrackingType.OccultedStar) { SelectedObjectType = TrackingType.OccultedStar; } }
private void Initialise() { picTarget1Pixels.Image = new Bitmap(AREA_SIDE * MAGN_FACTOR, AREA_SIDE * MAGN_FACTOR, PixelFormat.Format24bppRgb); picTarget1PSF.Image = new Bitmap(picTarget1PSF.Width, picTarget1PSF.Height); m_AllTargetColors = new Color[] { TangraConfig.Settings.Color.Target1, TangraConfig.Settings.Color.Target2, TangraConfig.Settings.Color.Target3, TangraConfig.Settings.Color.Target4 }; m_Color = m_AllTargetColors[m_ObjectId]; if (m_ObjectId < 3 && !m_IsEdit) { m_Color2 = m_AllTargetColors[m_ObjectId + 1]; } bool doubleModeDisabled = false; if (m_IsEdit && m_ObjectId2 <= 3) { m_Color2 = m_AllTargetColors[m_ObjectId2]; } else if (m_ObjectId == 3 || m_ObjectId2 == 4) { doubleModeDisabled = true; rbTwoObjects.Enabled = false; } m_Pen = new Pen(m_Color); m_Brush = new SolidBrush(m_Color); m_Pen2 = new Pen(m_Color2); m_Brush2 = new SolidBrush(m_Color2); m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 35); ImagePixel newCenter = null; bool autoDoubleObjectLocated = m_TryAutoDoubleFind && TryAutoLocateDoubleObject(out newCenter); if (autoDoubleObjectLocated) { int deltaX = (int)Math.Round(newCenter.XDouble - 18); int deltaY = (int)Math.Round(newCenter.YDouble - 18); m_X1Start -= deltaX; m_Y1Start -= deltaY; m_X2Start -= deltaX; m_Y2Start -= deltaY; m_Center = new ImagePixel(newCenter.Brightness, m_Center.XDouble + newCenter.XDouble - 18, m_Center.YDouble + newCenter.YDouble - 18); m_ProcessingPixels = m_AstroImage.GetMeasurableAreaPixels(m_Center.X, m_Center.Y, 35); m_DisplayPixels = m_AstroImage.GetMeasurableAreaDisplayBitmapPixels(m_Center.X, m_Center.Y, 35); m_AutoDoubleCenter = new ImagePixel(m_Center); m_AutoDoubleX1Start = m_X1Start; m_AutoDoubleY1Start = m_Y1Start; m_AutoDoubleX2Start = m_X2Start; m_AutoDoubleY2Start = m_Y2Start; } bool occultedStartAlreadyPicked = m_State.MeasuringStars.Any(x => x.IsOcultedStar()); if (m_IsEdit) { rbOcculted.Enabled = m_EditingOccultedStar || !occultedStartAlreadyPicked; rbReference.Checked = !m_EditingOccultedStar; rbOcculted.Checked = m_EditingOccultedStar; } else { if (occultedStartAlreadyPicked) { rbOcculted.Enabled = false; rbReference.Checked = true; } else { rbOcculted.Enabled = true; rbOcculted.Checked = true; } } if (doubleModeDisabled || !autoDoubleObjectLocated) { rbOneObject.Checked = true; } UpdateStateControls(); DrawCollorPanel(); DrawCollorPanel2(); CalculatePSF(); }