diff --git a/Code/BasicFilters/otbHillShadingFunctor.h b/Code/BasicFilters/otbHillShadingFunctor.h index 1d5832755d9906f65c634912aa361af8344fec0b..8eaa280c216e277dac4ff7bfba44f40735e7c7a7 100644 --- a/Code/BasicFilters/otbHillShadingFunctor.h +++ b/Code/BasicFilters/otbHillShadingFunctor.h @@ -44,9 +44,9 @@ public: inline TOutput operator ()(const TInput1& A, const TInput2& B) const { TOutput out; - out.SetRed(A.GetRed() * B); - out.SetGreen(A.GetGreen() * B); - out.SetBlue(A.GetBlue() * B); + out.SetRed( static_cast<typename TOutput::ValueType>(static_cast<double>(A.GetRed()) * static_cast<double>(B)) ); + out.SetGreen( static_cast<typename TOutput::ValueType>(static_cast<double>(A.GetGreen()) * static_cast<double>(B)) ); + out.SetBlue(static_cast<typename TOutput::ValueType>(static_cast<double>(A.GetBlue()) * static_cast<double>(B))); return out; } }; diff --git a/Code/ObjectDetection/otbDescriptorsListSampleGenerator.h b/Code/ObjectDetection/otbDescriptorsListSampleGenerator.h index 8a773dbb06fa2308bb1bab1455b9e46c326154e1..e3340d3cbb597fb5281796987cc04f31b3b75a5c 100644 --- a/Code/ObjectDetection/otbDescriptorsListSampleGenerator.h +++ b/Code/ObjectDetection/otbDescriptorsListSampleGenerator.h @@ -191,7 +191,7 @@ private: #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY if( itk::Math::RoundHalfIntegerUp<IndexValueType>(index[i]) < static_cast<IndexValueType>( region.GetIndex(i) ) + static_cast<IndexValueType>(m_NeighborhoodRadius) ) #else - if( index[i] < static_cast<TCoordRepType>( region.GetIndex(i) ) + m_NeighborhoodRadius ) + if( index[i] < static_cast<IndexValueType>( region.GetIndex(i) ) + m_NeighborhoodRadius ) #endif { return false; diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 433b57a506070f5de101c3855dcee692c8115a8c..e21735c17e525fb6713c6ea4f7034faef9ec221a 100644 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -2734,12 +2734,12 @@ ADD_TEST(ioTvImageComplexToVectorImageComplex ${IO_TESTS21} ADD_TEST(ioTvVectorImageDoubleToImageComplex ${IO_TESTS21} otbVectorImageDoubleToImageComplex - ${INPUTDATA}/multibandUnsignedInt.tif + ${INPUTDATA}/multibandDouble.tif ) ADD_TEST(ioTvVectorImageDoubleToVectorImageComplex ${IO_TESTS21} otbVectorImageDoubleToVectorImageComplex - ${INPUTDATA}/multibandUnsignedInt.tif + ${INPUTDATA}/multibandDouble.tif ) ADD_TEST(ioTvVectorImageComplexToVectorImageDouble ${IO_TESTS21} @@ -2757,6 +2757,21 @@ ADD_TEST(ioTvImageDoubleToVectorImageComplex ${IO_TESTS21} ${INPUTDATA}/monobandDouble.tif ) +ADD_TEST(ioTvVectorImageComplexToImageDouble_2bands ${IO_TESTS21} + otbVectorImageComplexToImageDouble + ${INPUTDATA}/multibandComplexDouble.hdr +) + +ADD_TEST(ioTvVectorImageComplexToImageDouble_3bands ${IO_TESTS21} + otbVectorImageComplexToImageDouble + ${INPUTDATA}/multi3bandsDouble.hdr +) + +ADD_TEST(ioTvVectorImageComplexToImageDouble_4bands ${IO_TESTS21} + otbVectorImageComplexToImageDouble + ${INPUTDATA}/mono3bandsDouble.hdr +) + #---------------------------------------------------------------------------------- SET(BasicIO_SRCS1 otbIOTests1.cxx diff --git a/Testing/Code/IO/otbComplexImageManipulationTest.cxx b/Testing/Code/IO/otbComplexImageManipulationTest.cxx index 79986253072207a2bc301cf8c24a31c6ddd08746..8257bab2229d80bbd10161da524a6f2646f518ea 100644 --- a/Testing/Code/IO/otbComplexImageManipulationTest.cxx +++ b/Testing/Code/IO/otbComplexImageManipulationTest.cxx @@ -63,11 +63,11 @@ int otbImageDoubleToImageComplex(int argc, char * argv[]) count = it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+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 : "<<it.Get()<<", waited for ("<<count<<", 0)"<<std::endl; + { + std::cout<<"Image double read as Image complex error : "<<it.Get()<<", waited for ("<<count<<", 0)"<<std::endl; - return EXIT_FAILURE; - } + return EXIT_FAILURE; + } ++it; } @@ -116,11 +116,11 @@ int otbImageComplexToImageDouble(int argc, char * argv[]) double norm = vcl_sqrt(static_cast<double>( (count*count) + (count+1)*(count+1))); if(it.Get() != static_cast<RealType>(norm)) - { - std::cout<<"Image complex read as Image double error : value (should be norm): "<<it.Get()<<", waited for "<<norm<<"."<<std::endl; - - return EXIT_FAILURE; - } + { + std::cout<<"Image complex read as Image double error : value (should be norm): "<<it.Get()<<", waited for "<<norm<<"."<<std::endl; + + return EXIT_FAILURE; + } ++it; } @@ -169,11 +169,11 @@ int otbImageComplexToImageComplex(int argc, char * argv[]) count = 2*(it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+it.GetIndex()[0]); if( (it.Get().real() != static_cast<RealType>(count)) || ( it.Get().imag() != static_cast<RealType>(count+1) ) ) - { - std::cout<<"Image complex read as Image complex error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; - - return EXIT_FAILURE; - } + { + std::cout<<"Image complex read as Image complex error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; + + return EXIT_FAILURE; + } ++it; @@ -222,11 +222,11 @@ int otbImageComplexToVectorImageDouble(int argc, char * argv[]) count = 2*(it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+it.GetIndex()[0]); if( (it.Get()[0] != static_cast<RealType>(count)) || (it.Get()[1] != static_cast<RealType>(count+1)) ) - { - std::cout<<"Image complex read as Vector Image double error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; - - return EXIT_FAILURE; - } + { + std::cout<<"Image complex read as Vector Image double error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; + + return EXIT_FAILURE; + } //count += 2; ++it; @@ -275,11 +275,11 @@ int otbImageComplexToVectorImageComplex(int argc, char * argv[]) count = 2*(it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+it.GetIndex()[0]); if( (it.Get()[0].real() != static_cast<RealType>(count)) || ( it.Get()[0].imag() != static_cast<RealType>(count+1) ) ) - { - std::cout<<"Image complex read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; - - return EXIT_FAILURE; - } + { + std::cout<<"Image complex read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; + + return EXIT_FAILURE; + } ++it; } @@ -327,11 +327,11 @@ int otbVectorImageDoubleToImageComplex(int argc, char * argv[]) count = 2*(it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+it.GetIndex()[0]); 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; - } + { + std::cout<<"Vector Image double read as Image double error: "<<it.Get()<<", waited for ("<<count<<", "<<count+1<<")"<<std::endl; + + return EXIT_FAILURE; + } ++it; } @@ -379,11 +379,11 @@ int otbVectorImageDoubleToVectorImageComplex(int argc, char * argv[]) count = 2*(it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+it.GetIndex()[0]);; if(it.Get()[0].real() != static_cast<RealType>(count) || (it.Get()[0].imag() != static_cast<RealType>(0)) ) - { - std::cout<<"Vector Image double read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", 0)."<<std::endl; - - return EXIT_FAILURE; - } + { + std::cout<<"Vector Image double read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", 0)."<<std::endl; + + return EXIT_FAILURE; + } ++it; } @@ -432,11 +432,11 @@ int otbVectorImageComplexToVectorImageDouble(int argc, char * argv[]) double norm2 = vcl_sqrt(static_cast<double>((2*l_Size+count)*(2*l_Size+count) + (2*l_Size+count+1)*(2*l_Size+count+1))); if( (it.Get()[0] != norm1) || (it.Get()[1] != norm2) ) - { - std::cout<<"Vector Image complex read as Vector Image double error: "<<it.Get()<<", waited for ("<<norm1<<", "<<norm2<<")."<<std::endl; - - return EXIT_FAILURE; - } + { + std::cout<<"Vector Image complex read as Vector Image double error: "<<it.Get()<<", waited for ("<<norm1<<", "<<norm2<<")."<<std::endl; + + return EXIT_FAILURE; + } ++it; } @@ -489,13 +489,13 @@ int otbVectorImageComplexToVectorImageComplex(int argc, char * argv[]) PixelType cmplx2(2*l_Size+count, 2*l_Size+count+1); if( (it.Get()[0] != cmplx1) || (it.Get()[1] != cmplx2) ) - { - std::cout<<"Image double read as Vector Image complex error: "<<std::endl; - std::cout<<it.Get()[0]<<", waited for "<<cmplx1<<"."<<std::endl; - std::cout<<it.Get()[1]<<", waited for "<<cmplx2<<"."<<std::endl; + { + std::cout<<"Image double read as Vector Image complex error: "<<std::endl; + std::cout<<it.Get()[0]<<", waited for "<<cmplx1<<"."<<std::endl; + std::cout<<it.Get()[1]<<", waited for "<<cmplx2<<"."<<std::endl; - return EXIT_FAILURE; - } + return EXIT_FAILURE; + } ++it; } @@ -552,11 +552,11 @@ int otbImageDoubleToVectorImageComplex(int argc, char * argv[]) count = it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+it.GetIndex()[0]; 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; - } + { + std::cout<<"Image double read as Vector Image complex error: "<<it.Get()[0]<<", waited for ("<<count<<", 0)."<<std::endl; + + return EXIT_FAILURE; + } ++it; } @@ -565,3 +565,102 @@ int otbImageDoubleToVectorImageComplex(int argc, char * argv[]) return EXIT_SUCCESS; } +/*********** + * 11. + * Read VectorImage<complex> as Image<double> + * out : Amplitude(norm(in[0]), norm(in[1], ...) + * Amplitude is defined as in itkConvertPixelBuffer + ***********/ +int otbVectorImageComplexToImageDouble(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 greater than 1."<<std::endl; + + return EXIT_FAILURE; + } + + itk::ImageRegionIteratorWithIndex<CmplxVectorImageType> it( reader->GetOutput(), region ); + unsigned int l_Size = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]* reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; + + unsigned int count = 0; + it.GoToBegin(); + while( it.IsAtEnd()==false ) + { + count = 2*(it.GetIndex()[1]*reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]+it.GetIndex()[0]); + + if(reader->GetOutput()->GetNumberOfComponentsPerPixel() == 2) + { + // Amplitude = input[0] norm * input[1] norm + double norm1 = vcl_sqrt(static_cast<double>( (count*count) + (count+1)*(count+1))); + double norm2 = vcl_sqrt(static_cast<double>( ((2*l_Size+count)*(2*l_Size+count)) + (2*l_Size+count+1)*(2*l_Size+count+1))); + + if( it.Get() != static_cast<RealType>(norm1*norm2)) + { + std::cout<<"Vector Image complex with 2 bands read as Image double error: "<<it.Get()<<", waited for norm value: "<<norm1*norm2<<"."<<std::endl; + + return EXIT_FAILURE; + } + } + else if(reader->GetOutput()->GetNumberOfComponentsPerPixel() == 3) + { + // Amplitude = (2125*norm(input[0]) + 7154*norm(input[1]) + 721*norm(input[2])) / 10000 + double norm1 = vcl_sqrt(static_cast<double>( (count*count) + (count+1)*(count+1))); + double norm2 = vcl_sqrt(static_cast<double>( ((2*l_Size+count)*(2*l_Size+count)) + (2*l_Size+count+1)*(2*l_Size+count+1))); + double norm3 = vcl_sqrt(static_cast<double>( ((4*l_Size+count)*(4*l_Size+count)) + (4*l_Size+count+1)*(4*l_Size+count+1))); + + if( it.Get() != static_cast<RealType>( (2125*norm1+7154*norm2+721*norm3)/10000 ) ) + { + std::cout<<"Vector Image complex with 3 bands read as Image double error: "<<it.Get()<<", waited for norm value: "<<(2125*norm1+7154*norm2+721*norm3)/10000<<"."<<std::endl; + std::cout<<"With: norm1="<<norm1<<", norm2=: "<<norm2<<", norm3= "<<norm3<<"."<<std::endl; + + return EXIT_FAILURE; + } + } + else + { + // Amplitude = (2125*norm(input[0]) + 7154*norm(input[1]) + 721*norm(input[2])) / 10000 + double norm1 = vcl_sqrt(static_cast<double>( (count*count) + (count+1)*(count+1))); + double norm2 = vcl_sqrt(static_cast<double>( ((2*l_Size+count)*(2*l_Size+count)) + (2*l_Size+count+1)*(2*l_Size+count+1))); + double norm3 = vcl_sqrt(static_cast<double>( ((4*l_Size+count)*(4*l_Size+count)) + (4*l_Size+count+1)*(4*l_Size+count+1))); + double norm4 = vcl_sqrt(static_cast<double>( ((6*l_Size+count)*(6*l_Size+count)) + (6*l_Size+count+1)*(6*l_Size+count+1))); + + if( it.Get() != static_cast<RealType>( (2125*norm1+7154*norm2+721*norm3)/10000 * norm4 ) ) + { + std::cout<<"Vector Image complex with 4 bands read as Image double error: "<<it.Get()<<", waited for norm value: "<<(2125*norm1+7154*norm2+721*norm3)/10000*norm4<<"."<<std::endl; + std::cout<<"With: norm1="<<norm1<<", norm2=: "<<norm2<<", norm3= "<<norm3<<", norm4= "<<norm4<<"."<<std::endl; + + return EXIT_FAILURE; + } + + ++it; + } + } + + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/IO/otbIOTests21.cxx b/Testing/Code/IO/otbIOTests21.cxx index 495663ce640507f2d35e006f5127f962b10a36ca..964dd2df95be43dfd70482739ba55a295708b91d 100644 --- a/Testing/Code/IO/otbIOTests21.cxx +++ b/Testing/Code/IO/otbIOTests21.cxx @@ -38,7 +38,8 @@ void RegisterTests() REGISTER_TEST(otbImageComplexToVectorImageComplex); REGISTER_TEST(otbVectorImageDoubleToImageComplex); REGISTER_TEST(otbVectorImageDoubleToVectorImageComplex); - REGISTER_TEST(otbVectorImageComplexToVectorImageDouble); + REGISTER_TEST(otbVectorImageComplexToVectorImageDouble); REGISTER_TEST(otbVectorImageComplexToVectorImageComplex); REGISTER_TEST(otbImageDoubleToVectorImageComplex); + REGISTER_TEST(otbVectorImageComplexToImageDouble); } diff --git a/Testing/Code/Visualization/otbAmplitudeFunctorTest.cxx b/Testing/Code/Visualization/otbAmplitudeFunctorTest.cxx index 2f8bcbc965220fe31658083826f0e427117cfa71..b61998fdc61d25da5e99af841ace27c1a5afaddb 100644 --- a/Testing/Code/Visualization/otbAmplitudeFunctorTest.cxx +++ b/Testing/Code/Visualization/otbAmplitudeFunctorTest.cxx @@ -54,7 +54,7 @@ int otbAmplitudeFunctorTest(int argc, char * argv[]) funct.SetChannelList(channels); output = funct.operator ()(vectorPixel); result = vcl_sqrt(vectorPixel[i] * vectorPixel[i] + vectorPixel[j] * vectorPixel[j]); - if( abs(result-output[0]) > 0.0000001) + if( abs(static_cast<double>(result)-static_cast<double>(output[0])) > 0.0000001) { std::cout << "vectorPixelType Test VectorPixelType failed for channels " << i<< " and " << j << " !" << std::endl; @@ -78,7 +78,7 @@ int otbAmplitudeFunctorTest(int argc, char * argv[]) funct.SetChannelList(channels); output = funct.operator ()(rgbPixel); result = vcl_sqrt(rgbPixel[i] * rgbPixel[i] + rgbPixel[j] * rgbPixel[j]); - if( abs(result-output[0]) > 0.0000001) + if( abs(static_cast<double>(result)-static_cast<double>(output[0])) > 0.0000001) { std::cout << "vectorPixelType Test RGBPixelType failed for channels " << i<< " and " << j << " !" << std::endl; @@ -107,7 +107,7 @@ int otbAmplitudeFunctorTest(int argc, char * argv[]) funct.SetChannelList(channels); output = funct.operator ()(rgbaPixel); result = vcl_sqrt(rgbaPixel[i] * rgbaPixel[i] + rgbaPixel[j] * rgbaPixel[j]); - if( abs(result-output[0]) > 0.0000001) + if( abs(static_cast<double>(result)-static_cast<double>(output[0])) > 0.0000001) { std::cout << "vectorPixelType Test RGBAPixelType failed for channels " << i<< " and " << j << " !" << std::endl; diff --git a/Testing/Utilities/ijGreyLevelRunLengthMatrixTextureCoefficientsCalculatorTest.cxx b/Testing/Utilities/ijGreyLevelRunLengthMatrixTextureCoefficientsCalculatorTest.cxx index 57cbba8bf4a5ba9878238a7c9827a3dad8c05be5..5626436f603084fcf74e0829cc8e4dddb446e5ed 100644 --- a/Testing/Utilities/ijGreyLevelRunLengthMatrixTextureCoefficientsCalculatorTest.cxx +++ b/Testing/Utilities/ijGreyLevelRunLengthMatrixTextureCoefficientsCalculatorTest.cxx @@ -54,7 +54,7 @@ int ijGreyLevelRunLengthMatrixTextureCoefficientsCalculatorTest( int argc, char* numberOfPixelsInMask *= imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[i]; numberOfDirections *= 3; } - numberOfDirections = vcl_floor( 0.5 * numberOfDirections ); + numberOfDirections = static_cast<unsigned int>( vcl_floor( 0.5 * static_cast<double>(numberOfDirections) ) ); unsigned int numberOfBins = 100; try