[Insight-users] the itkrecursivegaussianimagefilter

Luis Ibanez luis.ibanez@kitware.com
Tue, 19 Nov 2002 18:51:40 -0500


Hi Ting,

The itkRecursiveGaussianImageFilter may not be
the filter you want to use for smoothing an image.

Please take a look at the DiscreteGaussianImageFilter:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1DiscreteGaussianImageFilter.html

This filter compute the blurring by an actual
convolution which is ok if the kernel size of your
gaussian is not too large.

If you end up needing very large sigmas, It may be better
to connect two itkRecursiveGaussianImageFilter filters
in a pipeline in order to compute blurring along X with
the first and blurring along Y with the second.
The itkRecursiveGaussianImage filter uses a IIR filter
to compute an approximation of the convolution with a
gaussian. The approximation is quite good. In particular
it is better than truncating the gaussian kernel.

-----------

Just FYI:

The itkRecursiveGaussianImageFilter is intended
to apply the filtering in a single dimension.

It requires the use to first invoke the method:

   - SetDirection()

to select such direction. For example,
SetDirection( 0 ) will apply the filtering
along X, while SetDirection(1) will do it
along Y.

Also, this class can compute the equivalent of
convolving with a gaussian, the first derivative
of the gaussian or the second derivative of the
gaussian. The desired behavior is selected with
the method SetOrder(). It expect an enum that
is defined in the filter type:


   - SetOrder( FilterType::ZeroOrder );


Please let us know if you encounter any problems,


Thanks


Luis


===============================================

Ting Chen wrote:
> I tried the following code which i think should smooth a 2D image. however,
> I got an empty output (all the pixels are assigned to 0) can anyone go
> through the code finding the mistake here?
> 
> i am suing the latest itkRecursiveGaussianImageFilter
> 
>   // Define the dimension of the images
>   const unsigned int myDimension = 2;
> 
>   // Declare the types of the images
>   typedef itk::Image<double, myDimension>           myImageType;
> 
>   myImageType::Pointer inputImage  = myImageType::New();
> 
>   mySizeType size={{WIDTH,HEIGHT}};
>   myIndexType start;
>   start.Fill(0);
> 
>   myRegionType region;
>   region.SetIndex( start );
>   region.SetSize( size );
> 
>   // Initialize Image A
>   inputImage->SetLargestPossibleRegion( region );
>   inputImage->SetBufferedRegion( region );
>   inputImage->SetRequestedRegion( region );
>   inputImage->Allocate();
> 
>     fread(ImageBuffer, 1, WIDTH*HEIGHT, inputfile);
>     for (int j=0; j<WIDTH*HEIGHT; j++) {
>       it.Set((double)ImageBuffer[j]);
>       ++it;
>     }
> 
> 
>   typedef itk::RecursiveGaussianImageFilter<
>                                             myImageType,
>                                             myImageType
>                                             >  myGaussianFilterType;
> 
>   myGaussianFilterType::Pointer rgfilter = myGaussianFilterType::New();
>   rgfilter->SetInput( inputImage );
>   rgfilter->SetSigma( 2.0 );
>   rgfilter->Update();
> 
>   FILE *outputfile = fopen(OUTPUTFILE, "wb");
> 
>   itk::ImageRegionIteratorWithIndex <myImageType>
> outit(rgfilter->GetOutput(), region);
>   outit.GoToBegin();
>   double x;
>   int i=0;
>   while ( !outit.IsAtEnd() ) {
>     x = outit.Value();
>     ImageBuffer[i] = (unsigned char)x;
>     ++outit;
>     i++;
>   }
>   fwrite(ImageBuffer, 1, WIDTH*HEIGHT, outputfile);
> 
> 
> 
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
> 
>