diff --git a/Modules/Filtering/ImageManipulation/test/CMakeLists.txt b/Modules/Filtering/ImageManipulation/test/CMakeLists.txt index 17035f96f66fe1d52562e23782a123d628688b83..834a6d3da072adf5c4dbc385d46db7931132de97 100644 --- a/Modules/Filtering/ImageManipulation/test/CMakeLists.txt +++ b/Modules/Filtering/ImageManipulation/test/CMakeLists.txt @@ -624,7 +624,7 @@ otb_add_test(NAME bfTvClampImageFilterTest COMMAND otbImageManipulationTestDrive ) otb_add_test(NAME bfTvClampImageFilterConversionTest COMMAND otbImageManipulationTestDriver - otbClampImageFilterConversionFromRealTest + otbClampImageFilterConversionTest ${INPUTDATA}/veryverySmallFSATSW.tif ) diff --git a/Modules/Filtering/ImageManipulation/test/otbClampImageFilter.cxx b/Modules/Filtering/ImageManipulation/test/otbClampImageFilter.cxx index 20b2a9c3fe81d8f7f813735316b07b1022a07d17..602f524e33b7d4532d84695726a9bd8b5e737485 100644 --- a/Modules/Filtering/ImageManipulation/test/otbClampImageFilter.cxx +++ b/Modules/Filtering/ImageManipulation/test/otbClampImageFilter.cxx @@ -84,6 +84,19 @@ Cross ( std::string const & inputFileName ) return clamp->GetOutput(); } +template < class OutImageType > +typename OutImageType::Pointer +Cross ( otb::VectorImage< std::complex<float> >::Pointer input ) +{ + + typedef otb::ClampImageFilter< otb::VectorImage< std::complex<float> > , + OutImageType > ClampFilter; + typename ClampFilter::Pointer clamp ( ClampFilter::New() ); + clamp->SetInput( input ); + clamp->Update(); + return clamp->GetOutput(); +} + typedef otb::VectorImage<double> ImageRefType; template <class ImageType > @@ -128,7 +141,7 @@ CompareImageReal( const ImageRefType::Pointer imRef , template <class ImageType > bool CompareVectorReal( const ImageRefType::Pointer imRef , - const ImageType * im) + const ImageType * im ) { typedef typename ImageType::InternalPixelType RealPixelType; RealPixelType min = std::numeric_limits< RealPixelType >::lowest(); @@ -140,28 +153,37 @@ CompareVectorReal( const ImageRefType::Pointer imRef , itRef.GoToBegin(); it.GoToBegin(); unsigned int nbChanel = im->GetNumberOfComponentsPerPixel (); + // unsigned int nbChanelRef = imRef->GetNumberOfComponentsPerPixel (); RealPixelType val; double ref; while ( !it.IsAtEnd() ) { + // std::cout<<it.Get()<<std::endl; + // std::cout<<itRef.Get()<<std::endl; for ( unsigned int i = 0 ; i < nbChanel ; i++ ) { val = it.Get()[i]; ref = itRef.Get()[i]; + if ( ref > static_cast<double>( max ) && val != max ) { + std::cout<<"ref : "<<static_cast<RealPixelType>(ref)<<std::endl; + std::cout<<"val : "<<val<<std::endl; return false; } else if ( ref < static_cast<double>( min ) && val != min ) { + std::cout<<"ref : "<<static_cast<RealPixelType>(ref)<<std::endl; + std::cout<<"val : "<<val<<std::endl; return false; } else if ( static_cast<RealPixelType>(ref) != val ) { + std::cout<<"ref : "<<static_cast<RealPixelType>(ref)<<std::endl; + std::cout<<"val : "<<val<<std::endl; return false; } } - std::cout<<itRef.Get()<<std::endl; ++it; ++itRef; } @@ -215,7 +237,8 @@ CompareImageComplex( const ImageRefType::Pointer imageRef , template <class ImageType > bool CompareVectorComplex( const ImageRefType::Pointer imageRef , - const ImageType * im ) + const ImageType * im , + bool fromImage = false) { typedef typename ImageType::InternalPixelType ComplexType; typedef typename ComplexType::value_type RealType; @@ -228,7 +251,9 @@ CompareVectorComplex( const ImageRefType::Pointer imageRef , im->GetLargestPossibleRegion() ); itRef.GoToBegin(); it.GoToBegin(); - unsigned int nbChanel = im->GetNumberOfComponentsPerPixel (); + unsigned int nbChanel = 1; + if ( !fromImage ) + nbChanel = im->GetNumberOfComponentsPerPixel (); ComplexType val; float reRef , imRef; while ( !it.IsAtEnd() ) @@ -238,9 +263,6 @@ CompareVectorComplex( const ImageRefType::Pointer imageRef , val = it.Get()[i]; reRef = itRef.Get()[ 2 * i ]; imRef = itRef.Get()[ 2 * i + 1 ]; - std::cout<<it.Get()[0].real()<<" , "<<it.Get()[0].imag()<<" ; "<< - it.Get()[1].real()<<" , "<<it.Get()[1].imag()<<std::endl; - std::cout<<itRef.Get()<<std::endl; if ( ( reRef > static_cast<double>( max ) && val.real() != max ) || ( imRef > static_cast<double>( max ) && val.imag() != max ) ) { @@ -263,27 +285,127 @@ CompareVectorComplex( const ImageRefType::Pointer imageRef , return true; } -int otbClampImageFilterConversionFromRealTest(int itkNotUsed(argc), char* argv[]) +int otbClampImageFilterConversionTest(int itkNotUsed(argc), char* argv[]) { typedef otb::ImageFileReader< ImageRefType > ReaderType; ReaderType::Pointer reader ( ReaderType::New() ); reader->SetFileName( argv[1] ); reader->Update(); ImageRefType::Pointer imageRef = reader->GetOutput(); - otb::VectorImage< std::complex<float>>::Pointer image1 = - Cross < otb::VectorImage< float > , otb::VectorImage<std::complex<float>> > ( argv[1] ); - bool test1 = CompareVectorComplex < otb::VectorImage<std::complex<float>> >( imageRef , image1 ); + // vect<real> --> vect<real> + otb::VectorImage< short >::Pointer image0 = + Cross < otb::VectorImage< double > , otb::VectorImage< short > > ( argv[1] ); + bool test0 = CompareVectorReal < otb::VectorImage< short > >( imageRef , image0 ); + std::cout<< "Test 0 : "<<test0<<std::endl; + image0 =nullptr; + + // vect<real> --> vect<complex> + otb::VectorImage< std::complex<unsigned short>>::Pointer image1 = + Cross < otb::VectorImage< float > , otb::VectorImage<std::complex<unsigned short>> > ( argv[1] ); + bool test1 = CompareVectorComplex < otb::VectorImage<std::complex<unsigned short>> >( imageRef , image1 ); + std::cout<< "Test 1 : "<<test1<<std::endl; + image1 = nullptr; - otb::Image<double>::Pointer image2 = - Cross < otb::VectorImage< float > , otb::Image<double> > ( argv[1] ); - bool test2 = CompareImageReal < otb::Image<double> >( imageRef , image2 ); + // vect<real> --> image<real> + otb::Image<int>::Pointer image2 = + Cross < otb::VectorImage< float > , otb::Image<int> > ( argv[1] ); + bool test2 = CompareImageReal < otb::Image<int> >( imageRef , image2 ); + std::cout<< "Test 2 : "<<test2<<std::endl; + image2 = nullptr; + // vect<real> --> image<complex> otb::Image< std::complex<float>>::Pointer image3 = Cross < otb::VectorImage< float > , otb::Image<std::complex<float>> > ( argv[1] ); bool test3 = CompareImageComplex < otb::Image<std::complex<float>> >( imageRef , image3 ); + std::cout<< "Test 3 : "<<test3<<std::endl; + image3 = nullptr; + + // image<real> --> image<real> + otb::Image< unsigned short >::Pointer image4 = + Cross < otb::Image< itk::FixedArray < double , 4 > > , otb::Image< unsigned short > > ( argv[1] ); + bool test4 = CompareImageReal < otb::Image< unsigned short > >( imageRef , image4 ); + std::cout<< "Test 4 : "<<test4<<std::endl; + image4 = nullptr; + + // image<real> --> image<complex> + otb::Image< std::complex<int> >::Pointer image5 = + Cross < otb::Image< itk::FixedArray < double , 4 > > , otb::Image< std::complex<int> > > ( argv[1] ); + bool test5 = CompareImageComplex < otb::Image< std::complex<int> > >( imageRef , image5 ); + std::cout<< "Test 5 : "<<test5<<std::endl; + image5 = nullptr; + + // image<real> --> vector<real> + otb::VectorImage< float >::Pointer image6 = + Cross < otb::Image< itk::FixedArray < double , 4 > > , otb::VectorImage< float > > ( argv[1] ); + bool test6 = CompareVectorReal < otb::VectorImage< float > >( imageRef , image6 ); + std::cout<< "Test 6 : "<<test6<<std::endl; + image6 = nullptr; + + // image<real> --> vector<complex> + otb::VectorImage< std::complex<float> >::Pointer image7 = + Cross < otb::Image< itk::FixedArray < double , 4 > > , otb::VectorImage< std::complex<float> > > ( argv[1] ); + bool test7 = CompareVectorComplex < otb::VectorImage< std::complex<float> > >( imageRef , image7 ); + std::cout<< "Test 7 : "<<test7<<std::endl; + + // vector<complex> --> vector<real> + otb::VectorImage< int >::Pointer image8 = + Cross < otb::VectorImage< int > > ( image7 ); + bool test8 = CompareVectorReal < otb::VectorImage< int > >( imageRef , image8 ); + std::cout<< "Test 8 : "<<test8<<std::endl; + image8=nullptr; + + // vector<complex> --> vector<complex> + otb::VectorImage< std::complex<int> >::Pointer image9 = + Cross < otb::VectorImage< std::complex<int> > > ( image7 ); + bool test9 = CompareVectorComplex < otb::VectorImage< std::complex<int> > >( imageRef , image9 ); + std::cout<< "Test 9 : "<<test9<<std::endl; + image9=nullptr; + + // vector<complex> --> image<real> + otb::Image< int >::Pointer image10 = + Cross < otb::Image< int > > ( image7 ); + bool test10 = CompareImageReal < otb::Image< int > >( imageRef , image10 ); + std::cout<< "Test 10 : "<<test10<<std::endl; + image10=nullptr; + + // vector<complex> --> image<complex> + otb::Image< std::complex<unsigned short> >::Pointer image11 = + Cross < otb::Image< std::complex<unsigned short> > > ( image7 ); + bool test11 = CompareImageComplex < otb::Image< std::complex<unsigned short> > >( imageRef , image11 ); + std::cout<< "Test 11 : "<<test11<<std::endl; + image11=nullptr; + + // image<complex> --> vector<complex> + otb::VectorImage<std::complex<float>>::Pointer image12 = + Cross < otb::Image< std::complex<float> > , otb::VectorImage< std::complex<float>> > ( argv[1] ); + bool test12 = CompareVectorComplex < otb::VectorImage<std::complex<float>> >( imageRef , image12 ); + std::cout<< "Test 12 : "<<test12<<std::endl; + image12 = nullptr; + + // image<complex> --> image<complex> + otb::Image< std::complex< short >>::Pointer image13 = + Cross < otb::Image< std::complex<float> > , otb::Image< std::complex< short >> > ( argv[1] ); + bool test13 = CompareImageComplex < otb::Image< std::complex< short >> >( imageRef , image13 ); + std::cout<< "Test 13 : "<<test13<<std::endl; + image13 = nullptr; + + // image<complex> --> image<real> + otb::Image< int >::Pointer image14 = + Cross < otb::Image< std::complex<float> > , otb::Image< int > > ( argv[1] ); + bool test14 = CompareImageReal < otb::Image< int > >( imageRef , image14 ); + std::cout<< "Test 14 : "<<test14<<std::endl; + image14 = nullptr; + + // image<complex> --> vector<real> + otb::VectorImage< unsigned short >::Pointer image15 = + Cross < otb::Image< std::complex<float> > , otb::VectorImage< unsigned short > > ( argv[1] ); + bool test15 = CompareVectorReal < otb::VectorImage< unsigned short > >( imageRef , image15 ); + std::cout<< "Test 15 : "<<test15<<std::endl; + image15 = nullptr; - if (test1 && test2 && test3) + if (test1 && test2 && test3 && test4 && test5 &&test6 && test7 && test8 + && test9 && test10 && test11 && test12 && test13 && test14 && test15 ) return EXIT_SUCCESS; - return 42; + return EXIT_FAILURE; } diff --git a/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx b/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx index da2d733fb90ced66e8b741e946fd26755c486131..c5b59f8ef2d62eb790adf085e5c9121db5f28d4a 100644 --- a/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx +++ b/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx @@ -85,7 +85,7 @@ void RegisterTests() REGISTER_TEST(otbMultiplyByScalarImageFilterTest); REGISTER_TEST(otbClampImageFilterNew); REGISTER_TEST(otbClampImageFilterTest); - REGISTER_TEST(otbClampImageFilterConversionFromRealTest); + REGISTER_TEST(otbClampImageFilterConversionTest); REGISTER_TEST(otbConcatenateVectorImageFilter); REGISTER_TEST(otbBinaryImageMinimalBoundingRegionCalculatorNew); REGISTER_TEST(otbVectorRescaleIntensityImageFilterNew);