String GetPeakPositionStr(SapFlatFieldStats stats) { String str = ""; if (stats.NumComponents > 1) { str += "[ "; for (int iComponent = 0; iComponent < stats.NumComponents; iComponent++) { String szComponent;; szComponent = String.Format("{0}", stats.get_NumPixels(iComponent)); str += szComponent; if (iComponent != stats.NumComponents - 1) { str += ", "; } } str += " ]"; } else { str = String.Format("{0}", stats.NumPixels); } return(str); }
String GetHighStr(SapFlatFieldStats stats) { String str = ""; if (stats.NumComponents > 1) { str += "[ "; for (int iComponent = 0; iComponent < stats.NumComponents; iComponent++) { String szComponent; szComponent = String.Format("{0}", stats.get_High(iComponent)); str += szComponent; if (iComponent != stats.NumComponents - 1) { str += ", "; } } str += " ]"; } else { str = String.Format("{0}", stats.High); } return(str); }
private void BrightImage() { String str; SapFlatFieldStats stats = new SapFlatFieldStats(); if (m_pXfer != null) { str = String.Format("Number of frames to average: {0}", textBox_Frame_Avg.Text); LogMessage(LogTypes.Info, str); } if (m_CorrectionType == SapFlatField.ScanCorrectionType.Line) { str = String.Format("Number of lines to average: {0}", textBox_Line_Avg.Text); LogMessage(LogTypes.Info, str); str = String.Format("Vertical offset from top: {0}", textBox_Vert_Offset.Text); LogMessage(LogTypes.Info, str); } LogMessage(LogTypes.Info, "Bright image calibration"); // Get statistics on the (bright - dark) image if (!m_pFlatField.GetStats(m_pLocalBuffer, stats)) { LogMessage(LogTypes.Error, "Unable to get image statistic"); return; } str = "The following statistics have been computed on the bright image\n"; str += "after the substraction of the dark image:\n\n"; str += String.Format(" The average pixel value is {0}levels.\n", GetAverageStr(stats)); str += String.Format(" The highest peak has been detected at {0}.\n", GetPeakPositionStr(stats)); str += String.Format(" {0} pixels {1} have a luminance value between {2} to {3}\n", GetNumPixelsStr(stats), GetPixelRatioStr(stats), GetLowStr(stats), GetHighStr(stats)); str += String.Format("\nWe recommend at least {0} levels for the highest peak value\n", m_RecommendedBright); str += String.Format("with {0}% pixels lying between the lower and the higher bound.\n", SapDefFlatFieldPixelRatio); str += "\nDo you want to use this image?"; if (MessageBox.Show(str, "", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } // Log average pixel value, lower and higher bounds and pixel ratio str = String.Format(" Average pixel value: {0}", GetAverageStr(stats)); LogMessage(LogTypes.Info, str); str = String.Format(" Maximum deviation allowed from average pixel value: {0}", textBox_Max_Dev.Text); LogMessage(LogTypes.Info, str); str = String.Format(" Highest peak position: {0}", GetPeakPositionStr(stats)); LogMessage(LogTypes.Info, str); str = String.Format(" Lower bound: {0}", GetLowStr(stats)); LogMessage(LogTypes.Info, str); str = String.Format(" Upper bound: {0}", GetHighStr(stats)); LogMessage(LogTypes.Info, str); str = String.Format(" Number of pixels inside bounds: {0} ({1})", GetNumPixelsStr(stats), GetPixelRatioStr(stats)); LogMessage(LogTypes.Info, str); SapFlatFieldDefects defects = new SapFlatFieldDefects(); // Compute gain coefficient using last acquired image m_pFlatField.NumFramesAverage = m_pLocalBuffer.Count; if (m_pFlatField.ComputeGain(m_pLocalBuffer, defects, true)) { // Check for the presence of cluster (adjacent defective pixels) if (defects.NumClusters != 0) { str = String.Format("{0} pixels ({1} %) have been identified as being defective\n", defects.NumDefects, defects.DefectRatio); str += String.Format("with {0} clusters.\n", defects.NumClusters); str += String.Format("\nWe recommend less than {0}% of defective pixels with no cluster.\n", SapDefFlatFieldDefectRatio); str += String.Format("\nDo you still want to use this image?\n"); if (MessageBox.Show(str, "", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } // Log number of defective pixels detected str = String.Format(" Number of defective pixels detected: {0} ({1})", defects.NumDefects, defects.DefectRatio); LogMessage(LogTypes.Info, str); // Log number of cluster detected str = String.Format(" Number of clusters detected: {0}", defects.NumClusters); LogMessage(LogTypes.Info, str); button_Acq_Dark.Enabled = true; button_Acq_Bright.Enabled = false; button_OK.Enabled = true; bool isOnline = (m_pXfer != null && m_pXfer.Initialized); comboBox_Correction_Type.Enabled = !isOnline && m_VideoType == SapAcquisition.VideoType.Mono; comboBox_Video_Type.Enabled = m_pXfer == null; textBox_Frame_Avg.Enabled = m_pXfer != null; textBox_Line_Avg.Enabled = m_CorrectionType == SapFlatField.ScanCorrectionType.Line; textBox_Vert_Offset.Enabled = m_CorrectionType == SapFlatField.ScanCorrectionType.Line; textBox_Max_Dev.Enabled = true; button_Save_and_Upload.Enabled = true; comboBox_FlatField_Selector.Enabled = true; //Multi flat-field not implemented in .NET //m_CalibrationIndexCtrl.EnableWindow( m_pFlatField->GetNumFlatField() > 1); LogMessage(LogTypes.Info, "Calibration with a bright image has been done successfully"); textBox_Max_Dev.Text = m_pFlatField.DeviationMaxBlack.ToString(); } }
private void DarkImage() { String str; SapFlatFieldStats stats = new SapFlatFieldStats(); str = String.Format("Correction type: {0}", m_CorrectionType); LogMessage(LogTypes.Info, str); str = String.Format("Video type: {0}", m_VideoType); LogMessage(LogTypes.Info, str); if (m_pXfer != null) { str = String.Format("Number of frames to average: {0}", textBox_Frame_Avg.Text); LogMessage(LogTypes.Info, str); } if (m_CorrectionType == SapFlatField.ScanCorrectionType.Line) { str = String.Format("Number of lines to average: {0}", textBox_Line_Avg.Text); LogMessage(LogTypes.Info, str); str = String.Format("Vertical offset from top: {0}", textBox_Vert_Offset.Text); LogMessage(LogTypes.Info, str); } LogMessage(LogTypes.Info, "Dark image calibration"); if (!m_pFlatField.GetStats(m_pLocalBuffer, stats)) { LogMessage(LogTypes.Error, " Unable to get image statistics"); return; } bool tooManyBadPixels = false; int numComponents = stats.NumComponents; for (int i = 0; i < numComponents; i++) { if (stats.get_Average(i) > m_RecommendedDark) { tooManyBadPixels = true; break; } } if (tooManyBadPixels && m_pFlatField.ClippedGainOffsetDefects) { str = "The following statistics have been computed on the dark image: \n"; str += String.Format("The average pixel value is {0}\n", GetAverageStr(stats)); str += String.Format("\nThis yields too many bad pixels above the hardware limit of {0}\n", m_RecommendedDark); str += String.Format("\nTo disable bad pixels, uncheck the \'Consider as defective ...\'\n"); str += String.Format("checkbox, then acquire the dark image again\n"); MessageBox.Show(str, "", MessageBoxButtons.OK); return; } else { str = "The following statistics have been computed on the dark image: \n"; str += String.Format("The average pixel value is {0}\n", GetAverageStr(stats)); str += String.Format("\nWe recommend an average pixel value of less than {0}\n", m_RecommendedDark); str += String.Format("\nDo you want to use this image?"); if (MessageBox.Show(str, "", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } // Log pixel statistics str = String.Format(" Average pixel value: {0}", GetAverageStr(stats)); LogMessage(LogTypes.Info, str); str = String.Format(" Maximum deviation allowed from average pixel value: {0}", textBox_Max_Dev.Text); LogMessage(LogTypes.Info, str); // Compute offset coefficients using last acquired image m_pFlatField.NumFramesAverage = m_pLocalBuffer.Count; if (m_pFlatField.ComputeOffset(m_pLocalBuffer)) { button_Acq_Dark.Enabled = false; button_Acq_Bright.Enabled = true; comboBox_Correction_Type.Enabled = false; comboBox_Video_Type.Enabled = false; comboBox_Calibration_Index.Enabled = false; LogMessage(LogTypes.Info, "Calibration with a dark image has been done successfully"); textBox_Max_Dev.Text = m_pFlatField.DeviationMaxWhite.ToString(); } }