public frmDefineDisplayDynamicRange(VideoController videoController) { InitializeComponent(); m_VideoController = videoController; m_MaxPixelValue = m_VideoController.EffectiveMaxPixelValue; m_Bpp = m_VideoController.VideoBitPix; tbarFrom.Minimum = 0; tbarFrom.Maximum = (int)m_MaxPixelValue; tbarFrom.Value = (int)Math.Min(m_MaxPixelValue, Math.Max(0, m_VideoController.DynamicFromValue)); tbarFrom.TickFrequency = (int)Math.Ceiling(tbarFrom.Maximum / 256.0); tbarFrom.SmallChange = tbarFrom.TickFrequency; tbarFrom.LargeChange = tbarFrom.TickFrequency; tbarTo.Minimum = 0; tbarTo.Maximum = (int)m_MaxPixelValue; tbarTo.Value = (int)Math.Min(m_MaxPixelValue, Math.Max(0, m_VideoController.DynamicToValue)); tbarTo.TickFrequency = (int)Math.Ceiling(tbarTo.Maximum / 256.0); tbarTo.SmallChange = tbarFrom.TickFrequency; tbarTo.LargeChange = tbarFrom.TickFrequency; AstroImage image = m_VideoController.GetCurrentAstroImage(false); if (image != null) { PopulateDistribution(image.Pixelmap.Pixels); } PlotData(); DrawHistogram(); }
public frmDefineDynamicRange(VideoController videoController) { InitializeComponent(); m_VideoController = videoController; m_MaxPixelValue = m_VideoController.EffectiveMaxPixelValue; m_Bpp = m_VideoController.VideoBitPix; tbarFrom.Minimum = 0; tbarFrom.Maximum = (int)m_MaxPixelValue; tbarFrom.Value = (int)Math.Min(m_MaxPixelValue, Math.Max(0, m_VideoController.DynamicFromValue)); tbarFrom.TickFrequency = (int)Math.Ceiling(tbarFrom.Maximum / 256.0); tbarFrom.SmallChange = tbarFrom.TickFrequency; tbarFrom.LargeChange = tbarFrom.TickFrequency; tbarTo.Minimum = 0; tbarTo.Maximum = (int)m_MaxPixelValue; tbarTo.Value = (int)Math.Min(m_MaxPixelValue, Math.Max(0, m_VideoController.DynamicToValue)); tbarTo.TickFrequency = (int)Math.Ceiling(tbarTo.Maximum / 256.0); tbarTo.SmallChange = tbarFrom.TickFrequency; tbarTo.LargeChange = tbarFrom.TickFrequency; AstroImage image = m_VideoController.GetCurrentAstroImage(false); if (image != null) { PopulateDistribution(image.Pixelmap.Pixels); } PlotData(); DrawHistogram(); }
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(); } }
internal frmAddOrEditMutualEventsTarget(int objectId, TrackedObjectConfig selectedObject, LCStateMachine state, VideoController videoController) { InitializeComponent(); m_VideoController = videoController; Text = "Edit 'Mutual Event' Target"; btnAdd.Text = "Save"; btnDontAdd.Text = "Cancel"; btnDelete.Visible = true; m_IsEdit = true; m_ObjectId = objectId; m_State = state; m_AstroImage = m_VideoController.GetCurrentAstroImage(false); ObjectToAdd = selectedObject; 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(selectedObject.ApertureStartingX, selectedObject.ApertureStartingY); m_OriginalCenter = new ImagePixel(selectedObject.ApertureStartingX, selectedObject.ApertureStartingY); if (selectedObject.ProcessInPsfGroup) { m_GroupId = selectedObject.GroupId; List <TrackedObjectConfig> otherGroupedObjects = state.m_MeasuringStars.Where(x => m_GroupId >= 0 && x.GroupId == m_GroupId && x != selectedObject).ToList(); if (otherGroupedObjects.Count == 1) { ObjectToAdd2 = otherGroupedObjects[0]; m_ObjectId2 = state.m_MeasuringStars.IndexOf(ObjectToAdd2); } } else { ObjectToAdd2 = null; m_GroupId = objectId; // If we are to use a second object, it should have the next available Id m_ObjectId2 = state.m_MeasuringStars.Count; } m_EditingOccultedStar = selectedObject.IsOcultedStar(); Initialise(); }
private void AutoDetectVTIOSDPosition() { var pixelMap = m_VideoController.GetCurrentAstroImage(false).Pixelmap; if (!LocateTimestampPosition(pixelMap.Pixels, pixelMap.Width, pixelMap.Height)) { var lastChoise = TangraConfig.Settings.AAV.GetLastOsdPositionForFrameSize(m_VideoController.FramePlayer.Video.Width, m_VideoController.FramePlayer.Video.Height); if (lastChoise != null) { m_RoiSelector.SetUserFrame(new Rectangle(lastChoise.Item3, lastChoise.Item1, lastChoise.Item4 - lastChoise.Item3, lastChoise.Item2 - lastChoise.Item1)); m_VideoController.RefreshCurrentFrame(); } m_VideoController.ShowMessageBox("Cannot locate the VTI-OSD position. Please specify it manually.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void SetBestAngle(float bestAngle) { SelectedStarBestAngle = bestAngle; m_OperationState = SpectroscopyState.StarConfirmed; var reader = new SpectraReader(m_VideoController.GetCurrentAstroImage(false), bestAngle, PixelValueCoefficient); Spectra spectra = reader.ReadSpectra( (float)SelectedStar.XDouble, (float)SelectedStar.YDouble, MeasurementAreaWing, BackgroundAreaWing, BackgroundAreaGap, PixelCombineMethod.Average); m_ControlPanel.PreviewSpectra(spectra); }
internal ucCalibrationPanel(AstrometryController astrometryController, VideoController videoController, IPlateCalibrationTool configTool) { InitializeComponent(); m_AstrometryController = astrometryController; m_VideoController = videoController; m_CalibrationTool = configTool; m_CalibrationTool.AreaChanged += m_CalibrationTool_AreaChanged; pnlDebugFits.Visible = false; m_AstrometryController.RegisterCalibrationRunner(this); rbIdentify3Stars.Checked = true; UpdateEnabledStateOfScrollControls(); m_InitialPixelmap = m_VideoController.GetCurrentAstroImage(false).Pixelmap; m_VideoController.ApplyDisplayModeAdjustments(m_InitialPixelmap.DisplayBitmap, false, m_InitialPixelmap); m_CalibrationTool.ActivateOsdAreaSizing(); rbInclusion.Checked = TangraConfig.Settings.PlateSolve.SelectedScopeRecorderConfig.IsInclusionArea; }
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(); }
private void MeasureCurrentPSF() { if (m_PSFFit == null) { return; } float aperture = (float)nudMeasuringAperture.Value; using (Graphics g = Graphics.FromImage(picPixels.Image)) { m_PSFFit.DrawDataPixels(g, new Rectangle(0, 0, picPixels.Width, picPixels.Height), aperture, Pens.Lime, m_Bpp, m_NormVal); g.Save(); } picPixels.Invalidate(); int centerX = (int)Math.Round(m_PSFFit.XCenter); int centerY = (int)Math.Round(m_PSFFit.YCenter); uint[,] data = m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaPixels(centerX, centerY, 17); uint[,] bagPixels = m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaPixels(centerX, centerY, 35); NotMeasuredReasons rv = MeasureObject( new ImagePixel(m_PSFFit.XCenter, m_PSFFit.YCenter), data, bagPixels, m_VideoController.VideoBitPix, m_Measurer, TangraConfig.PreProcessingFilter.NoFilter, m_SignalMethod, TangraConfig.PsfQuadrature.NumericalInAperture, TangraConfig.Settings.Photometry.PsfFittingMethod, aperture, m_PSFFit.FWHM, (float)m_PSFFit.FWHM, new FakeIMeasuredObject(m_PSFFit), null, null, false); double reading = m_Measurer.TotalReading; double bgReading = m_Measurer.TotalBackground; if (rv == NotMeasuredReasons.MeasuredSuccessfully) { tbxSmBG.Text = (reading - bgReading).ToString("0.000"); tbxBg.Text = bgReading.ToString("0.000"); } else { Trace.WriteLine("TargetPSFViewer.NotMeasuredReasons: " + rv.ToString()); tbxBg.Text = "ERR"; tbxSmBG.Text = "ERR"; } // Show the apertures in the main view m_Aperture = aperture; m_InnerRadius = (float)(TangraConfig.Settings.Photometry.AnnulusInnerRadius * aperture); m_OuterRadius = (float)Math.Sqrt(TangraConfig.Settings.Photometry.AnnulusMinPixels / Math.PI + m_InnerRadius * m_InnerRadius); //m_VideoController.RefreshCurrentFrame(); }
internal float LocateSpectraAngle(PSFFit selectedStar, int?roughStartingAngle = null) { float x0 = (float)selectedStar.XCenter; float y0 = (float)selectedStar.YCenter; uint brigthness10 = (uint)(0.1 * selectedStar.Brightness); uint brigthness20 = (uint)(0.2 * selectedStar.Brightness); uint brigthness40 = (uint)(0.4 * selectedStar.Brightness); uint bgFromPsf = (uint)(selectedStar.I0); int minDistance = (int)(10 * selectedStar.FWHM); int clearDist = (int)(2 * selectedStar.FWHM); AstroImage image = m_VideoController.GetCurrentAstroImage(false); float width = image.Width; float height = image.Height; uint[] angles = new uint[360]; uint[] sums = new uint[360]; uint[] pixAbove10Perc = new uint[360]; uint[] pixAbove20Perc = new uint[360]; uint[] pixAbove40Perc = new uint[360]; int diagonnalPixels = (int)Math.Ceiling(Math.Sqrt(image.Width * image.Width + image.Height * image.Height)); int iFrom = 0; int iTo = 360; if (roughStartingAngle.HasValue) { iFrom = roughStartingAngle.Value - 10; iTo = roughStartingAngle.Value + 10; } bool peakFound = false; for (int i = iFrom; i < iTo; i++) { var mapper = new RotationMapper(image.Width, image.Height, i); PointF p1 = mapper.GetDestCoords(x0, y0); float x1 = p1.X; float y1 = p1.Y; uint rowSum = 0; uint pixAbove10 = 0; uint pixAbove10Max = 0; bool prevPixAbove10 = false; uint pixAbove20 = 0; uint pixAbove20Max = 0; bool prevPixAbove20 = false; uint pixAbove40 = 0; uint pixAbove40Max = 0; bool prevPixAbove40 = false; for (int d = minDistance; d < diagonnalPixels; d++) { PointF p = mapper.GetSourceCoords(x1 + d, y1); if (p.X >= 0 && p.X < width && p.Y >= 0 && p.Y < height) { uint value = image.Pixelmap[(int)p.X, (int)p.Y]; rowSum += value; PointF pu = mapper.GetSourceCoords(x1 + d, y1 + clearDist); PointF pd = mapper.GetSourceCoords(x1 + d, y1 - clearDist); if (pu.X >= 0 && pu.X < width && pu.Y >= 0 && pu.Y < height && pd.X >= 0 && pd.X < width && pd.Y >= 0 && pd.Y < height) { uint value_u = image.Pixelmap[(int)pu.X, (int)pu.Y]; uint value_d = image.Pixelmap[(int)pd.X, (int)pd.Y]; if ((value - bgFromPsf) > brigthness10 && value > value_u && value > value_d) { if (prevPixAbove10) { pixAbove10++; } prevPixAbove10 = true; } else { prevPixAbove10 = false; if (pixAbove10Max < pixAbove10) { pixAbove10Max = pixAbove10; } pixAbove10 = 0; peakFound = true; } if ((value - bgFromPsf) > brigthness20 && value > value_u && value > value_d) { if (prevPixAbove20) { pixAbove20++; } prevPixAbove20 = true; } else { prevPixAbove20 = false; if (pixAbove20Max < pixAbove20) { pixAbove20Max = pixAbove20; } pixAbove20 = 0; peakFound = true; } if ((value - bgFromPsf) > brigthness40 && value > value_u && value > value_d) { if (prevPixAbove40) { pixAbove40++; } prevPixAbove40 = true; } else { prevPixAbove40 = false; if (pixAbove40Max < pixAbove40) { pixAbove40Max = pixAbove40; } pixAbove40 = 0; peakFound = true; } } else { prevPixAbove10 = false; if (pixAbove10Max < pixAbove10) { pixAbove10Max = pixAbove10; } pixAbove10 = 0; prevPixAbove20 = false; if (pixAbove20Max < pixAbove20) { pixAbove20Max = pixAbove20; } pixAbove20 = 0; prevPixAbove40 = false; if (pixAbove40Max < pixAbove40) { pixAbove40Max = pixAbove40; } pixAbove40 = 0; peakFound = true; } } } angles[i] = (uint)i; sums[i] = rowSum; pixAbove10Perc[i] = pixAbove10Max; pixAbove20Perc[i] = pixAbove20Max; pixAbove40Perc[i] = pixAbove40Max; } if (!peakFound) { return(float.NaN); } var angles10 = new List <uint>(angles).ToArray(); var angles20 = new List <uint>(angles).ToArray(); var angles40 = new List <uint>(angles).ToArray(); Array.Sort(sums, angles); Array.Sort(pixAbove10Perc, angles10); Array.Sort(pixAbove20Perc, angles20); Array.Sort(pixAbove40Perc, angles40); uint roughAngle = angles[359]; if (pixAbove10Perc[358] * 2 < pixAbove10Perc[359]) { // If second best at 10% id a lot smaller score than the top 10% scopem then this is it roughAngle = angles10[359]; } else { if (Math.Abs((int)angles[358] - (int)angles[359]) > 3)// or for large stars the two best can be sequential angles { return(float.NaN); } } uint bestSum = 0; float bestAngle = 0f; for (float a = roughAngle - 1; a < roughAngle + 1; a += 0.02f) { var mapper = new RotationMapper(image.Width, image.Height, a); PointF p1 = mapper.GetDestCoords(x0, y0); float x1 = p1.X; float y1 = p1.Y; uint rowSum = 0; for (int d = minDistance; d < diagonnalPixels; d++) { PointF p = mapper.GetSourceCoords(x1 + d, y1); if (p.X >= 0 && p.X < width && p.Y >= 0 && p.Y < height) { uint pixVal = image.Pixelmap[(int)p.X, (int)p.Y]; rowSum += pixVal; } } if (rowSum > bestSum) { bestSum = rowSum; bestAngle = a; } } return(bestAngle); }
private void btnMeasure_Click(object sender, EventArgs e) { if (m_IsMeasuring) { m_VideoOperation.StopMeasurements(); return; } var frm = new frmRunMultiFrameSpectroscopy(m_FramePlayer, m_VideoOperation, m_VideoContoller.GetCurrentAstroImage(false)); if (m_VideoContoller.ShowDialog(frm) == DialogResult.OK) { m_SpectroscopyController.SpectraReductionContext.Reset(); m_SpectroscopyController.SpectraReductionContext.FramesToMeasure = frm.NumberOfMeasurements; m_SpectroscopyController.SpectraReductionContext.MeasurementAreaWing = frm.MeasurementAreaWing; m_SpectroscopyController.SpectraReductionContext.BackgroundAreaWing = frm.BackgroundAreaWing; m_SpectroscopyController.SpectraReductionContext.BackgroundAreaGap = frm.BackgroundAreaGap; m_SpectroscopyController.SpectraReductionContext.BackgroundMethod = frm.BackgroundMethod; m_SpectroscopyController.SpectraReductionContext.PixelValueCoefficient = frm.PixelValueCoefficient; m_SpectroscopyController.SpectraReductionContext.FrameCombineMethod = frm.FrameCombineMethod; m_SpectroscopyController.SpectraReductionContext.UseFineAdjustments = frm.UseFineAdjustments; m_SpectroscopyController.SpectraReductionContext.AlignmentAbsorptionLinePos = frm.AlignmentAbsorptionLinePos; m_SpectroscopyController.SpectraReductionContext.ExposureSeconds = frm.ExposureSeconds; m_VideoOperation.StartMeasurements(); } }
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(); }
internal frmAddOrEditMutualEventsTarget(int objectId, TrackedObjectConfig selectedObject, LCStateMachine state, VideoController videoController) { InitializeComponent(); m_VideoController = videoController; Text = "Edit 'Mutual Event' Target"; btnAdd.Text = "Save"; btnDontAdd.Text = "Cancel"; btnDelete.Visible = true; m_IsEdit = true; m_ObjectId = objectId; m_State = state; m_AstroImage = m_VideoController.GetCurrentAstroImage(false); ObjectToAdd = selectedObject; 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(selectedObject.ApertureStartingX, selectedObject.ApertureStartingY); m_OriginalCenter = new ImagePixel(selectedObject.ApertureStartingX, selectedObject.ApertureStartingY); if (selectedObject.ProcessInPsfGroup) { m_GroupId = selectedObject.GroupId; List<TrackedObjectConfig> otherGroupedObjects = state.m_MeasuringStars.Where(x => m_GroupId >= 0 && x.GroupId == m_GroupId && x != selectedObject).ToList(); if (otherGroupedObjects.Count == 1) { ObjectToAdd2 = otherGroupedObjects[0]; m_ObjectId2 = state.m_MeasuringStars.IndexOf(ObjectToAdd2); } } else { ObjectToAdd2 = null; m_GroupId = objectId; // If we are to use a second object, it should have the next available Id m_ObjectId2 = state.m_MeasuringStars.Count; } m_EditingOccultedStar = selectedObject.IsOcultedStar(); Initialise(); }
internal byte[,] GetDisplayBitmapPixels(int xCenter, int yCenter) { return(m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaDisplayBitmapPixels(xCenter, yCenter, 35)); }