[Insight-users] "In place" filtering

Karthik Krishnan karthik.krishnan at kitware.com
Mon Oct 25 01:18:54 EDT 2010


On Mon, Oct 25, 2010 at 10:43 AM, Karthik Krishnan <
karthik.krishnan at kitware.com> wrote:

> On Mon, Oct 25, 2010 at 3:49 AM, David Doria <daviddoria at gmail.com> wrote:
>
>> I don't believe the following will work. The idea is to pass an image to a
>> function and smooth it "in place".
>>
>> ImageType::Pointer image = get image from somewhere...
>> SmoothImage(image);
>>
>> where:
>>
>> void SmoothImage(ImageType::Pointer image)
>> {
>>  // Create and setup a mean filter
>>  typedef itk::MeanImageFilter<
>>   ImageType, ImageType >  filterType;
>>
>>   filterType::Pointer meanFilter = filterType::New();
>>   meanFilter->SetInput(image);
>>   meanFilter->Update();
>>
>>   image = meanFilter->GetOutput();
>> }
>>
>> Of course you can do this:
>>
>> ImageType::Pointer image = get image from somewhere...
>> ImageType::Pointer output = ImageType::Pointer::New();
>> SmoothImage(image, output);
>>
>> void SmoothImage(ImageType::Pointer image, ImageType::Pointer output)
>> {
>>  // Create and setup a mean filter
>>  typedef itk::MeanImageFilter<
>>   ImageType, ImageType >  filterType;
>>
>>   filterType::Pointer meanFilter = filterType::New();
>>   meanFilter->SetInput(image);
>>   meanFilter->Update();
>>
>>   output = meanFilter->GetOutput();
>> }
>>
>
>
> That's not an inplace processing of the data. What is being done above is
> to allocate the output buffer, in addition to the input buffer - executing
> the filter - and then taking a reference the newly created output buffer
> into the variable "output".
>
> You might as well just set ReleaseDataFlagOn() on the meanFilter. That way,
> the memory footprint remains the same as above, and the code is cleaner. Its
> input gets released after a downstream filter has consumed its output.
>
> A in-place filter overwrites its input buffer. The snippet below should do
> that
>
>   meanFilter->SetInput(image);
>   meanFilter->GraftOutput(image);
>   meanFilter->Update();
>
>
Ascertain this by printing the image object to and after execution..
something like:

  meanFilter->SetInput(image);
  meanFilter->GraftOutput(image);

  meanFilter->GetInput()->Print(std::cout);
  meanFilter->Update();
  meanFilter->GetOutput()->Print(std::cout);

... and the internal PixelContainer object on the input as well as the
output should (hopefully :) ) have the same address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101025/5e783a5c/attachment-0001.htm>


More information about the Insight-users mailing list