From 0d190f4fa05574849eb1886c4b716f84d68be0fa Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@c-s.fr> Date: Thu, 15 Feb 2007 16:21:03 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20GenerateOutputInformation()=20po?= =?UTF-8?q?ur=20la=20compatibilit=C3=A9=20avec=20les=20filtres=20multi-thr?= =?UTF-8?q?ead=C3=A9s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ForwardFourierMellinTransformImageFilter.h | 48 ++++++++--- ...rwardFourierMellinTransformImageFilter.txx | 86 +++++++++++-------- 2 files changed, 88 insertions(+), 46 deletions(-) diff --git a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h index 5f18d93f8d..f7c1520126 100644 --- a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h +++ b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.h @@ -23,6 +23,9 @@ #include "itkLinearInterpolateImageFunction.h" #include "itkImageToImageFilter.h" #include "itkVnlFFTRealToComplexConjugateImageFilter.h" +#include "otbLogPolarTransform.h" +#include "itkResampleImageFilter.h" +#include "itkImageRegionIteratorWithIndex.h" namespace otb { @@ -50,22 +53,24 @@ template < class TPixel, class ITK_EXPORT ForwardFourierMellinTransformImageFilter : public itk::ImageToImageFilter<Image< TPixel , Dimension >, - Image< std::complex<TPixel> , Dimension > > + itk::Image< std::complex<TPixel> , Dimension > > { -public: + public: //typedef TPixel PixelType; typedef otb::Image< TPixel , Dimension > InputImageType; - typedef otb::Image< std::complex< TPixel > , Dimension > OutputImageType; - + /* typedef otb::Image< std::complex< TPixel > , Dimension > OutputImageType; */ + + typedef typename itk::VnlFFTRealToComplexConjugateImageFilter<TPixel,Dimension> FourierImageFilterType; + typedef typename FourierImageFilterType::OutputImageType OutputImageType; + + /** Standard class typedefs. */ typedef ForwardFourierMellinTransformImageFilter Self; typedef itk::ImageToImageFilter< InputImageType, OutputImageType> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; - - /** Run-time type information (and related methods). */ itkTypeMacro( ForwardFourierMellinTransformImageFilter, itk::ImageToImageFilter); @@ -77,6 +82,8 @@ public: typedef typename InputImageType::IndexType IndexType; typedef typename InputImageType::Pointer ImagePointer; typedef typename InputImageType::ConstPointer ImageConstPointer; + + /** InputImageType typedef support. */ typedef typename OutputImageType::PixelType OutputPixelType; @@ -96,7 +103,14 @@ public: typedef typename InterpolatorType::CoordRepType CoordRepType; typedef typename InterpolatorType::PointType PointType; - typedef typename itk::VnlFFTRealToComplexConjugateImageFilter<PixelType,Dimension> FourierImageFilterType; + + typedef otb::LogPolarTransform<CoordRepType> LogPolarTransformType; + typedef typename LogPolarTransformType::Pointer LogPolarTransformPointerType; + typedef itk::ResampleImageFilter<InputImageType,InputImageType,CoordRepType> ResampleFilterType; + typedef typename ResampleFilterType::Pointer ResampleFilterPointerType; + typedef itk::ImageRegionIteratorWithIndex<InputImageType> IteratorType; + + typedef typename FourierImageFilterType::Pointer FourierImageFilterPointer; typedef typename FourierImageFilterType::ConstPointer FourierImageFilterConstPointer; @@ -112,6 +126,8 @@ public: itkSetMacro(DefaultPixelValue, PixelType); itkGetMacro(DefaultPixelValue, PixelType); + virtual void GenerateOutputInformation(void); + /** Set/Get the Interpolator pointer for the Log-polar resampler */ itkSetObjectMacro(Interpolator,InterpolatorType); itkGetObjectMacro(Interpolator,InterpolatorType); @@ -124,13 +140,12 @@ protected: /** Main Computation Method */ void GenerateData(); + private: ForwardFourierMellinTransformImageFilter( const Self& ); //purposely not implemented void operator=( const Self& ); //purposely not implemented - FourierImageFilterPointer m_FourierTransform; - /** Sigma for normalization */ double m_Sigma; @@ -139,9 +154,22 @@ private: /** Output pixel default value */ PixelType m_DefaultPixelValue; - + /** Interpolator */ InterpolatorPointerType m_Interpolator; + + /** Transform */ + LogPolarTransformPointerType m_Transform; + + /** Resampler */ + ResampleFilterPointerType m_ResampleFilter; + + /** FFT Filter */ + FourierImageFilterPointer m_FFTFilter; + + /** Iterator */ + IteratorType m_Iterator; + }; } // namespace otb diff --git a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx index 4111a754ab..1b223c86f3 100644 --- a/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx +++ b/Code/FeatureExtraction/otbForwardFourierMellinTransformImageFilter.txx @@ -19,9 +19,7 @@ PURPOSE. See the above copyright notices for more information. #define _otbForwardFourierMellinTransformImageFilter_txx #include "otbForwardFourierMellinTransformImageFilter.h" -#include "itkImageRegionIteratorWithIndex.h" -#include "otbLogPolarTransform.h" -#include "itkResampleImageFilter.h" +#include "itkImageDuplicator.h" namespace otb { @@ -29,43 +27,60 @@ namespace otb ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension > ::ForwardFourierMellinTransformImageFilter() { - m_FourierTransform = FourierImageFilterType::New(); - m_Interpolator = InterpolatorType::New(); + 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); } + + template < class TPixel,class TInterpol,unsigned int Dimension > + void + ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension > + ::GenerateOutputInformation(void) + { + Superclass::GenerateOutputInformation(); + + OutputImagePointer outputPtr = this->GetOutput(); + + if(!outputPtr) + { + return; + } + typename OutputImageType::RegionType largestPossibleRegion; + typename OutputImageType::IndexType index; + index.Fill(0); + largestPossibleRegion.SetIndex(index); + largestPossibleRegion.SetSize(m_OutputSize); + outputPtr->SetLargestPossibleRegion(largestPossibleRegion); + } + template < class TPixel,class TInterpol,unsigned int Dimension > void ForwardFourierMellinTransformImageFilter<TPixel, TInterpol, Dimension > ::GenerateData() - { - // some typedefs - typedef otb::LogPolarTransform<double> LogPolarTransformType; - typedef itk::ResampleImageFilter<InputImageType,InputImageType,double> ResampleFilterType; - typedef itk::ImageRegionIteratorWithIndex<InputImageType> IteratorType; - - typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); - typename LogPolarTransformType::Pointer transform = LogPolarTransformType::New(); - + { typename LogPolarTransformType::ParametersType params(4); // Center the transform params[0]=0.5*static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0]); params[1]=0.5*static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[1]); params[2]=360./m_OutputSize[0]; - params[3]=log(sqrt(pow(static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0]),2) - +pow(static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[1]),2.))/2)/m_OutputSize[1]; - transform->SetParameters(params); + params[3]=vcl_log(vcl_sqrt(vcl_pow(static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0]),2) + +vcl_pow(static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[1]),2.))/2)/m_OutputSize[1]; + m_Transform->SetParameters(params); // log polar resampling - resampler->SetInput(this->GetInput()); - resampler->SetTransform(transform); - resampler->SetInterpolator(m_Interpolator); - resampler->SetDefaultPixelValue(m_DefaultPixelValue); - resampler->SetSize(m_OutputSize); - resampler->Update(); + m_ResampleFilter->SetInput(this->GetInput()); + m_ResampleFilter->SetDefaultPixelValue(m_DefaultPixelValue); + m_ResampleFilter->SetSize(m_OutputSize); + m_ResampleFilter->Update(); - typename InputImageType::Pointer tempImage = resampler->GetOutput(); - IteratorType it(tempImage,tempImage->GetLargestPossibleRegion()); + typename InputImageType::Pointer tempImage = m_ResampleFilter->GetOutput(); + m_Iterator = IteratorType(tempImage,tempImage->GetRequestedRegion()); // Min/max values of the output pixel type AND these values // represented as the output type of the interpolator @@ -74,12 +89,12 @@ namespace otb // Normalization is specific to FourierMellin convergence conditions, and // thus should be implemented here instead of in the resample filter. - for(it.GoToBegin();!it.IsAtEnd();++it) + for(m_Iterator.GoToBegin();!m_Iterator.IsAtEnd();++m_Iterator) { - double Rho = it.GetIndex()[1]*params[3]; + double Rho = m_Iterator.GetIndex()[1]*params[3]; PixelType pixval; - double valueTemp = static_cast<double>(it.Get()); - valueTemp *= exp(m_Sigma * Rho); + double valueTemp = static_cast<double>(m_Iterator.Get()); + valueTemp *= vcl_exp(m_Sigma * Rho); valueTemp *=params[3]; PixelType value = static_cast<PixelType>(valueTemp); @@ -95,14 +110,13 @@ namespace otb { pixval = static_cast<PixelType>(value); } - it.Set(pixval); + m_Iterator.Set(pixval); } - // Fourrier transform of the output - m_FourierTransform->SetInput(tempImage ); - m_FourierTransform->GraftOutput( this->GetOutput() ); - - m_FourierTransform->Update(); - this->GraftOutput( m_FourierTransform->GetOutput() ); + m_FFTFilter->SetInput(tempImage ); + + m_FFTFilter->GraftOutput( this->GetOutput() ); + m_FFTFilter->Update(); + this->GraftOutput( m_FFTFilter->GetOutput() ); } /** * Standard "PrintSelf" method -- GitLab