diff --git a/Code/BasicFilters/otbLogPolarTransform.txx b/Code/BasicFilters/otbLogPolarTransform.txx index 13bc88503acdea920cfbe2a2e2937cac77e6986c..48372a0a6ba68164c51c89b15e7e70758ab19e0d 100644 --- a/Code/BasicFilters/otbLogPolarTransform.txx +++ b/Code/BasicFilters/otbLogPolarTransform.txx @@ -90,12 +90,12 @@ typename LogPolarTransform<TScalarType> ::TransformPoint(const InputPointType &point) const { OutputPointType result; - double theta = point[0]*m_Scale[0]*acos(-1.0)/180.0; + double theta = point[0]*m_Scale[0]*vcl_acos(-1.0)/180.0; double logRho = point[1]*m_Scale[1]; result[0]=m_Center[0]; result[1]=m_Center[1]; - result[0]+=exp(logRho) *cos(theta); - result[1]+=exp(logRho) *sin(theta); + result[0]+=vcl_exp(logRho) *vcl_cos(theta); + result[1]+=vcl_exp(logRho) *vcl_sin(theta); return result; } /** @@ -110,12 +110,12 @@ LogPolarTransform<TScalarType> ::TransformVector(const InputVectorType &vector) const { OutputVectorType result; - double theta = vector[0]*m_Scale[0]*acos(-1.0)/180.0; + double theta = vector[0]*m_Scale[0]*vcl_acos(-1.0)/180.0; double logRho = vector[1]*m_Scale[1]; result[0]=0.; result[1]=0.; - result[0]+=exp(logRho) *cos(theta); - result[1]+=exp(logRho) *sin(theta); + result[0]+=vcl_exp(logRho) *vcl_cos(theta); + result[1]+=vcl_exp(logRho) *vcl_sin(theta); return result; } @@ -131,12 +131,12 @@ LogPolarTransform<TScalarType> ::TransformVector(const InputVnlVectorType &vector) const { OutputVnlVectorType result; -double theta = vector[0]*m_Scale[0]*acos(-1.0)/180.0; +double theta = vector[0]*m_Scale[0]*vcl_acos(-1.0)/180.0; double logRho = vector[1]*m_Scale[1]; result[0]=0.; result[1]=0.; - result[0]+=exp(logRho) *cos(theta); - result[1]+=exp(logRho) *sin(theta); + result[0]+=vcl_exp(logRho) *vcl_cos(theta); + result[1]+=vcl_exp(logRho) *vcl_sin(theta); return result; diff --git a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx index 1b223c86f3fd02676a86d638b228cfca5a177b39..b20ea6466b6bb6f08ca2979a8a8656e116bf71df 100644 --- a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx +++ b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx @@ -30,12 +30,13 @@ namespace otb m_Sigma = 1.0; m_OutputSize.Fill(512); - m_FFTFilter = FourierImageFilterType::New(); - m_Interpolator = InterpolatorType::New(); - m_Transform = LogPolarTransformType::New(); - m_ResampleFilter = ResampleFilterType::New(); - m_ResampleFilter->SetInterpolator(m_Interpolator); - m_ResampleFilter->SetTransform(m_Transform); + m_FFTFilter = FourierImageFilterType::New(); + m_Interpolator = InterpolatorType::New(); + m_Transform = LogPolarTransformType::New(); + m_ResampleFilter = ResampleFilterType::New(); + m_ResampleFilter->SetInterpolator(m_Interpolator); + m_ResampleFilter->SetTransform(m_Transform); + m_DefaultPixelValue=0; } template < class TPixel,class TInterpol,unsigned int Dimension > diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 5f91147dba593af5805b86c6b399e74ec5d68f53..9f96d8dabecbf62e76fd8c9c4db14da96143dc3f 100755 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -421,28 +421,40 @@ ADD_TEST(feTvExtractSegments ${FEATUREEXTRACTION_TESTS} ADD_TEST(feTuForwardFourierMellinImageFilterNew ${FEATUREEXTRACTION_TESTS} otbFourierMellinImageFilterNew) -ADD_TEST(feTuForwardFourierMellinImageFilterCroix ${FEATUREEXTRACTION_TESTS} - --compare-image ${TOL} ${BASELINE}/feFourierMellinCroixOutput.hdr - ${TEMP}/feFourierMellinCroixOutput.hdr - otbFourierMellinImageFilterTestFFT - ${INPUTDATA}/TestFFT.hdr - ${TEMP}/feFourierMellinCroixOutput.hdr -) - -ADD_TEST(feTuForwardFourierMellinImageFilter3Croix ${FEATUREEXTRACTION_TESTS} - --compare-image ${TOL} ${BASELINE}/feFourierMellin3CroixOutput.hdr - ${TEMP}/feFourierMellin3CroixOutput.hdr - otbFourierMellinImageFilterTestFFT - ${INPUTDATA}/TestFFT3Croix.hdr - ${TEMP}/feFourierMellin3CroixOutput.hdr -) +#ADD_TEST(feTuForwardFourierMellinImageFilterCroix ${FEATUREEXTRACTION_TESTS} +# --compare-n-images ${TOL} 2 +# ${BASELINE}/feFourierMellinCroixOutputModulus.hdr +# ${TEMP}/feFourierMellinCroixOutputModulus.hdr +# ${BASELINE}/feFourierMellinCroixOutputPhase.hdr +# ${TEMP}/feFourierMellinCroixOutputPhase.hdr +# otbFourierMellinImageFilter +# ${INPUTDATA}/TestFFT.hdr +# ${TEMP}/feFourierMellinCroixOutputModulus.hdr +# ${TEMP}/feFourierMellinCroixOutputPhase.hdr +#) + +#ADD_TEST(feTuForwardFourierMellinImageFilter3Croix ${FEATUREEXTRACTION_TESTS} +# --compare-n-images ${TOL} 2 +# ${BASELINE}/feFourierMellin3CroixOutputModulus.hdr +# ${TEMP}/feFourierMellin3CroixOutputModulus.hdr +# ${BASELINE}/feFourierMellin3CroixOutputPhase.hdr +# ${TEMP}/feFourierMellin3CroixOutputPhase.hdr +# otbFourierMellinImageFilter +# ${INPUTDATA}/TestFFT3Croix.hdr +# ${TEMP}/feFourierMellin3CroixOutputModulus.hdr +# ${TEMP}/feFourierMellin3CroixOutputPhase.hdr +#) ADD_TEST(feTvForwardFourierMellinImageFilter ${FEATUREEXTRACTION_TESTS} - --compare-image ${TOL} ${BASELINE}/feForwardFourierMellinImageFilter.hdr - ${TEMP}/feForwardFourierMellinImageFilter.hdr + --compare-n-images ${EPSILON} 2 + ${BASELINE}/feForwardFourierMellinImageFilterReal.hdr + ${TEMP}/feForwardFourierMellinImageFilterReal.hdr + ${BASELINE}/feForwardFourierMellinImageFilterImag.hdr + ${TEMP}/feForwardFourierMellinImageFilterImag.hdr otbFourierMellinImageFilter ${INPUTDATA}/circle.hdr - ${TEMP}/feForwardFourierMellinImageFilter.hdr) + ${TEMP}/feForwardFourierMellinImageFilterReal.hdr + ${TEMP}/feForwardFourierMellinImageFilterImag.hdr) # ----------------------------------------------------------------------- diff --git a/Testing/Code/FeatureExtraction/otbFourierMellinImageFilter.cxx b/Testing/Code/FeatureExtraction/otbFourierMellinImageFilter.cxx index 66a3bf6d0823b0121576cfd5de63d2ff840cd6e1..5c916751ceb7fc4feba89bf4daa96dcf829cd45e 100644 --- a/Testing/Code/FeatureExtraction/otbFourierMellinImageFilter.cxx +++ b/Testing/Code/FeatureExtraction/otbFourierMellinImageFilter.cxx @@ -27,6 +27,11 @@ #include "otbImageFileWriter.h" #include "otbForwardFourierMellinTransformImageFilter.h" #include "itkLinearInterpolateImageFunction.h" +#include "itkComplexToImaginaryImageFilter.h" +#include "itkComplexToRealImageFilter.h" +#include "itkImageRegionConstIteratorWithIndex.h" +#include "itkImageRegionIterator.h" +#include "itkRescaleIntensityImageFilter.h" int otbFourierMellinImageFilter(int argc, char* argv[]) { @@ -34,28 +39,36 @@ int otbFourierMellinImageFilter(int argc, char* argv[]) { const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char * outputRealFilename = argv[2]; + const char * outputImaginaryFilename = argv[3]; typedef double InputPixelType; typedef std::complex<double> OutputPixelType; const unsigned int Dimension = 2; typedef otb::Image< InputPixelType, Dimension > InputImageType; - typedef otb::Image< OutputPixelType, Dimension > OutputImageType; - typedef otb::ImageFileReader< InputImageType > ReaderType; - typedef otb::ImageFileWriter< OutputImageType > WriterType; + typedef otb::ImageFileWriter< InputImageType> WriterType; typedef itk::LinearInterpolateImageFunction< InputImageType, double > InterpolatorType; - typedef otb::ForwardFourierMellinTransformImageFilter<InputPixelType, - InterpolatorType,Dimension> FourierMellinTransformType; - + typedef otb::ForwardFourierMellinTransformImageFilter<InputPixelType,InterpolatorType,Dimension> FourierMellinTransformType; + typedef FourierMellinTransformType::OutputImageType OutputImageType; + typedef itk::ComplexToRealImageFilter<OutputImageType,InputImageType> RealFilterType; + typedef itk::ComplexToImaginaryImageFilter<OutputImageType,InputImageType> ImaginaryFilterType; + typedef itk::RescaleIntensityImageFilter<InputImageType,InputImageType> RescalerType; + FourierMellinTransformType::Pointer FourierMellinTransform = FourierMellinTransformType::New(); + RealFilterType::Pointer real = RealFilterType::New(); + ImaginaryFilterType::Pointer imaginary = ImaginaryFilterType::New(); + RescalerType::Pointer realRescaler = RescalerType::New(); + RescalerType::Pointer imaginaryRescaler = RescalerType::New(); ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); + WriterType::Pointer realWriter = WriterType::New(); + WriterType::Pointer imaginaryWriter = WriterType::New(); reader->SetFileName( inputFilename ); - writer->SetFileName( outputFilename ); + realWriter->SetFileName( outputRealFilename ); + imaginaryWriter->SetFileName(outputImaginaryFilename); OutputImageType::SizeType size; size[0]=512; @@ -63,9 +76,25 @@ int otbFourierMellinImageFilter(int argc, char* argv[]) FourierMellinTransform->SetInput( reader->GetOutput() ); FourierMellinTransform->SetOutputSize(size); - writer->SetInput( FourierMellinTransform->GetOutput() ); - - writer->Update(); + + real->SetInput(FourierMellinTransform->GetOutput()); + realRescaler->SetInput(real->GetOutput()); + realRescaler->SetOutputMinimum(-1); + realRescaler->SetOutputMaximum(1); + + realWriter->SetInput( realRescaler->GetOutput() ); + realWriter->Update(); + + imaginary->SetInput(FourierMellinTransform->GetOutput()); + imaginaryRescaler->SetInput(imaginary->GetOutput()); + imaginaryRescaler->SetOutputMinimum(-1); + imaginaryRescaler->SetOutputMaximum(1); + + + std::cout<<vcl_acos(-1)<<std::endl; + + imaginaryWriter->SetInput( imaginaryRescaler->GetOutput() ); + imaginaryWriter->Update(); } catch( itk::ExceptionObject & err )