[Insight-users] Image Adaptor question

Rhazes Spell rus1 at duke.edu
Thu Mar 31 15:56:32 EST 2005

I have been able to successfully extract the channels from an RGB image 
using the Image Adaptor examples in the user guide.  However, I have a 
question concerning the use of the RescaleIntensityImageFilter.  Since 
ImageAdaptors conform to the itk::Image API, why is it necessary to 
pass the adaptor through the RescaleFilter?

I am assuming (perhaps erroneously) that if the pixel type of the RGB 
components of the input image is the same as the pixel type of the 
single channel output image than it is not necessary to Rescale the 
pixel values.  When I tried using the Image Adaptor without using the 
RescaleFilter, however, I did not get the correct results.    I have 
included my code below.  The two commented line produce the correct 
results when compiled, and the two lines with asterisks produce the 
incorrect result.  The incorrect result is a gray scale version of the 
original image zoomed in and cropped to the same dimensions???

If anyone could provide some insight I would be very appreciative.

typedef unsigned char cPixelType;
typedef itk::GreenPixelAccessor<cPixelType> GreenChannelPixelAccessor;
typedef GreenChannelPixelAccessor::InternalType RGBPixel;

typedef itk::Image<RGBPixel,2> RGBImage2D;
typedef itk::Image<cPixelType,2> ScalarImage2D;

typedef itk::ImageAdaptor<RGBImage2D,GreenChannelPixelAccessor> 

typedef itk::ImageFileReader<RGBImage2D> RGBImageFileReader2D;
//typedef itk::ImageFileWriter<ScalarImage2D> GreenChannelFileWriter2D;
** typedef itk::ImageFileWriter<GreenChannelImageAdaptor> 

int main(int argc, char * argv[]) {

	RGBImageFileReader2D::Pointer reader = RGBImageFileReader2D::New();
	try {
	}catch( itk::ExceptionObject &err ) {
	       cout << " Exception Objet caught ! " << endl;
	       cout << err << endl;

	GreenChannelImageAdaptor::Pointer greenAdaptor = 

	typedef itk::RescaleIntensityImageFilter<GreenChannelImageAdaptor, 
ScalarImage2D> RescalarType;
	RescalarType::Pointer rescalar = RescalarType::New();
	rescalar->SetOutputMinimum( 0 );
	rescalar->SetOutputMaximum( 255 );
	rescalar->SetInput( greenAdaptor );

	GreenChannelFileWriter2D::Pointer writer = 
//	writer->SetInput(rescalar->GetOutput());
**	writer->SetInput(greenAdaptor);

	return 0;

More information about the Insight-users mailing list