[Insight-users] Image Adaptor question

Luis Ibanez luis.ibanez at kitware.com
Sat Apr 2 10:48:20 EST 2005


Hi Rhazes,

There are two reason why we passed the output of the adaptor
to a RescaleImageFilter in the Examples.


These two reasons are:

1) Writers do not support adaptors.
    Most writers expect to have direct access to the image buffer,
    which in the case of adaptors... doesn't exist, since ImageAdaptors
    compute the pixel values on the fly.

2) Make sure that the output images are visible with naive
    viewers that do not perform intensity normalization.


In practice, reason (1) was the strongest justification.
The Rescale filter is making sure that after the adaptor a
real image buffer is created.

This means that when you use ImageAdaptors, you must make sure
that the filter receiving the Adaptor is based on the use of the
"*WithIndex" iterators.

If you have any doubt about it, just post to the list the names
of the filters that you are intending to use after the adaptor
and we will help you find whether it support adaptors or not.


    Regards,


       Luis



----------------------------
Rhazes Spell wrote:

> 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.
> 
> Cheers,
> RS
> -=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=
> 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> 
> GreenChannelImageAdaptor;
> 
> typedef itk::ImageFileReader<RGBImage2D> RGBImageFileReader2D;
> //typedef itk::ImageFileWriter<ScalarImage2D> GreenChannelFileWriter2D;
> ** typedef itk::ImageFileWriter<GreenChannelImageAdaptor> 
> GreenChannelFileWriter2D;
> 
> int main(int argc, char * argv[]) {
> 
>     RGBImageFileReader2D::Pointer reader = RGBImageFileReader2D::New();
>     reader->SetFileName(argv[1]);
>     try {
>         reader->Update();
>     }catch( itk::ExceptionObject &err ) {
>            cout << " Exception Objet caught ! " << endl;
>            cout << err << endl;
>            }   
> 
>     GreenChannelImageAdaptor::Pointer greenAdaptor = 
> GreenChannelImageAdaptor::New();
>     greenAdaptor->SetImage(reader->GetOutput());
> 
>     typedef itk::RescaleIntensityImageFilter<GreenChannelImageAdaptor, 
> ScalarImage2D> RescalarType;
>     RescalarType::Pointer rescalar = RescalarType::New();
>     rescalar->SetOutputMinimum( 0 );
>     rescalar->SetOutputMaximum( 255 );
>     rescalar->SetInput( greenAdaptor );
> 
> 
>     GreenChannelFileWriter2D::Pointer writer = 
> GreenChannelFileWriter2D::New();
>     writer->SetFileName(argv[2]);
> //    writer->SetInput(rescalar->GetOutput());
> **    writer->SetInput(greenAdaptor);
>     writer->Update();
> 
>     return 0;
> }
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 





More information about the Insight-users mailing list