[Insight-users] "In place" filtering

Karthik Krishnan karthik.krishnan at kitware.com
Mon Oct 25 01:13:47 EDT 2010


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


Filters that derive from itk::InPlaceImageFilter do this automatically
bypassing the usual AllocateOutputs prior to execution.




> but that seems a bit awkward.
>
> Is there a pattern that makes sense for this "in place filtering" style
> function?
>
> Thanks,
>
> David
>
> _____________________________________
> 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.html
>
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101025/09e20314/attachment.htm>


More information about the Insight-users mailing list