[Insight-users] ImageAdaptor and Regions
Nick Arini
nick.arini at zinir.com
Sun Aug 8 11:17:31 EDT 2004
Luis,
I ran the experiments you suggested with the following results:
Thanks,
Nick.
Luis Ibanez wrote:
>
> Hi Nick,
>
> Please do the two following experiments:
>
> 1) Instead of calling Update() in the resampler filter
> call UpdateLargestPossibleRegion().
RESULT: This caused exactly the same behaviour as previously (i.e.
exception still thrown).
>
> 2) Before calling Update() in the resampler filter, call
> Update() directly on the reader.
>
RESULT: This fixed the problem and led to the program giving the
expected and desired results (i.e. image loaded and rescaled correctly).
>
> Let us know what happens on each cases, that
> will help us localize the eventual problem.
>
>
> Thanks
>
>
> Luis
>
>
> ---------------------
> Nick Arini wrote:
>
>> 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>
>>
>> _______________________________________________
>> 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