[Insight-users] problems filtering using GaussianBlurImageFunction

Julien Jomier jjomier at cs.unc.edu
Thu, 8 Jan 2004 12:20:53 -0500


Phillip,

Thanks for the report and your example. Luis has added an example in
Insight/Examples/Filtering/GaussianBlurImageFunction.cxx based on your code.
I just found the problem and I've logged a bug in the BugTracker
(http://www.itk.org/Bug/): Bug #498 - itkGaussianBlurImageFunction is not
computing blurred values correctly.

I'll try to fix it as soon as possible,
Thanks again for the report and the clear example,

Julien

----- Original Message ----- 
From: "Phillip Cheng" <pmcheng at u.washington.edu>
To: <insight-users at itk.org>
Sent: Wednesday, January 07, 2004 9:01 PM
Subject: [Insight-users] problems filtering using GaussianBlurImageFunction


> Hello all,
>
> I'm trying to get some code working that uses itkGaussianBlurImageFunction
> to filter an image volume.  I can't just use itkDiscreteGaussianFilter
> because I need to vary the width of the kernel throughout the image, based
> on external data.
>
> I didn't get the results I expected, probably because I don't really
> understand how GaussianBlurImageFunction is supposed to work.  Appended
are
> two code samples, one using DiscreteGaussianFilter and the other using
> GaussianBlurImageFunction, with the same kernel sizes.  I would like them
to
> give the same results, but they clearly do not.  The
DiscreteGaussianFilter
> gives results that appear correct; the GaussianBlurImageFunction seems to
be
> less blurred than what I expect.  I'm not sure how best to debug what's
> going on.  Can anyone shed some light on this?
>
> Thanks,
>
> Phillip
>
>
> ==== Using DiscreteGaussianImageFilter:
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkDiscreteGaussianImageFilter.h"
>
> int main( int argc, char * argv[] )
> {
>   if( argc < 3 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << "  inputImageFile  outputImageFile" <<
> std::endl;
>     return 1;
>     }
>
>   typedef itk::Image< float,  3 >   ImageType;
>   typedef itk::ImageFileReader< ImageType >  ReaderType;
>   typedef itk::ImageFileWriter< ImageType >  WriterType;
>
>   ReaderType::Pointer reader = ReaderType::New();
>   reader->SetFileName( argv[1] );
>
>   typedef itk::DiscreteGaussianImageFilter< ImageType, ImageType >
> FilterType;
>   FilterType::Pointer filter = FilterType::New();
>   filter->SetInput( reader->GetOutput() );
>   filter->SetVariance(25.0);
>
>   WriterType::Pointer writer = WriterType::New();
>   writer->SetFileName( argv[2] );
>   writer->SetInput( filter->GetOutput() );
>   writer->Update();
>
>   return 0;
> }
>
>
> ==== Using GaussianBlurImageFunction:
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkGaussianBlurImageFunction.h"
> #include "itkImageRegionIterator.h"
>
> int main( int argc, char * argv[] )
> {
>   if( argc < 3 ) {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << "  inputImageFile  outputImageFile" <<
> std::endl;
>     return 1;
>   }
>
>   typedef itk::Image< float, 3 >   ImageType;
>   typedef itk::ImageFileReader< ImageType >  ReaderType;
>   typedef itk::ImageRegionIterator< ImageType > IteratorType;
>
>   ReaderType::Pointer reader = ReaderType::New();
>   reader->SetFileName( argv[1] );
>   reader->Update();
>
>   IteratorType it( reader->GetOutput(),
> reader->GetOutput()->GetRequestedRegion() );
>   ImageType::Pointer output = ImageType::New();
>   output->SetRegions(reader->GetOutput()->GetRequestedRegion());
>   output->SetOrigin(reader->GetOutput()->GetOrigin());
>   output->SetSpacing(reader->GetOutput()->GetSpacing());
>   output->Allocate();
>   IteratorType out(output,reader->GetOutput()->GetRequestedRegion());
>
>   typedef itk::GaussianBlurImageFunction< ImageType > GFunctionType;
>   GFunctionType::Pointer gaussianFunction = GFunctionType::New();
>   gaussianFunction->SetInputImage(reader->GetOutput());
>
>   GFunctionType::ErrorArrayType setError;
>   setError.Fill( 0.01 );
>   gaussianFunction->SetMaximumError( setError );
>   gaussianFunction->SetSigma(5.0);
>   it.GoToBegin();
>   out.GoToBegin();
>   while (!it.IsAtEnd()) {
>       out.Set(gaussianFunction->EvaluateAtIndex(it.GetIndex()));
>       ++it;
>       ++out;
>   }
>
>   typedef itk::ImageFileWriter < ImageType > WriterType;
>   WriterType::Pointer writer = WriterType::New();
>   writer->SetFileName(argv[2]);
>   writer->SetInput(output);
>   writer->Update();
>
>   return 0;
> }
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>