From 8878ff58d6d1d4724951bac87d19c7cb2d4f03f1 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@c-s.fr>
Date: Tue, 19 Dec 2006 10:59:09 +0000
Subject: [PATCH] =?UTF-8?q?D=C3=A9placements=20de=20la=20nomalisation=20da?=
 =?UTF-8?q?ns=20le=20filtre=20de=20FourrierMellin.=20Correction=20des=20im?=
 =?UTF-8?q?ages=20en=20base=20associ=C3=A9es.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../otbLogPolarResampleImageFilter.h          |  6 --
 .../otbLogPolarResampleImageFilter.txx        | 30 +---------
 ...ForwardFourierMellinTransformImageFilter.h |  7 ++-
 ...rwardFourierMellinTransformImageFilter.txx | 59 +++++++++++++------
 Testing/Code/FeatureExtraction/CMakeLists.txt |  4 +-
 5 files changed, 50 insertions(+), 56 deletions(-)

diff --git a/Code/BasicFilters/otbLogPolarResampleImageFilter.h b/Code/BasicFilters/otbLogPolarResampleImageFilter.h
index b2d427c9b3..271f8eb76c 100644
--- a/Code/BasicFilters/otbLogPolarResampleImageFilter.h
+++ b/Code/BasicFilters/otbLogPolarResampleImageFilter.h
@@ -134,11 +134,6 @@ public:
   /** Get the Angular number of samples. */
   itkGetConstReferenceMacro(AngularNumberOfSamples, double);
 
-  /** Set the Sigma value. */
-  itkSetMacro(Sigma, double);
-  /** Get the Sigma value. */
-  itkGetConstMacro(Sigma, double);
-
   /** LogPolarResampleImageFilter produces an image which is a different size
    * than its input.  As such, it needs to provide an implementation
    * for GenerateOutputInformation() in order to inform the pipeline
@@ -212,7 +207,6 @@ private:
   double		  m_RadialStep;
   double		  m_RadialNumberOfSamples;
   double		  m_AngularNumberOfSamples;
-  double 		  m_Sigma;
   bool 			  m_AngularStepIsConfigured;
   bool 			  m_RadialStepIsConfigured;
   
diff --git a/Code/BasicFilters/otbLogPolarResampleImageFilter.txx b/Code/BasicFilters/otbLogPolarResampleImageFilter.txx
index d5d1f4892d..2d463a87fb 100644
--- a/Code/BasicFilters/otbLogPolarResampleImageFilter.txx
+++ b/Code/BasicFilters/otbLogPolarResampleImageFilter.txx
@@ -52,7 +52,6 @@ LogPolarResampleImageFilter<TInputImage, TInterpolator>
 
   m_OriginIsAtCenter  = true;
   m_DefaultPixelValue = 0;
-  m_Sigma             = 0.5;
   
   m_Interpolator      = itk::LinearInterpolateImageFunction<InputImageType, CoordRepType>::New();
   
@@ -150,11 +149,6 @@ LogPolarResampleImageFilter<TInputImage,TInterpolator>
         
   typedef typename InterpolatorType::OutputType OutputType;
 
-  // Min/max values of the output pixel type AND these values
-  // represented as the output type of the interpolator
-  const OutputPixelType minOutputValue =  itk::NumericTraits<OutputPixelType >::NonpositiveMin();
-  const OutputPixelType maxOutputValue =  itk::NumericTraits<OutputPixelType >::max();
-
   // Walk the output region
   outIt.GoToBegin();
 
@@ -185,23 +179,8 @@ LogPolarResampleImageFilter<TInputImage,TInterpolator>
       {
       OutputPixelType pixval;
       double valueTemp = static_cast<double>(m_Interpolator->EvaluateAtContinuousIndex(inputIndex) );
-      valueTemp *= exp(m_Sigma * Rho);
-      valueTemp *= m_RadialStep; 
       OutputPixelType value = static_cast<OutputPixelType>(valueTemp);
-      
-      if( value < minOutputValue )
-        {
-        pixval = minOutputValue;
-        }
-      else if( value > maxOutputValue )
-        {
-        pixval = maxOutputValue;
-        }
-      else 
-        {
-        pixval = static_cast<OutputPixelType>( value );
-        }
-      outIt.Set( pixval );      
+      outIt.Set(value);      
       }
     else
       {
@@ -212,13 +191,8 @@ LogPolarResampleImageFilter<TInputImage,TInterpolator>
     ++outIt;
     }
 
-  return;
-  
+  return;  
 }
-
-
-
-
 /** 
  * Inform pipeline of necessary input image region
  *
diff --git a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h
index 69f3d33d79..5ccc02f6ac 100644
--- a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h
+++ b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h
@@ -122,8 +122,8 @@ public:
   const double GetAngularNumberOfSamples( void );  
 
   /** Set/Get the Sigma value for the Log-polar resampler  */
