[Insight-users] RegionOfInterestImageFilter Question

alex Dowson alexdowson at hotmail.com
Sat May 26 08:35:27 EDT 2012


Thanx David for clearing the confusion.



Alex


-----Original Message----- 
From: David Doria
Sent: Saturday, May 26, 2012 6:02 PM
To: alex Dowson
Cc: itk
Subject: Re: [Insight-users] RegionOfInterestImageFilter Question

On Sat, May 26, 2012 at 7:57 AM, alex Dowson <alexdowson at hotmail.com> wrote:
>
> Dear David
>
> Please see the attached code with create image function and some cleanup.
>
> Alex

Here is the minimal example you should have been going for :)

#include "itkImage.h"
#include "itkRegionOfInterestImageFilter.h"

// Setup types
typedef itk::Image<double, 2>                   ImageType;

void CreateImage(ImageType::Pointer image)
{
  // Create a black image with a white square
  ImageType::IndexType start = {{-50, -40}};

  ImageType::SizeType size;
  size.Fill(582);

  ImageType::RegionType region(start,size);
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(0);
}

int main( int argc, char *argv[] )
{
  ImageType::Pointer image = ImageType::New();
  CreateImage(image);

  typedef itk::RegionOfInterestImageFilter< ImageType,ImageType> 
RoiCropType;
  RoiCropType::Pointer roiCropFilter = RoiCropType::New();
  roiCropFilter->SetInput(image);

  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);
  roiCropFilter->Update();

  return EXIT_SUCCESS;
}

Now that I look again:

Index : [ –50,-40]   Size : [582,582]

ROI Size :
Index : [15,0]  Size: [ 553,582]

the max index of your image is (-50 + 582, -40 + 582) = (532, 542).
You are requesting all the way to (15 + 553, 0 + 582) = (568, 582).
Note that both components are past your image!

David 



More information about the Insight-users mailing list