[Insight-users] Problem with itkConvolutionImageFilter

Bradley Lowekamp blowekamp at mail.nih.gov
Mon Aug 27 11:37:56 EDT 2012


Hello Cory,

The Convolution filter should expand it's input's requested region, to avoid boundary artifacts between requested regions.

The output of updating the largest possible region should be the same as when the filter is only updating a ROI. A good test is to check that the output of a full update matches that of when the filter is being driven by the StreamingImageFilter or the ImageFileWriter with a SetNumberOfStreamDivisions to a number.

Brad

On Aug 27, 2012, at 11:23 AM, Cory Quammen wrote:

> Matthias,
> 
> You've uncovered a use-case that no one else has. I'm not too
> surprised it doesn't work when the image region is smaller than the
> kernel.
> 
> What would your expectation be if this worked? Would you want the
> convolution filter to expand the requested region of the image when
> the kernel is larger? Or would you want to apply the boundary
> condition to extrapolate values beyond the requested region?
> 
> The first option seems reasonable to me. What do you think?
> 
> Thanks,
> Cory
> 
> On Mon, Aug 27, 2012 at 9:57 AM, Matthias Schneider
> <schneider at vision.ee.ethz.ch> wrote:
>> 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/
>> _____________________________________
>> Powered by www.kitware.com
>> 
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>> 
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>> 
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
> 
> 
> 
> -- 
> Cory Quammen
> Research Associate
> Department of Computer Science
> The University of North Carolina at Chapel Hill
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

========================================================
Bradley Lowekamp  
Medical Science and Computing for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120827/4c3edfe9/attachment.htm>


More information about the Insight-users mailing list