[Insight-users] problems filtering using GaussianBlurImageFunction
Phillip Cheng
pmcheng at u.washington.edu
Wed, 7 Jan 2004 18:01:14 -0800
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;
}