[Insight-users] Problem with itkConvolutionImageFilter

Cory Quammen cquammen at cs.unc.edu
Mon Aug 27 12:04:04 EDT 2012


Matthias,

All I meant is you are the first to uncover the problem when using the
code this way :-)

What you describe makes perfect sense.

The ConvolutionImageFilter uses the NeighborhoodOperatorImageFilter
underneath the covers to compute the convolution, so I expect the
problem is there. This means that any other filter that uses
NeighborhoodOperatorImageFilter currently cannot be used in this way,
and there are a number of those in ITK.

I don't have time at the moment to look into this deeper. If you are
so inclined, I would set your debugger to break in the method
itk::NeighborhoodOperatorImageFilter::GenerateInputRequestedRegion()
and see what the input requested region is padded to.

Thanks,
Cory

On Mon, Aug 27, 2012 at 11:48 AM, Matthias Schneider
<schneider at vision.ee.ethz.ch> wrote:
> Cory,
>
> Thanks for your quick reply.
> I don't think this is an extremely special use-case. Consider a
> convolution-based feature to be extracted at certain interest points in the
> image. If the interest points are somewhat sparse, it is obviously much
> faster to apply the convolution to several ROIs of size 1 in each dimension
> rather than convolving the whole image.
> As for the expected behavior, I would say this is pretty much straight
> forward. The pipeline says
>
> [Input] -> [Compute Convolution] -> [Extract ROI] -> [Output]
>
> I don't think expanding the output's ROI or doing some awkward extrapolation
> is really meaningful here. The latter would rather map to:
>
> [Input] -> [Extract ROI] -> [Compute Convolution] ->  [Output]
>
> Personally, I would expect the filter to generate the same output as
> produced by
>
> 1. Compute the convolution for the whole image
> 2. Feed the output to the ROI extractor
>
> This works for all examples but involves a huge computational overhead, of
> course.
>
> Hope that makes sense...
>
> Best,
> matthias
>
>
> On 08/27/2012 05:23 PM, 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
>>
>>
>>
>>
>
> --
> 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


More information about the Insight-users mailing list