@@ -47,6 +47,7 @@ void vtkPlusAndorVideoSource::PrintSelf(ostream& os, vtkIndent indent)
47
47
os << indent << " CameraIntrinsics: " << cvCameraIntrinsics << std::endl;
48
48
os << indent << " DistanceCoefficients: " << cvDistanceCoefficients << std::endl;
49
49
os << indent << " UseFrameCorrections: " << UseFrameCorrections << std::endl;
50
+ os << indent << " UseCosmicRayCorrection: " << UseCosmicRayCorrection << std::endl;
50
51
os << indent << " FlatCorrection: " << flatCorrection << std::endl;
51
52
os << indent << " BiasDarkCorrection: " << biasDarkCorrection << std::endl;
52
53
os << indent << " BadPixelCorrection: " << badPixelCorrection << std::endl;
@@ -128,6 +129,7 @@ PlusStatus vtkPlusAndorVideoSource::ReadConfiguration(vtkXMLDataElement* rootCon
128
129
XML_READ_BOOL_ATTRIBUTE_OPTIONAL (InitializeCoolerState, deviceConfig);
129
130
XML_READ_BOOL_ATTRIBUTE_OPTIONAL (RequireCoolTemp, deviceConfig);
130
131
XML_READ_BOOL_ATTRIBUTE_OPTIONAL (UseFrameCorrections, deviceConfig);
132
+ XML_READ_BOOL_ATTRIBUTE_OPTIONAL (UseCosmicRayCorrection, deviceConfig)
131
133
132
134
deviceConfig->GetVectorAttribute (" HSSpeed" , 2 , HSSpeed);
133
135
deviceConfig->GetVectorAttribute (" OutputSpacing" , 3 , OutputSpacing);
@@ -173,6 +175,7 @@ PlusStatus vtkPlusAndorVideoSource::WriteConfiguration(vtkXMLDataElement* rootCo
173
175
deviceConfig->SetAttribute (" BadPixelCorrection" , badPixelCorrection.c_str ());
174
176
175
177
XML_WRITE_BOOL_ATTRIBUTE (UseFrameCorrections, deviceConfig);
178
+ XML_WRITE_BOOL_ATTRIBUTE (UseCosmicRayCorrection, deviceConfig);
176
179
177
180
return PLUS_SUCCESS;
178
181
}
@@ -588,7 +591,7 @@ void vtkPlusAndorVideoSource::CorrectBadPixels(int binning, cv::Mat& cvIMG)
588
591
unsigned endX, endY;
589
592
int numCellsToCorrect = resolutionCellsToCorrect.size ();
590
593
for (uint cell : resolutionCellsToCorrect)
591
- {
594
+ {
592
595
resolutionCellIndexX = cell - frameSize[0 ] * (cell / frameSize[0 ]);
593
596
resolutionCellIndexY = cell / frameSize[0 ];
594
597
startX = resolutionCellIndexX - 1 ;
@@ -634,6 +637,38 @@ void vtkPlusAndorVideoSource::CorrectBadPixels(int binning, cv::Mat& cvIMG)
634
637
}
635
638
}
636
639
640
+ // ----------------------------------------------------------------------------
641
+ void vtkPlusAndorVideoSource::ApplyCosmicRayCorrection (int bin, cv::Mat& floatImage)
642
+ {
643
+ int kernelSize = 3 ;
644
+ if (bin < 3 )
645
+ {
646
+ kernelSize = 5 ;
647
+ }
648
+
649
+ // find and subtract background
650
+ cv::Mat meanCols, medianImage, diffImage, medianPixels;
651
+ cv::reduce (floatImage, meanCols, 0 , cv::REDUCE_AVG, CV_32FC1);
652
+ ushort background = (ushort )meanCols.at <float >(0 , 0 );
653
+ cv::subtract (floatImage, background, floatImage);
654
+
655
+ // idenfify cosmice ray indices
656
+ cv::medianBlur (floatImage, medianImage, kernelSize);
657
+ cv::subtract (floatImage, medianImage, diffImage);
658
+ cv::Mat cosmicInd = (diffImage > 50 ) & (diffImage > 4 * medianImage);
659
+ cv::Mat notCosmicInd = ~cosmicInd;
660
+ cosmicInd.convertTo (cosmicInd, floatImage.type ());
661
+ notCosmicInd.convertTo (notCosmicInd, floatImage.type ());
662
+ cosmicInd /= 255 ;
663
+ notCosmicInd /= 255 ;
664
+
665
+ // use maskes to replace cosmic ray indices with values from median image
666
+ medianImage.convertTo (medianImage, floatImage.type ());
667
+ cv::multiply (notCosmicInd, floatImage, floatImage);
668
+ cv::multiply (cosmicInd, medianImage, medianPixels);
669
+ floatImage += medianPixels;
670
+ }
671
+
637
672
// ----------------------------------------------------------------------------
638
673
void vtkPlusAndorVideoSource::ApplyFrameCorrections (int binning)
639
674
{
@@ -648,6 +683,12 @@ void vtkPlusAndorVideoSource::ApplyFrameCorrections(int binning)
648
683
cv::subtract (floatImage, cvBiasDarkCorrection, floatImage, cv::noArray (), CV_32FC1);
649
684
LOG_INFO (" Applied constant bias+dark correction" );
650
685
686
+ if (this ->UseCosmicRayCorrection )
687
+ {
688
+ ApplyCosmicRayCorrection (binning, floatImage);
689
+ LOG_INFO (" Applied cosmic ray correction" );
690
+ }
691
+
651
692
// OpenCV's lens distortion correction
652
693
cv::undistort (floatImage, result, cvCameraIntrinsics, cvDistanceCoefficients);
653
694
LOG_INFO (" Applied lens distortion correction" );
@@ -939,6 +980,19 @@ bool vtkPlusAndorVideoSource::GetUseFrameCorrections()
939
980
return this ->UseFrameCorrections ;
940
981
}
941
982
983
+ // ----------------------------------------------------------------------------
984
+ PlusStatus vtkPlusAndorVideoSource::SetUseCosmicRayCorrection (bool useCosmicRayCorrection)
985
+ {
986
+ this ->UseCosmicRayCorrection = useCosmicRayCorrection;
987
+ return PLUS_SUCCESS;
988
+ }
989
+
990
+ // ----------------------------------------------------------------------------
991
+ bool vtkPlusAndorVideoSource::GetUseCosmicRayCorrection ()
992
+ {
993
+ return this ->UseCosmicRayCorrection ;
994
+ }
995
+
942
996
// ----------------------------------------------------------------------------
943
997
PlusStatus vtkPlusAndorVideoSource::SetRequireCoolTemp (bool requireCoolTemp)
944
998
{
0 commit comments