[Insight-users] ImageAdaptor and Regions

Nick Arini nick.arini at zinir.com
Fri Aug 6 06:50:29 EDT 2004


Dear Insight users,

I am trying to use an image adapter to get and rescale the individual 
channels of an RGB image in a similar way to
Examples/DataRepresentation/Image/ImageAdaptor2.cxx.

I then want to use an image iterator on the resulting images to access 
the pixel values of the individual channels. I have encountered a 
problem with defining a region (I want the whole image here) for input 
to the iterator. This works just fine until I added the ImageAdaptor 
stuff. I caught the exception and it tells me I am requesting a region 
outside the largest region but as I want the whole image and it stays 
the same size throughout I dont know why I am getting this exception. 
The message and the code snippet are below. Can anyone enlighten me as 
to what I have done wrong?

Thanks and best regards,

Nick

<begin exception message>

  itk::ExceptionObject (0xbfe3f9e0)
  Location: "ImageAdaptor::PropagateRequestedRegion()"
  File: /home/nicha/ITK_source/Insight/Code/Common/itkDataObject.cxx
  Line: 397
  Description: Requested region is (at least partially) outside the 
largest possible region.

<end exception message>



<begin code>

    typedef  float                                                  
ChannelPixelType;
    typedef  itk::RGBPixel< ChannelPixelType >   RGBPixelType;


    // We will need to use an adapter to make the RGB image look like a 
scalar image for the rescaling
    typedef itk::RedPixelAccessor< ChannelPixelType >::InternalType 
InputPixelType;
   
    typedef itk::Image< InputPixelType,  2 >  ImageType;
    typedef itk::ImageAdaptor< ImageType, itk::RedPixelAccessor< 
ChannelPixelType > > ImageAdaptorType;
 
    ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();


    typedef itk::ImageFileReader< ImageType >  ReaderType;
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName( filename );


    adaptor->SetImage( reader->GetOutput() );


    typedef itk::Image< ChannelPixelType > OutputImageType; // the red 
channel image type

    // Do some image rescaling here
    typedef itk::RescaleIntensityImageFilter< ImageAdaptorType, 
OutputImageType >  RescalerType;
    RescalerType::Pointer rescaler = RescalerType::New();
    rescaler->SetInput( adaptor );
    
    rescaler->SetOutputMinimum( 0 );
    rescaler->SetOutputMaximum( 255 );

    OutputImageType::Pointer image = rescaler->GetOutput();
  
    try
      {
        rescaler->Update();
      }
    catch( itk::ExceptionObject exp )
      {
        std::cout << exp << std::endl;
      }
   
    // now get the region associated with the image
    OutputImageType::RegionType region = image->GetLargestPossibleRegion();
 

    // And the image dimensions
   Output ImageType::RegionType::SizeValueType width = region.GetSize(0);
   OutputImageType::RegionType::SizeValueType height = region.GetSize(1);

    // define and construct a simple image iterator from an itk::Image    
    typedef itk::ImageRegionConstIterator< OutputImageType > 
ConstIteratorType;
    ConstIteratorType constIterator( image, region );

    // Use the iterator in a loop
    for( constIterator.GoToBegin(); !constIterator.IsAtEnd(); 
++constIterator )
      {
         float pix  =  constIterator.Get();
      }


<end code>



More information about the Insight-users mailing list