From 9897ea64ebd3b280d6244f63fd7c732fe9a48f85 Mon Sep 17 00:00:00 2001 From: Antoine Regimbeau <antoine.regimbeau@c-s.fr> Date: Mon, 20 Nov 2017 18:07:43 +0100 Subject: [PATCH] TEST: add test for contrast filter --- .../app/otbContrastEnhancement.cxx | 38 +++++++------- .../AppFiltering/test/CMakeLists.txt | 5 ++ .../Filtering/Contrast/test/CMakeLists.txt | 49 ++++++++++++++++++- .../Contrast/test/otbApplyGainFilter.cxx | 8 +-- .../test/otbCLHistogramEqualizationFilter.cxx | 20 ++++---- .../Contrast/test/otbComputeGainLutFilter.cxx | 12 +++-- .../Contrast/test/otbComputeHistoFilter.cxx | 14 +++--- .../Contrast/test/otbHelperCLAHE.cxx | 9 ++-- 8 files changed, 106 insertions(+), 49 deletions(-) diff --git a/Modules/Applications/AppFiltering/app/otbContrastEnhancement.cxx b/Modules/Applications/AppFiltering/app/otbContrastEnhancement.cxx index dde4dbf220..75c3a93165 100644 --- a/Modules/Applications/AppFiltering/app/otbContrastEnhancement.cxx +++ b/Modules/Applications/AppFiltering/app/otbContrastEnhancement.cxx @@ -206,14 +206,15 @@ private: AddParameter(ParameterType_Choice , "spatial" , "Spatial parameters " "for the histogram computation"); - AddChoice( "spatial.global" , "Global" ); - SetParameterDescription("spatial.global" , "The histogram will be " - "computed on the whole image. The equalization will be done on " - "this single histogram."); AddChoice( "spatial.local" , "Local" ); SetParameterDescription("spatial.local" , "The histograms will be " "computed on the each thumbnail. Each of the histogram will be " "equalized and the corresponding gain will be interpolated."); + AddChoice( "spatial.global" , "Global" ); + SetParameterDescription("spatial.global" , "The histogram will be " + "computed on the whole image. The equalization will be done on " + "this single histogram."); + AddParameter(ParameterType_Int,"spatial.local.h" , "Thumbnail height in pixel"); @@ -309,7 +310,8 @@ private: !HasUserValue("mode.lum.blu.ch") ) SetDefaultValue( inImage , "RGB" ); - // if ( HasUserValue("minmax.manuel.min") && HasUserValue("minmax.manuel.max") ) + // if ( HasUserValue("minmax.manuel.min") && + // HasUserValue("minmax.manuel.max") ) // { // if ( GetParameterFloat( "minmax.manuel.min" ) > // GetParameterFloat( "minmax.manuel.max" ) ) @@ -327,7 +329,6 @@ private: // otbAppLogINFO( << oss.str() ); // } // } - } if ( GetParameterString("minmax") == "manuel" ) @@ -381,8 +382,6 @@ private: m_ImageListToVectorFilterOut = ImageListToVectorFilterType::New() ; m_ImageListToVectorFilterOut->SetInput(outputImageList); - // m_ImageListToVectorFilterOut->Update(); - // std::cout<<"not you imagelistetovecor"<<std::endl; SetParameterOutputImage( "out" , m_ImageListToVectorFilterOut->GetOutput() ); } @@ -510,7 +509,8 @@ private: { std::ostringstream oss; oss<<"The minimum (" << GetParameterFloat( "minmax.manuel.min" ) << - ") is superior to the maximum (" << GetParameterFloat( "minmax.manuel.max" ) + ") is superior to the maximum (" + << GetParameterFloat( "minmax.manuel.max" ) << ") please correct this error or allow the application to compute " "those parameters"; otbAppLogFATAL( << oss.str() ) @@ -601,7 +601,8 @@ private: m_BufferFilter[channel] = BufferFilterType::New(); m_BufferFilter[channel]->SetInput( input ); m_GainLutFilter[channel]->SetInput ( m_Histogram[channel] ); - m_StreamingFilter[channel]->SetInput( m_GainLutFilter[channel]->GetOutput() ); + m_StreamingFilter[channel]->SetInput( + m_GainLutFilter[channel]->GetOutput() ); m_ApplyFilter[channel]->SetInputImage ( m_BufferFilter[channel]->GetOutput() ); m_ApplyFilter[channel]->SetInputLut( @@ -693,7 +694,6 @@ private: m_LuminanceFunctor->GetFunctor().SetLumCoef( lumCoef ); m_LuminanceFunctor->SetInput( inImage ); m_LuminanceFunctor->UpdateOutputInformation(); - // std::cout<<m_LuminanceFunctor->GetOutput()->GetNumberOfComponentsPerPixel()<<std::endl; } // Equalize the luminance and apply the corresponding gain on each channel @@ -815,7 +815,7 @@ private: HistogramType::IndexType zero; HistogramType::Pointer & histoToThresh = m_Histogram[j]; zero.Fill(0); - for( unsigned int i = 0 ; i < nbBin ; i++ ) + for ( unsigned int i = 0 ; i < nbBin ; i++ ) { if ( histoToThresh->GetPixel(zero)[i] > height ) { @@ -825,7 +825,7 @@ private: } height = rest / nbBin; rest = rest % nbBin; - for( unsigned int i = 0 ; i < nbBin ; i++ ) + for ( unsigned int i = 0 ; i < nbBin ; i++ ) { histoToThresh->GetPixel(zero)[i] += height ; if ( i > (nbBin - rest)/2 && i <= (nbBin - rest)/2 + rest ) @@ -843,15 +843,19 @@ private: unsigned int nbBin( GetParameterInt( "bins" ) ); HistoPersistentFilterType::HistogramType::Pointer histo; - FloatImageType::SpacingType inputSpacing ( GetParameterImage("in")->GetSpacing() ); - FloatImageType::PointType inputOrigin ( GetParameterImage("in")->GetOrigin() ); + FloatImageType::SpacingType inputSpacing ( + GetParameterImage("in")->GetSpacing() ); + FloatImageType::PointType inputOrigin ( + GetParameterImage("in")->GetOrigin() ); HistogramType::SpacingType histoSpacing ; histoSpacing[0] = inputSpacing[0] * m_ThumbSize[0] ; histoSpacing[1] = inputSpacing[1] * m_ThumbSize[1] ; HistogramType::PointType histoOrigin ; - histoOrigin[0] = histoSpacing[0] / 2 + inputOrigin[0] - inputSpacing[0] / 2 ; - histoOrigin[1] = histoSpacing[1] / 2 + inputOrigin[1] - inputSpacing[1] / 2 ; + histoOrigin[0] = histoSpacing[0] / 2 + + inputOrigin[0] - inputSpacing[0] / 2 ; + histoOrigin[1] = histoSpacing[1] / 2 + + inputOrigin[1] - inputSpacing[1] / 2 ; for ( unsigned int i = 0 ; i < histoList->Size() ; i++ ) { diff --git a/Modules/Applications/AppFiltering/test/CMakeLists.txt b/Modules/Applications/AppFiltering/test/CMakeLists.txt index 9c4a802688..bdf1671b8c 100644 --- a/Modules/Applications/AppFiltering/test/CMakeLists.txt +++ b/Modules/Applications/AppFiltering/test/CMakeLists.txt @@ -48,6 +48,11 @@ otb_test_application(NAME apTvUtSmoothingTest_OutXML VALID --compare-image ${NOTOL} ${BASELINE}/apTvUtSmoothingTest.tif ${TEMP}/apTvUtSmoothingTest_OutXML.tif) + +#----------- Contrast TESTS ---------------- + + + diff --git a/Modules/Filtering/Contrast/test/CMakeLists.txt b/Modules/Filtering/Contrast/test/CMakeLists.txt index f7bd3a8cd8..a97aace437 100644 --- a/Modules/Filtering/Contrast/test/CMakeLists.txt +++ b/Modules/Filtering/Contrast/test/CMakeLists.txt @@ -38,4 +38,51 @@ target_link_libraries(otbContrastTestDriver ${OTBContrast-Test_LIBRARIES}) otb_module_target_label(otbContrastTestDriver) otb_add_test(NAME bfTuCLHistogramEqualizationFilterNew COMMAND otbContrastTestDriver - otbCLHistogramEqualizationFilterNew) \ No newline at end of file + otbCLHistogramEqualizationFilterNew) + +otb_add_test(NAME bfTuApplyGainFilterNew COMMAND otbContrastTestDriver + otbApplyGainFilterNew) + +otb_add_test(NAME bfTuComputeGainLutFilterNew COMMAND otbContrastTestDriver + otbComputeGainLutFilterNew) + +otb_add_test(NAME bfTuComputeHistoFilterNew COMMAND otbContrastTestDriver + otbComputeHistoFilterNew) + +otb_add_test(NAME bfTvComputeHistoFilter COMMAND otbContrastTestDriver + --compare-image ${EPSILON_7} + ${BASELINE}/bfTvComputeHistoFilter.tif + ${TEMP}/bfTvComputeHistoFilter.tif + otbComputeHistoFilter + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/inputHisto_QB_Suburb.tif + ) + +otb_add_test(NAME bfTvComputeGainLutFilter COMMAND otbContrastTestDriver + --compare-image ${EPSILON_7} + ${BASELINE}/bfTvComputeGainLutFilter.tif + ${TEMP}/bfTvComputeGainLutFilter.tif + otbComputeGainLutFilter + ${INPUTDATA}/QB_Suburb.png + ${INPUTDATA}/inputHisto_QB_Suburb.tif + ${TEMP}/inputLut_QB_Suburb.tif + ) + +otb_add_test(NAME bfTvApplyGainFilter COMMAND otbContrastTestDriver + --compare-image ${EPSILON_7} + ${BASELINE}/bfTvApplyGainFilter.tif + ${TEMP}/bfTvApplyGainFilter.tif + otbApplyGainFilter + ${INPUTDATA}/QB_Suburb.png + ${INPUTDATA}/inputLut_QB_Suburb.tif + ${TEMP}/bfTvApplyGainFilter.tif + ) + +otb_add_test(NAME bfTvCLHistoEqFilter COMMAND otbContrastTestDriver + --compare-image ${EPSILON_7} + ${BASELINE}/bfTvApplyGainFilter.tif + ${TEMP}/bfTvCLHistoEqFilter.tif + otbCLHistogramEqualizationFilter + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/bfTvCLHistoEqFilter.tif + ) \ No newline at end of file diff --git a/Modules/Filtering/Contrast/test/otbApplyGainFilter.cxx b/Modules/Filtering/Contrast/test/otbApplyGainFilter.cxx index 19d119e1f2..f16636f5fb 100644 --- a/Modules/Filtering/Contrast/test/otbApplyGainFilter.cxx +++ b/Modules/Filtering/Contrast/test/otbApplyGainFilter.cxx @@ -24,7 +24,7 @@ #include "otbVectorImage.h" #include "otbApplyGainFilter.h" -int otbApplyGainFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) +int otbApplyGainFilter(int itkNotUsed(argc), char * argv []) { typedef int InputPixelType; typedef double LutPixelType; @@ -42,9 +42,9 @@ int otbApplyGainFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) ReaderType::Pointer reader ( ReaderType::New() ); ReaderLutType::Pointer readerLut ( ReaderLutType::New() ); WriterType::Pointer writer ( WriterType::New() ); - reader->SetFileName( "/home/antoine/dev/my_data/test/smallinput.tif" ); - readerLut->SetFileName( "/home/antoine/dev/my_data/test/small_glob_lut_ref.tif" ); - writer->SetFileName( "/home/antoine/dev/my_data/test/small_glob_apply.tif" ); + reader->SetFileName( argv[1] ); + readerLut->SetFileName( argv[2] ); + writer->SetFileName( argv[3] ); reader->UpdateOutputInformation(); readerLut->UpdateOutputInformation(); diff --git a/Modules/Filtering/Contrast/test/otbCLHistogramEqualizationFilter.cxx b/Modules/Filtering/Contrast/test/otbCLHistogramEqualizationFilter.cxx index 4094ec451a..403fa06d79 100644 --- a/Modules/Filtering/Contrast/test/otbCLHistogramEqualizationFilter.cxx +++ b/Modules/Filtering/Contrast/test/otbCLHistogramEqualizationFilter.cxx @@ -23,7 +23,7 @@ #include "otbImage.h" #include "otbCLHistogramEqualizationFilter.h" -int otbCLHistogramEqualizationFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) +int otbCLHistogramEqualizationFilter(int itkNotUsed(argc), char * argv []) { typedef int InputPixelType; const unsigned int Dimension = 2; @@ -36,20 +36,22 @@ int otbCLHistogramEqualizationFilter(int itkNotUsed(argc), char * itkNotUsed(arg ReaderType::Pointer reader ( ReaderType::New() ); WriterType::Pointer writer ( WriterType::New() ); - reader->SetFileName( "/home/antoine/dev/my_data/test/smallinput.tif" ); - writer->SetFileName( "/home/antoine/dev/my_data/test/small_glob_clahe.tif" ); + reader->SetFileName( argv[1] ); + writer->SetFileName( argv[2] ); reader->UpdateOutputInformation(); + FilterType::Pointer histoEqualize ( FilterType::New() ); + histoEqualize->SetInput( reader->GetOutput() ); histoEqualize->SetMin(0); histoEqualize->SetMax(255); histoEqualize->SetNbBin(256); - InputImageType::SizeType size; - size[0] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]; - size[1] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; - histoEqualize->SetThumbSize(size); - // histoEqualize->SetThreshold(100); - writer->SetInput(histoEqualize->GetOutput()); + auto size = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); + size[0] /= 4; + size[1] /= 4; + histoEqualize->SetThumbSize( size ); + + writer->SetInput( histoEqualize->GetOutput() ); writer->Update(); return EXIT_SUCCESS; } diff --git a/Modules/Filtering/Contrast/test/otbComputeGainLutFilter.cxx b/Modules/Filtering/Contrast/test/otbComputeGainLutFilter.cxx index ec5e0532af..77a8c3fdeb 100644 --- a/Modules/Filtering/Contrast/test/otbComputeGainLutFilter.cxx +++ b/Modules/Filtering/Contrast/test/otbComputeGainLutFilter.cxx @@ -24,7 +24,7 @@ #include "otbImageFileReader.h" #include "otbComputeGainLutFilter.h" -int otbComputeGainLutFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) +int otbComputeGainLutFilter(int itkNotUsed(argc), char * argv []) { typedef int InputPixelType; typedef double OutputPixelType; @@ -41,9 +41,9 @@ int otbComputeGainLutFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) ReaderImageType::Pointer readerImage( ReaderImageType::New() ); ReaderType::Pointer reader( ReaderType::New() ); WriterType::Pointer writer ( WriterType::New() ); - readerImage->SetFileName( "/home/antoine/dev/my_data/test/smallinput.tif" ); - reader->SetFileName( "/home/antoine/dev/my_data/test/small_glob_histo_ref.tif" ); - writer->SetFileName( "/home/antoine/dev/my_data/test/small_glob_lut.tif" ); + readerImage->SetFileName( argv[1] ); + reader->SetFileName( argv[2] ); + writer->SetFileName( argv[3] ); reader->UpdateOutputInformation(); readerImage->UpdateOutputInformation(); @@ -53,7 +53,9 @@ int otbComputeGainLutFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) computeGainLut->SetMin(0); computeGainLut->SetMax(255); auto size = readerImage->GetOutput()->GetLargestPossibleRegion().GetSize(); - auto nbPix = size[0]*size[1]; + size[0] /= 4; + size[1] /= 4; + auto nbPix = size[0]*size[1] ; computeGainLut->SetNbPixel( nbPix ); writer->SetInput( computeGainLut->GetOutput() ); diff --git a/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx b/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx index db5deeeebf..f8407bee8d 100644 --- a/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx +++ b/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx @@ -24,7 +24,7 @@ #include "otbVectorImage.h" #include "otbComputeHistoFilter.h" -int otbComputeHistoFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) +int otbComputeHistoFilter(int itkNotUsed(argc), char * argv []) { typedef int InputPixelType; typedef int OutputPixelType; @@ -38,8 +38,8 @@ int otbComputeHistoFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) typedef otb::ImageFileWriter< HistoImageType > WriterType; ReaderType::Pointer reader ( ReaderType::New() ); WriterType::Pointer writer ( WriterType::New() ); - reader->SetFileName( "/home/antoine/dev/my_data/test/smallinput.tif" ); - writer->SetFileName( "/home/antoine/dev/my_data/test/small_glob_histo.tif" ); + reader->SetFileName( argv[1] ); + writer->SetFileName( argv[2] ); reader->UpdateOutputInformation(); FilterType::Pointer computeHisto ( FilterType::New() ); @@ -48,14 +48,12 @@ int otbComputeHistoFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) computeHisto->SetMin(0); computeHisto->SetMax(255); computeHisto->SetNbBin(256); - // computeHisto->SetThreshol(256); auto size = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); - computeHisto->SetThumbSize(size); + size[0] /= 4; + size[1] /= 4; + computeHisto->SetThumbSize( size ); writer->SetInput( computeHisto->GetHistoOutput() ); writer->Update(); - auto index = computeHisto->GetHistoOutput()->GetLargestPossibleRegion().GetIndex(); - std::cout << computeHisto->GetHistoOutput()->GetPixel(index) << std::endl; - return EXIT_SUCCESS; } \ No newline at end of file diff --git a/Modules/Filtering/Contrast/test/otbHelperCLAHE.cxx b/Modules/Filtering/Contrast/test/otbHelperCLAHE.cxx index 6a2461d0ce..b1fc8953f6 100644 --- a/Modules/Filtering/Contrast/test/otbHelperCLAHE.cxx +++ b/Modules/Filtering/Contrast/test/otbHelperCLAHE.cxx @@ -25,7 +25,7 @@ #include "itkImageRegionIterator.h" #include "otbCLHistogramEqualizationFilter.h" -int otbHelperCLAHE(int itkNotUsed(argc), char * itkNotUsed(argv) []) +int otbHelperCLAHE(int itkNotUsed(argc), char * argv []) { typedef int InputPixelType; const unsigned int Dimension = 2; @@ -35,8 +35,8 @@ int otbHelperCLAHE(int itkNotUsed(argc), char * itkNotUsed(argv) []) typedef otb::ImageFileWriter< InputImageType > WriterType; ReaderType::Pointer reader ( ReaderType::New() ); WriterType::Pointer writer ( WriterType::New() ); - reader->SetFileName( "/home/antoine/dev/my_data/smallinputmono.tif" ); - writer->SetFileName( "/home/antoine/dev/my_data/smallnewtest.tif" ); + reader->SetFileName( argv[1] ); + writer->SetFileName( argv[2] ); reader->UpdateOutputInformation(); typedef otb::VectorImage< int , 2 > HistogramType; @@ -62,8 +62,7 @@ int otbHelperCLAHE(int itkNotUsed(argc), char * itkNotUsed(argv) []) BufferFilter::Pointer buffer( BufferFilter::New() ); StreamingImageFilter::Pointer streamFilter( StreamingImageFilter::New() ); InputImageType::SizeType size; - size[0] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]; - size[1] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; + size = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); // histoEqualize->SetThreshold(100); histoFilter->SetInput( reader->GetOutput() ); -- GitLab