[Insight-users] the itkrecursivegaussianimagefilter
Ting Chen
chenting@graphics.cis.upenn.edu
Tue, 19 Nov 2002 18:31:55 -0500
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);