private void RecomputeData() { NumericUpDown[] targetApertures = new NumericUpDown[] { nudAperture1, nudAperture2, nudAperture3, nudAperture4 }; NumericUpDown[] targetFitAreas = new NumericUpDown[] { nudFitArea1, nudFitArea2, nudFitArea3, nudFitArea4 }; PictureBox[] psfBoxes = new PictureBox[] { picTarget1PSF, picTarget2PSF, picTarget3PSF, picTarget4PSF }; MeasurementsHelper measurer = new MeasurementsHelper( m_Context.BitPix, m_Context.BackgroundMethod, TangraConfig.Settings.Photometry.SubPixelSquareSize, TangraConfig.Settings.Photometry.Saturation.GetSaturationForBpp(m_Context.BitPix, m_Context.MaxPixelValue)); for (int i = 0; i < m_Header.ObjectCount; i++) { // Apply the selected filter, compute the PSF and then draw the data LCMeasurement reading = m_SelectedMeasurements[i]; if (!LCMeasurement.IsEmpty(reading)) { LCMeasurement updatedReading = reading.Clone(); int x0Int = (int)Math.Round(reading.X0); int y0Int = (int)Math.Round(reading.Y0); updatedReading.PsfFit = new PSFFit(x0Int, y0Int); updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit; int pixelDataWidth = updatedReading.PixelData.GetLength(0); int pixelDataHeight = updatedReading.PixelData.GetLength(1); updatedReading.PsfFit.Fit( updatedReading.PixelData, m_Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize, x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1, y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1, false); int fitArea = (int)targetFitAreas[i].Value; measurer.FindBestFit( reading.X0, reading.Y0, GetCurrentFilter(), reading.PixelData, m_Context.BitPix, ref fitArea, m_Header.FixedApertureFlags[i]); updatedReading.PsfFit = measurer.FoundBestPSFFit; updatedReading.PixelData = measurer.PixelData; m_SelectedMeasurements[i] = updatedReading; psfBoxes[reading.TargetNo].Visible = true; PlotSingleGaussian( psfBoxes[reading.TargetNo], updatedReading, m_AllBrushes, (float)targetApertures[i].Value, m_Footer.ReductionContext.BitPix); } } }
internal void HandleNewSelectedFrame(LCMeasurement[] selectedMeasurements) { m_SelectedMeasurements = selectedMeasurements; if (m_SelectedMeasurements != null) { for (int i = 0; i < m_SelectedMeasurements.Length; i++) { LCMeasurement reading = m_SelectedMeasurements[i]; if (!LCMeasurement.IsEmpty(reading) && reading.TargetNo >= 0 && reading.TargetNo <= 3) { LCMeasurement updatedReading = reading.Clone(); int x0Int = (int)Math.Round(reading.X0); int y0Int = (int)Math.Round(reading.Y0); updatedReading.PsfFit = new PSFFit(x0Int, y0Int); updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit; int pixelDataWidth = updatedReading.PixelData.GetLength(0); int pixelDataHeight = updatedReading.PixelData.GetLength(1); uint[,] pixelData = GetPixelData(updatedReading.PixelData); updatedReading.PsfFit.Fit( pixelData, m_LCFile.Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize, x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1, y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1, false); PlotSingleGaussian( m_TargetBoxes[reading.TargetNo], updatedReading, m_DisplaySettings.TargetBrushes, m_LCFile.Footer.TrackedObjects[updatedReading.TargetNo].ApertureInPixels, m_LCFile.Footer.ReductionContext.BitPix); } else { Bitmap bmp = m_TargetBoxes[i].Image as Bitmap; if (bmp != null) { using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(m_DisplaySettings.BackgroundColor); g.Save(); } } m_TargetBoxes[i].Refresh(); } } } }
private void PlotGaussians() { PictureBox[] psfBoxes = new PictureBox[] { picTarget1PSF, picTarget2PSF, picTarget3PSF, picTarget4PSF }; NumericUpDown[] targetApertures = new NumericUpDown[] { nudAperture1, nudAperture2, nudAperture3, nudAperture4 }; Label[] fwhmLabels = new Label[] { lblFWHM1, lblFWHM2, lblFWHM3, lblFWHM4 }; for (int i = 0; i < m_SelectedMeasurements.Length; i++) { LCMeasurement reading = m_SelectedMeasurements[i]; if (!LCMeasurement.IsEmpty(reading) && reading.TargetNo >= 0 && reading.TargetNo <= 3) { LCMeasurement updatedReading = reading.Clone(); int x0Int = (int)Math.Round(reading.X0); int y0Int = (int)Math.Round(reading.Y0); updatedReading.PsfFit = new PSFFit(x0Int, y0Int); updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit; int pixelDataWidth = updatedReading.PixelData.GetLength(0); int pixelDataHeight = updatedReading.PixelData.GetLength(1); updatedReading.PsfFit.Fit( updatedReading.PixelData, m_Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize, x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1, y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1, false); psfBoxes[reading.TargetNo].Visible = true; PlotSingleGaussian( psfBoxes[reading.TargetNo], updatedReading, m_AllBrushes, (float)targetApertures[i].Value, m_Footer.ReductionContext.BitPix); fwhmLabels[updatedReading.TargetNo].Text = string.Format("{0} px = {1} FWHM", targetApertures[updatedReading.TargetNo].Value.ToString("0.00"), ((double)targetApertures[updatedReading.TargetNo].Value / updatedReading.PsfFit.FWHM).ToString("0.0")); } else { psfBoxes[i].Visible = false; fwhmLabels[i].Text = string.Empty; } } }
internal void HandleNewSelectedFrame(LCMeasurement[] selectedMeasurements) { m_SelectedMeasurements = selectedMeasurements; if (m_SelectedMeasurements != null) { for (int i = 0; i < m_SelectedMeasurements.Length; i++) { LCMeasurement reading = m_SelectedMeasurements[i]; if (!LCMeasurement.IsEmpty(reading) && reading.TargetNo >= 0 && reading.TargetNo <= 3) { LCMeasurement updatedReading = reading.Clone(); int pixelDataWidth = updatedReading.PixelData.GetLength(0); int pixelDataHeight = updatedReading.PixelData.GetLength(1); Dictionary <uint, int> histogram = new Dictionary <uint, int>(); for (uint j = 0; j <= m_Context.MaxPixelValue; j++) { histogram.Add(j, 0); } for (int x = 0; x < pixelDataWidth; x++) { for (int y = 0; y < pixelDataHeight; y++) { histogram[updatedReading.PixelData[x, y]]++; } } // TODO: Plot the histogram, then the values for the PSF, Average and Background Mode on it int x0Int = (int)Math.Round(reading.X0); int y0Int = (int)Math.Round(reading.Y0); updatedReading.PsfFit = new PSFFit(x0Int, y0Int); updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit; updatedReading.PsfFit.Fit( updatedReading.PixelData, m_LCFile.Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize, x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1, y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1, false); double psfBackground = updatedReading.PsfFit.I0; float aperture = m_Context.ReProcessApertures[reading.TargetNo]; List <uint> allKeys = histogram.Keys.ToList(); foreach (uint key in allKeys) { histogram[key] = (int)Math.Round(100 * Math.Log(histogram[key] + 1)); } DrawHistogram(m_TargetBoxes[reading.TargetNo], histogram); } } } }