diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 71c2900977f4ca7bf585b078249ec545ee790236..79adbd2482c6d906c703a9bae6aed32c69abb55a 100644 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -2709,12 +2709,12 @@ ADD_TEST(ioTvTileMapImageIOHelperTest ${IO_TESTS21} ADD_TEST(ioTvImageDoubleToImageComplex ${IO_TESTS21} otbImageDoubleToImageComplex - ${INPUTDATA}/monobandunsignedchar.png + ${INPUTDATA}/monobandUnsignedInt.tif ) ADD_TEST(ioTvImageComplexToImageDouble ${IO_TESTS21} otbImageComplexToImageDouble - ${INPUTDATA}/monobandComplexDouble.hdr + ${INPUTDATA}/monobandComplexDouble ) ADD_TEST(ioTvImageComplexToImageComplex ${IO_TESTS21} @@ -2732,7 +2732,30 @@ ADD_TEST(ioTvImageComplexToVectorImageComplex ${IO_TESTS21} ${INPUTDATA}/monobandComplexDouble.hdr ) +ADD_TEST(ioTvVectorImageDoubleToImageComplex ${IO_TESTS21} + otbVectorImageDoubleToImageComplex + ${INPUTDATA}/multibandUnsignedInt.tif +) +ADD_TEST(ioTvVectorImageDoubleToVectorImageComplex ${IO_TESTS21} + otbVectorImageDoubleToVectorImageComplex + ${INPUTDATA}/multibandUnsignedInt.tif +) + +ADD_TEST(ioTvVectorImageComplexToVectorImageDouble ${IO_TESTS21} + otbVectorImageComplexToVectorImageDouble + ${INPUTDATA}/multibandComplexDouble.hdr +) + +ADD_TEST(ioTvVectorImageComplexToVectorImageComplex ${IO_TESTS21} + otbVectorImageComplexToVectorImageComplex + ${INPUTDATA}/multibandComplexDouble.hdr +) + +ADD_TEST(ioTvImageDoubleToVectorImageComplex ${IO_TESTS21} + otbImageDoubleToVectorImageComplex + ${INPUTDATA}/monobandUnsignedInt.tif +) #---------------------------------------------------------------------------------- SET(BasicIO_SRCS1 diff --git a/Testing/Code/IO/otbComplexImageManipulationTest.cxx b/Testing/Code/IO/otbComplexImageManipulationTest.cxx index 8f00552f996a352525e673337974d4f370a29521..86c135dd610fd2f5f2bb4479110165ca9a5c527a 100644 --- a/Testing/Code/IO/otbComplexImageManipulationTest.cxx +++ b/Testing/Code/IO/otbComplexImageManipulationTest.cxx @@ -18,7 +18,6 @@ #include <complex> #include "otbImageFileReader.h" -//#include "otbImageFileWriter.h" #include "otbImage.h" #include "otbVectorImage.h" #include "otbMacro.h" @@ -28,13 +27,10 @@ int otbImageDoubleToImageComplex(int argc, char * argv[]) { - typedef double RealType; - typedef std::complex<RealType> PixelType; - typedef otb::Image<PixelType, 2> CplxImageType; - //typedef otb::Image<RealType, 2> ScalImageType; - - typedef otb::ImageFileReader<CplxImageType> ReaderType; - + typedef double RealType; + typedef std::complex<RealType> PixelType; + typedef otb::Image<PixelType, 2> CplxImageType; + typedef otb::ImageFileReader<CplxImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); @@ -55,26 +51,20 @@ int otbImageDoubleToImageComplex(int argc, char * argv[]) itk::ImageRegionIteratorWithIndex<CplxImageType> it( reader->GetOutput(), region ); + unsigned int count = 0; it.GoToBegin(); while( it.IsAtEnd()==false ) { - if(it.Get().real() != static_cast<RealType>(it.GetIndex()[0])) + if( (it.Get().real() != static_cast<RealType>(count)) || (it.Get().imag() != static_cast<RealType>(0)) ) { - std::cout<<"Image double read as Image complex error : read real part "<<it.Get().real()<<", waited for "<<it.GetIndex()[0]<<"."<<std::endl; + std::cout<<"Image double read as Image complex error : "<<it.Get()<<", waited for ("<<count<<", 0)"<<std::endl; return EXIT_FAILURE; } - else if(it.Get().imag() != static_cast<RealType>(0)) - { - std::cout<<"Image double read as Image complex error : read imaginary part "<<it.Get().imag()<<", waited for "<<0<<"."<<std::endl; - - return EXIT_FAILURE; - } - + count++; ++it; } - return EXIT_SUCCESS; } @@ -159,21 +149,14 @@ int otbImageComplexToImageComplex(int argc, char * argv[]) it.GoToBegin(); while( it.IsAtEnd()==false ) { - if(it.Get().real() != static_cast<RealType>(count)) - { - std::cout<<"Image double read as Image complex error in real part: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; - - return EXIT_FAILURE; - } - else if(it.Get().imag() != static_cast<RealType>(count+1) ) + if( (it.Get().real() != static_cast<RealType>(count)) || ( it.Get().imag() != static_cast<RealType>(count+1) ) ) { - std::cout<<"Image double read as Image complex error in imaginary part: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; + std::cout<<"Image complex read as Image complex error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; return EXIT_FAILURE; } count += 2; - ++it; } @@ -187,7 +170,6 @@ int otbImageComplexToVectorImageDouble(int argc, char * argv[]) { typedef double RealType; typedef otb::VectorImage<RealType, 2> ScalVectorImageType; - typedef otb::ImageFileReader<ScalVectorImageType> ReaderType; @@ -214,15 +196,103 @@ int otbImageComplexToVectorImageDouble(int argc, char * argv[]) it.GoToBegin(); while( it.IsAtEnd()==false ) { - if(it.Get()[0] != static_cast<RealType>(count)) + if( (it.Get()[0] != static_cast<RealType>(count)) || (it.Get()[1] != static_cast<RealType>(count+1)) ) { - std::cout<<"Image double read as Image complex error read real part: "<<it.Get()[0]<<", waited for "<<count<<"."<<std::endl; + std::cout<<"Image complex read as Vector Image double error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; return EXIT_FAILURE; } - else if(it.Get()[1] != static_cast<RealType>(count+1)) + + count += 2; + ++it; + } + + + return EXIT_SUCCESS; +} + + +int otbImageComplexToVectorImageComplex(int argc, char * argv[]) +{ + typedef double RealType; + typedef std::complex<RealType> PixelType; + typedef otb::VectorImage<PixelType, 2> CmplxVectorImageType; + typedef otb::ImageFileReader<CmplxVectorImageType> ReaderType; + + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + + CmplxVectorImageType::IndexType id; + CmplxVectorImageType::SizeType size; + CmplxVectorImageType::RegionType region; + + id.Fill(0); + size[0] = 10; + size[1] = 1; + + region.SetSize( size ); + region.SetIndex( id ); + + reader->GetOutput()->SetRequestedRegion(region); + reader->Update(); + + itk::ImageRegionIterator<CmplxVectorImageType> it( reader->GetOutput(), region ); + + unsigned int count = 0; + it.GoToBegin(); + while( it.IsAtEnd()==false ) + { + if( (it.Get()[0].real() != static_cast<RealType>(count)) || ( it.Get()[0].imag() != static_cast<RealType>(count+1) ) ) { - std::cout<<"Image double read as Image complex error : read imaginary part: "<<it.Get()[1]<<", waited for "<<count<<"."<<std::endl; + std::cout<<"Image complex read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; + + return EXIT_FAILURE; + } + + count += 2; + ++it; + } + + + return EXIT_SUCCESS; +} + + +int otbVectorImageDoubleToImageComplex(int argc, char * argv[]) +{ + typedef double RealType; + typedef std::complex<RealType> PixelType; + typedef otb::Image<PixelType, 2> CmplxImageType; + typedef otb::ImageFileReader<CmplxImageType> ReaderType; + + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + + CmplxImageType::IndexType id; + CmplxImageType::SizeType size; + CmplxImageType::RegionType region; + + id.Fill(0); + size[0] = 10; + size[1] = 1; + + region.SetSize( size ); + region.SetIndex( id ); + + reader->GetOutput()->SetRequestedRegion(region); + reader->Update(); + + itk::ImageRegionIterator<CmplxImageType> it( reader->GetOutput(), region ); + + unsigned int count = 0; + it.GoToBegin(); + while( it.IsAtEnd()==false ) + { + if(it.Get().real() != static_cast<RealType>(count) || (it.Get().imag() != static_cast<RealType>(count+1)) ) + { + std::cout<<"Vector Image double read as Image double error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; return EXIT_FAILURE; } @@ -236,7 +306,7 @@ int otbImageComplexToVectorImageDouble(int argc, char * argv[]) } -int otbImageComplexToVectorImageComplex(int argc, char * argv[]) +int otbVectorImageDoubleToVectorImageComplex(int argc, char * argv[]) { typedef double RealType; typedef std::complex<RealType> PixelType; @@ -267,15 +337,56 @@ int otbImageComplexToVectorImageComplex(int argc, char * argv[]) it.GoToBegin(); while( it.IsAtEnd()==false ) { - if(it.Get()[0].real() != static_cast<RealType>(count)) + if(it.Get()[0].real() != static_cast<RealType>(count) || (it.Get()[0].imag() != static_cast<RealType>(0)) ) { - std::cout<<"Image double read as Image complex error : read real part "<<it.Get()[0].real()<<", waited for "<<count<<"."<<std::endl; + std::cout<<"Vector Image double read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", 0)."<<std::endl; return EXIT_FAILURE; } - else if(it.Get()[0].imag() != static_cast<RealType>(count+1)) + + count += 2; + ++it; + } + + + return EXIT_SUCCESS; +} + +int otbVectorImageComplexToVectorImageDouble(int argc, char * argv[]) +{ + typedef double RealType; + typedef otb::VectorImage<RealType, 2> ScalVectorImageType; + typedef otb::ImageFileReader<ScalVectorImageType> ReaderType; + + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + + ScalVectorImageType::IndexType id; + SccalVectorImageType::SizeType size; + ScalVectorImageType::RegionType region; + + id.Fill(0); + size[0] = 10; + size[1] = 1; + + region.SetSize( size ); + region.SetIndex( id ); + + reader->GetOutput()->SetRequestedRegion(region); + reader->Update(); + + itk::ImageRegionIterator<ScalVectorImageType> it( reader->GetOutput(), region ); + unsigned int l_Size = reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[0]* reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[1]; + unsigned int count = 0; + it.GoToBegin(); + while( it.IsAtEnd()==false ) + { + RealType norm1 = static_cast<double>( vcl_sqrt( static_cast<double>( (count*count)+((count+1)*(count+1)) ) ) ); + RealType norm2 = static_cast<double>( vcl_sqrt( static_cast<double>( ((l_size+count)*(l_Size+count))+((l_Size+count+1)*(l_Size+count+1)) ) ) ); + if( (it.Get()[0] != norm1) || (it.Get()[1] != norm2) ) { - std::cout<<"Image double read as Image complex error : read imaginary part "<<it.Get()[0].imag()<<", waited for "<<count<<"."<<std::endl; + std::cout<<"Vector Image complex read as Vector Image double error: "<<it.Get()<<", waited for ("<<norm1<<", "<<norm2<<")."<<std::endl; return EXIT_FAILURE; } @@ -287,3 +398,59 @@ int otbImageComplexToVectorImageComplex(int argc, char * argv[]) return EXIT_SUCCESS; } + + +int otbImageDoubleToVectorImageComplex(int argc, char * argv[]) +{ + typedef double RealType; + typedef std::complex<RealType> PixelType; + typedef otb::VectorImage<PixelType, 2> CmplxVectorImageType; + typedef otb::ImageFileReader<CmplxVectorImageType> ReaderType; + + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + + CmplxVectorImageType::IndexType id; + CmplxVectorImageType::SizeType size; + CmplxVectorImageType::RegionType region; + + id.Fill(0); + size[0] = 10; + size[1] = 1; + + region.SetSize( size ); + region.SetIndex( id ); + + reader->GetOutput()->SetRequestedRegion(region); + reader->Update(); + + if(reader->GetOutput()->GetNumberOfComponentsPerPixel() != 1) + { + std::cout<<"Invalid image size, should be 1, no "<<reader->GetOutput()->GetNumberOfComponentsPerPixel()<<"."<<std::endl; + + return EXIT_FAILURE; + } + + itk::ImageRegionIterator<CmplxVectorImageType> it( reader->GetOutput(), region ); + unsigned int l_Size = reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[0]* reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[1]; + + unsigned int count = 0; + it.GoToBegin(); + while( it.IsAtEnd()==false ) + { + if( (it.Get()[0].real() != static_cast<RealType>(count)) || (it.Get()[0].imag() != 0) ) + { + std::cout<<"Image double read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", 0)."<<std::endl; + + return EXIT_FAILURE; + } + + count++; + ++it; + } + + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/IO/otbIOTests21.cxx b/Testing/Code/IO/otbIOTests21.cxx index acfc3100779dc758ec92e2b5ed2451b4cb760643..9c0bf5842901117d2c6c1b1c3edbd4eac68508cd 100644 --- a/Testing/Code/IO/otbIOTests21.cxx +++ b/Testing/Code/IO/otbIOTests21.cxx @@ -36,4 +36,8 @@ void RegisterTests() REGISTER_TEST(otbImageComplexToImageComplex); REGISTER_TEST(otbImageComplexToVectorImageDouble); REGISTER_TEST(otbImageComplexToVectorImageComplex); + REGISTER_TEST(otbVectorImageDoubleToImageComplex); + REGISTER_TEST(otbVectorImageDoubleToVectorImageComplex); + REGISTER_TEST(otbVectorImageComplexToVectorImageComplex); + REGISTER_TEST(otbImageDoubleToVectorImageComplex); }