-  void SetSigma( double sigma );
-  const double GetSigma( void );  
+  itkSetMacro(Sigma,double);
+   itkGetMacro(Sigma,double);  
 
   /** Set/Get the OriginIsAtCenter value for the Log-polar resampler  */
   void SetOriginIsAtCenter( bool isAtCenter );
@@ -158,6 +158,9 @@ private:
 
   LogPolarResampleImageFilterPointer	   m_LogPolarResample;
   FourierImageFilterPointer 	           m_FourierTransform;
+
+  /** Sigma for normalization */
+  double m_Sigma;
 };
 
 } // namespace otb
diff --git a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx
index 39eca5a683..17d82efa84 100644
--- a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx
+++ b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx
@@ -20,7 +20,7 @@
 #define _otbForwardFourierMellinTransformImageFilter_txx
 
 #include "otbForwardFourierMellinTransformImageFilter.h"
-
+#include "itkImageRegionIteratorWithIndex.h"
 
 namespace otb
 {
@@ -38,8 +38,47 @@ void
 ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension >
 ::GenerateData()
 {
+       // Normalization is specific to FourierMellin convergence conditions, and
+       // thus should be implemented here instead of in the resample filter.
+
+       typedef itk::ImageRegionIteratorWithIndex<InputImageType> IteratorType;
+
 	m_LogPolarResample->SetInput( this->GetInput() );
- 	m_FourierTransform->SetInput( m_LogPolarResample->GetOutput() );
+	m_LogPolarResample->Update();
+	
+	typename InputImageType::Pointer tempImage = m_LogPolarResample->GetOutput();
+	IteratorType it(tempImage,tempImage->GetLargestPossibleRegion());
+
+        // Min/max values of the output pixel type AND these values
+        // represented as the output type of the interpolator
+        const PixelType minOutputValue =  itk::NumericTraits<PixelType >::NonpositiveMin();
+        const PixelType maxOutputValue =  itk::NumericTraits<PixelType >::max();
+
+	for(it.GoToBegin();!it.IsAtEnd();++it)
+	  {
+	    double Rho   = it.GetIndex()[1]*m_LogPolarResample->GetRadialStep();
+	    PixelType pixval;
+	    double valueTemp = static_cast<double>(it.Get());
+	    valueTemp *= exp(m_Sigma * Rho);
+	    valueTemp *=m_LogPolarResample->GetRadialStep() ; 
+	    PixelType value = static_cast<PixelType>(valueTemp);
+	    
+	    if( value < minOutputValue )
+	      {
+		pixval = minOutputValue;
+	      }
+	    else if( value > maxOutputValue )
+	      {
+		pixval = maxOutputValue;
+	      }
+	    else 
+	      {
+		pixval = static_cast<PixelType>(value);
+	      }
+	    it.Set(pixval);      
+	  }
+
+ 	m_FourierTransform->SetInput(tempImage );
  	m_FourierTransform->GraftOutput( this->GetOutput() );
 
 	m_FourierTransform->Update();
@@ -139,22 +178,6 @@ ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension >
 {
 	return static_cast<const double>(m_LogPolarResample->GetRadialNumberOfSamples() );
 }
-
-template < class TPixel,class  TInterpol,unsigned int   Dimension >
-void
-ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension >
-::SetSigma(double sigma )
-{
-	m_LogPolarResample->SetSimga(sigma);
-}
-template < class TPixel,class  TInterpol,unsigned int   Dimension >
-const double
-ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension >
-::GetSigma( )
-{
-	return m_LogPolarResample->GetSigma();
-}
-
 template < class TPixel,class  TInterpol,unsigned int   Dimension >
 void
 ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension >
diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt
index 2d2d60b3dc..66982f1b53 100755
--- a/Testing/Code/FeatureExtraction/CMakeLists.txt
+++ b/Testing/Code/FeatureExtraction/CMakeLists.txt
@@ -434,8 +434,8 @@ ADD_TEST(feTuForwardFourierMellinImageFilterTestFFT3Croix ${FEATUREEXTRACTION_TE
 	${TEMP}/feFFTTest3Croix.hdr)
 
 ADD_TEST(feTvForwardFourierMellinImageFilter ${FEATUREEXTRACTION_TESTS}  
-#  --compare-image ${TOL}  ${BASELINE}/feForwardFourierMellinImageFilter.hdr
-#                          ${TEMP}/feForwardFourierMellinImageFilter.hdr
+  --compare-image ${TOL}  ${BASELINE}/feForwardFourierMellinImageFilter.hdr
+                          ${TEMP}/feForwardFourierMellinImageFilter.hdr
         otbFourierMellinImageFilter
         ${INPUTDATA}/DeuxCercles.hdr
 	${TEMP}/feForwardFourierMellinImageFilter.hdr)
-- 
GitLab