[ITK-users] [ITK] it.IsAtEnd() is true immediately after setting it.GoToBegin()

Matt McCormick matt.mccormick at kitware.com
Tue Apr 15 23:34:36 EDT 2014


Hi David,

Update() has to be called on fourierImage in order for its contents to
be available.

Hope this helps,
Matt

PS. Tip: ForwardFFTImageFilter can be used instead of
VnlForwardFFTImageFilter, and ForwardFFTImageFilter will automatically
use VnlForwardFFTImageFilter if FFTW is not available.

On Tue, Apr 15, 2014 at 10:28 AM, DVigneault <davis.vigneault at gmail.com> wrote:
> All--
>
> In connection with my previous  phase unwrapping question
> <http://itk-users.7.n7.nabble.com/Is-there-a-phase-unwrapping-filter-in-ITK-td33731.html>
> , I'm trying to write a filter with the following structure:
>
> --Take the vnl forward Fourier transform
> --Alter the pixel values using itkImageRegionIteratorWithIndex
> --Take the vnl inverse Fourier transform
> --Multiply by a constant
>
> However, in the second step, it.IsAtEnd() is true immediately after setting
> it.GoToBegin(), suggesting that I've done something wrong in assigning the
> output of the vnl forward FFT to the pointer that I'm trying to iterate
> over.
>
> Does anyone see where I've gone wrong?
>
> Best,
>
> --Davis
>
> *** Code ***
>
> #ifndef DV_FORWARDLAPLACIANIMAGEFILTER_H
> #define DV_FORWARDLAPLACIANIMAGEFILTER_H
>
> #include "itkImageToImageFilter.h"
> #include "itkVnlForwardFFTImageFilter.h"
> #include "itkVnlInverseFFTImageFilter.h"
> #include "itkMultiplyImageFilter.h"
> #include "itkImageRegionIteratorWithIndex.h"
> #include "vnl/vnl_math.h"
>
> namespace itk {
>
> template < typename TWorkImage >
> class ITK_EXPORT ForwardLaplacianImageFilter :
> public ImageToImageFilter< TWorkImage, TWorkImage >
> {
> public:
>
> //  Standard declarations
> //  Used for object creation with the object factory:
>
>   typedef ForwardLaplacianImageFilter                  Self;
>   typedef ImageToImageFilter< TWorkImage, TWorkImage > Superclass;
>   typedef SmartPointer<Self>                           Pointer;
>   typedef SmartPointer<const Self>                     ConstPointer;
>
>   // Typedefs
>         typedef TWorkImage                        WorkImageType;
>         typedef std::complex< double >            ComplexPixelType;
>         typedef itk::Image< ComplexPixelType, 2 > ComplexImageType;
>
>   /** Method for creation through object factory */
>   itkNewMacro(Self);
>
>   /** Run-time type information */
>   itkTypeMacro(ForwardLaplacianImageFilter, ImageToImageFilter);
>
>   /** Display */
>   void PrintSelf( std::ostream& os, Indent indent ) const;
>
> protected:
>
>   ForwardLaplacianImageFilter();
>
> //  Declare the component filter types:
>
> protected:
>
>         typedef VnlForwardFFTImageFilter< WorkImageType, ComplexImageType >
> ForwardFFTType;
>         typedef VnlInverseFFTImageFilter< ComplexImageType, WorkImageType >
> InverseFFTType;
>         typedef MultiplyImageFilter< WorkImageType, WorkImageType, WorkImageType >
> MultiplyType;
>         typedef ImageRegionIteratorWithIndex< ComplexImageType > ItType;
>
>     void GenerateData();
>
> private:
>
>   ForwardLaplacianImageFilter(Self&);   // intentionally not implemented
>   void operator=(const Self&);          // intentionally not implemented
>
> //  Component filters are declared as data members, all using the smart
> //  pointer types.
>
>         typename ForwardFFTType::Pointer m_FFT_Forward;
>         typename InverseFFTType::Pointer m_FFT_Inverse;
>         typename MultiplyType::Pointer   m_Multiply;
>
> };
>
> }
>
> //  The constructor sets up the pipeline, which involves creating the
> //  stages, connecting them together, and setting default parameters.
>
> namespace itk
> {
>
> template < typename WorkImageType >
> ForwardLaplacianImageFilter< WorkImageType >::ForwardLaplacianImageFilter()
> {
>
>         m_FFT_Forward = ForwardFFTType::New();
>         m_FFT_Inverse = InverseFFTType::New();
>         m_Multiply =    MultiplyType::New();
>
> }
>
> template < typename WorkImageType >
> void
> ForwardLaplacianImageFilter< WorkImageType >::GenerateData()
> {
>
>         // Description:
>         //              Take the FORWARD Fourier transform
>         //              Modify the values
>         //              Take the INVERSE Fourier transform
>         //              Multiply by a constant
>
>         // Set the input to the filter to the forward FFT
>         m_FFT_Forward->SetInput( this->GetInput() );
>
>         // Assign the output of this filter to a pointer
>         ComplexImageType::Pointer fourierImage = m_FFT_Forward->GetOutput();
>
>         // Iterate over this image to modify the values based on the indices
>         ItType fourierIt(fourierImage, fourierImage->GetLargestPossibleRegion() );
>     fourierIt.GoToBegin();
>     std::complex< double > a( 4, 0 );
>
>     // IsAtEnd() seems to be true, even though we're at the beginning
>     // Does this mean that the FFT output wasn't really assigned?
>     std::cout << fourierIt.IsAtEnd() << std::endl; // Prints "1"
>
>     // The while loop is not executed, as fourierIt.IsAtEnd() is true from
> the start
>     while ( !fourierIt.IsAtEnd() ) {
>         fourierIt.Set( a );
>         std::cout << fourierIt.Get() << std::endl; // Doesn't print
>         ++fourierIt;
>     }
>
>         // Assign that pointer to the inverse FFT filter
>         m_FFT_Inverse->SetInput( fourierImage );
>
>         // Multiply by a constant
>         m_Multiply->SetInput1( m_FFT_Inverse->GetOutput() );
>         m_Multiply->SetConstant( 2*pow(vnl_math::pi, 2)/pow(160, 2) );
>
>         // Assign the output of the multiplication filter to the output of this
> filter
>         m_Multiply->GraftOutput( this->GetOutput() );
>         m_Multiply->Update();
>         this->GraftOutput( m_Multiply->GetOutput() );
>
> }
>
> //  PrintSelf method prints parameters
>
> template < typename WorkImageType >
> void
> ForwardLaplacianImageFilter< WorkImageType >::PrintSelf( std::ostream& os,
> Indent indent ) const
> {
>   Superclass::PrintSelf(os,indent);
>
>   os
>     << indent << "No parameters."
>     << std::endl;
> }
>
> } /* end namespace itk */
>
> #endif
>
> *** End Code ***
>
>
>
> --
> View this message in context: http://itk-users.7.n7.nabble.com/it-IsAtEnd-is-true-immediately-after-setting-it-GoToBegin-tp33751.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/community


More information about the Insight-users mailing list