[Insight-users] Problem with resampling

Chris Farmer cfarmer at scitegic.com
Tue Oct 18 11:27:55 EDT 2005



Hi.  I'm having trouble using the VectorResampleImageFilter.  I saw a
discussion in the archives where Luis recommended its use for resampling
an RGB image.  My RGB image was a png read in with the ImageFileReader.
In my little example, I just want to resize an image from 400 x 400 to
200 x 200 pixels.  At the moment, I don't really care what the
interpolation method is.  Here's what I'm trying:


//typedef itk::RGBPixel<unsigned char>	RGB8PixelType;
//typedef itk::Image< RGB8PixelType, 2 >   RGB8ImageType;
RGB8ImageType::RegionType region =
m_rgbimage->GetLargestPossibleRegion();
RGB8ImageType::SizeType size = region.GetSize();
	
double yscale = (double)width / size[0];
double xscale = (double)height / size[1];
	
typedef itk::ScaleTransform<double, 2> Transform;
Transform::Pointer scaler = Transform::New();
Transform::OutputVectorType scalevector;
scalevector[0] = yscale;
scalevector[1] = xscale;
scaler->SetScale(scalevector);

typedef itk::VectorResampleImageFilter<RGB8ImageType, RGB8ImageType>
ResampleFilterType;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
resampler->SetTransform(scaler);
resampler->SetInput(m_rgbimage);
RGB8ImageType::Pointer image2 = resampler->GetOutput();
resampler->Update();
image2->Update();


In the debugger, the output from the filter looks bogus. (The input
m_rgbimage is valid.)  When I try to write the output to a file using
ImageFileWriter, I get an exception with this message:

itk::ERROR: PNGImageIO(06470AA8): PNG Writer can only write
2-dimensional images. You are requesting to write an image of dimension
= 0 with filename c:\blah.png

Clearly I'm doing something wrong, but I have no idea what it is.  How
can I correctly use this filter with a ScaleTransform?


Thanks,
Chris



More information about the Insight-users mailing list