[Insight-users] Problem with itkConvolutionImageFilter

Matthias Schneider schneider at vision.ee.ethz.ch
Mon Aug 27 09:57:31 EDT 2012


Hi,

I noticed some "strange" behavior of the convolution filter.
Applying the ConvolutionImageFilter to a small region of interest (ROI) 
of an image seems to work iff the kernel size somehow matches the ROI.

In the code attached below I use a 100x100x100 voxel image.
Applying the filter for different kernel sizes and ROI configurations I 
get (kernel size [KS], ROI index [RI], ROI size [RS]):

[KS]	[RI]	[RS]	[ERROR]
5	0	2	OK
5	0	1	ERROR
5	1	1	ERROR

6	0	2	ERROR
6	0	3	OK
6	1	2	OK

The error look like this, e.g. for the case
[KS]=5, [RI]=0, [RS]=1

== BEGIN ERROR MESSAGE ==
itk::ERROR: MultiThreader(0x1a31350): Exception occurred during 
SingleMethodExecute
[some 
path]/InsightToolkit-4.1.0/Modules/Core/Common/include/itkImageConstIterator.h:177:
itk::ERROR: Region ImageRegion (0x7fff61cb7ae0)
   Dimension: 3
   Index: [2, 0, 0]
   Size: [1, 1, 1]
  is outside of buffered region ImageRegion (0x1a2f770)
   Dimension: 3
   Index: [0, 0, 0]
   Size: [1, 1, 1]

Aborted
== END ERROR MESSAGE ==

It seems like in this case the condition is something like
[RI]+[RS] >= floor([KS]/2)

But I do not fully understand where this might come from?!

For the record, I am using ITK 4.1.0 (self-compiled)

Any hint/help is appreciated very much!

Thanks,
matthias



This is the code:

== BEGIN CODE ==

#include <itkConvolutionImageFilter.h>
#include <itkRegionOfInterestImageFilter.h>

int main(int argc, char **argv) {
   typedef itk::Image<double, 3> ImageType;
   typedef ImageType::RegionType RegionType;

   int kernelSize = atoi(argv[1]);
   int roiIndex = atoi(argv[2]);
   int roiSize = atoi(argv[3]);

   // set up image regions
   RegionType imageRegion, kernelRegion, roi;
   for (unsigned int i = 0; i < ImageType::ImageDimension; ++i) {
     imageRegion.SetSize(i, 100);
     kernelRegion.SetSize(i, kernelSize);
     roi.SetSize(i, roiSize);
     roi.SetIndex(i, roiIndex);
   }

   // allocate test image
   ImageType::Pointer image = ImageType::New();
   image->SetRegions(imageRegion);
   image->Allocate();
   image->FillBuffer(1.0);

   // allocate kernel
   ImageType::Pointer kernel = ImageType::New();
   kernel->SetRegions(kernelRegion);
   kernel->Allocate();
   kernel->FillBuffer(1.0);

   // set up convolution
   typedef itk::ConvolutionImageFilter<ImageType> FilterType;
   FilterType::Pointer conv = FilterType::New();
   conv->SetOutputRegionModeToSame();
   conv->SetInput(image);
   conv->SetKernelImage(kernel);

   // extract region of interest
   typedef itk::RegionOfInterestImageFilter<ImageType, ImageType> 
ExtractorFilterType;
   ExtractorFilterType::Pointer extractor = ExtractorFilterType::New();
   extractor->SetInput(conv->GetOutput());
   extractor->SetRegionOfInterest(roi);

   // run pipeline
   extractor->Update();

   /* NOTE: Skipping the RegionOfInterestImageFilter and directly
    * setting the ROI on the convolution filter output results in the
    * same behavior
    * [...]
    * conv->GetOutput()->SetRequestedRegion(roi);
    * conv->Update();
    */

   return 1;
}

== END CODE ==

-- 
Matthias Schneider
Computer Vision Laboratory

ETH Zürich, ETF D114.1
Sternwartstrasse 7
8092 Zürich, Switzerland

fon: +41 44 63 20379
fax: +41 44 63 21199
www.vision.ee.ethz.ch/~schneima/


More information about the Insight-users mailing list