[Insight-users] RegionOfInterestImageFilter Question
alex Dowson
alexdowson at hotmail.com
Sat May 26 07:57:31 EDT 2012
Dear David
Please see the attached code with create image function and some cleanup.
Alex
-----Original Message-----
From: David Doria
Sent: Saturday, May 26, 2012 4:54 PM
To: alex Dowson
Subject: Re: [Insight-users] RegionOfInterestImageFilter Question
Please shorten this significantly. Programmatically generate an input
image rather than reading it from a file. Remove all of the filters
not involved in the error. The idea is that we can copy/paste/compile
and see the actual error.
David
On Sat, May 26, 2012 at 7:19 AM, alex Dowson <alexdowson at hotmail.com> wrote:
> Dear David
>
> Here is my code and input image is 512x512 and gets error
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageSeriesWriter.h"
> #include "itkNumericSeriesFileNames.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkChangeInformationImageFilter.h"
> #include "itkOrientImageFilter.h"
> #include "itkMirrorPadImageFilter.h"
> #include "itkRegionOfInterestImageFilter.h"
> #include "itkConstantPadImageFilter.h"
> #include "itkChangeInformationImageFilter.h"
> #include "itkImageRegionConstIterator.h"
> #include "itkImageRegionIterator.h"
> #include "itkMultiplyByConstantImageFilter.h"
>
>
> int main( int argc, char *argv[] )
> {
>
>
> // Setup types
> typedef itk::Image<double, 2> ImageType;
> typedef itk::Image<unsigned char, 2> charType;
>
> typedef itk::ImageFileReader<ImageType> ReaderType;
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileName( "lena.jpg" );
> reader->Update();
>
>
> typedef itk::MirrorPadImageFilter< ImageType, ImageType > MirrorPadType;
> MirrorPadType::Pointer mirrorPadFilter = MirrorPadType::New();
> mirrorPadFilter->SetInput(reader->GetOutput());
>
> ImageType::SizeType upperfactors;
> upperfactors[0] = 20;
> upperfactors[1] = 30;
>
> ImageType::SizeType lowerfactors;
> lowerfactors[0] = 50;
> lowerfactors[1] = 40;
>
>
> mirrorPadFilter->SetPadLowerBound(lowerfactors);
> mirrorPadFilter->SetPadUpperBound(upperfactors);
> mirrorPadFilter->Update();
>
>
> ImageType::IndexType indexToDebug =
> mirrorPadFilter->GetOutput()->GetLargestPossibleRegion().GetIndex();
> ImageType::SizeType sizeToDebug =
> mirrorPadFilter->GetOutput()->GetLargestPossibleRegion().GetSize();
>
> std::cout << indexToDebug ;
> std::cout << sizeToDebug ;
>
>
> typedef itk::RegionOfInterestImageFilter< ImageType,ImageType>
> RoiCropType;
> RoiCropType::Pointer roiCropFilter = RoiCropType::New();
> roiCropFilter->SetInput(mirrorPadFilter->GetOutput());
>
>
> ImageType::IndexType index;
> index[0] = 15;
> index[1] = 0;
>
> ImageType::SizeType size;
> size[0] = 553;
> size[1] = 582;
>
> ImageType::RegionType roi;
> roi.SetIndex(index);
> roi.SetSize(size);
>
> roiCropFilter->SetRegionOfInterest(roi);
>
> try
> {
> roiCropFilter->Update();
> }
> catch (itk::ExceptionObject &ex)
> {
> std::cout << ex;
> return EXIT_FAILURE;
> }
>
>
> typedef itk::RescaleIntensityImageFilter<ImageType,charType>
> RescaleType;
> RescaleType::Pointer rescale = RescaleType::New();
> rescale->SetInput(roiCropFilter->GetOutput());
> rescale->SetOutputMinimum(0);
> rescale->SetOutputMaximum(255);
>
>
> typedef itk::ImageFileWriter<charType> ImageWriterType;
> ImageWriterType::Pointer writer = ImageWriterType::New();
> writer->SetFileName("out.jpg");
> writer->SetInput(rescale->GetOutput());
>
>
> try
> {
> writer->Update();
> }
> catch (itk::ExceptionObject &ex)
> {
> std::cout << ex;
> return EXIT_FAILURE;
> }
>
>
>
> return EXIT_SUCCESS;
> }
>
>
>
>
>
>
> -----Original Message----- From: David Doria
> Sent: Saturday, May 26, 2012 4:22 PM
> To: alex Dowson
> Cc: itk
> Subject: Re: [Insight-users] RegionOfInterestImageFilter Question
>
>
> On Sat, May 26, 2012 at 5:47 AM, alex Dowson <alexdowson at hotmail.com>
> wrote:
>>
>> Hi
>>
>> I am using RegionOfInterestImageFilter file for cropping some region but
>> it
>> gives me this error
>>
>> Description: Requested region is (at least partially) outside the largest
>> possible region.
>>
>>
>> I donot know what is problem here is my index and size for input and
>> output.
>>
>> Input LargestPossibleRegion:
>> Index : [ –50,-40] Size : [582,582]
>>
>> ROI Size :
>> Index : [15,0] Size: [ 553,582]
>>
>>
>> Can anyone tell me what is doing I am wrong ? I am in already range for
>> Region interest.
>>
>>
>> Alex
>
>
> That looks reasonable... but I've actually never used negative
> indexes. Could you throw together a quick demo that sets up those
> regions and demonstrates the error?
>
> David
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: HelloWorld.cxx
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120526/b3a589bf/attachment.txt>
More information about the Insight-users
mailing list