[Insight-users] "In place" filtering

Markus Neuner neuner.markus at gmx.net
Mon Oct 25 16:37:22 EDT 2010


On 25.10.2010 21:50, David Doria wrote:
>
>     Hi David,
>
>     You must get the output and pass it back.
>     If you want to disconnect the output from the pipeline use
>     image->DisconnectPipeline();
>
>     Try this:
>
>     void ApplyThresholding(ImageType::Pointer &image)
>     {
>      typedef itk::BinaryThresholdImageFilter <ImageType, ImageType>
>              BinaryThresholdImageFilterType;
>
>      BinaryThresholdImageFilterType::Pointer thresholdFilter
>              = BinaryThresholdImageFilterType::New();
>      thresholdFilter->SetInput(image);
>      thresholdFilter->SetLowerThreshold(10);
>      thresholdFilter->SetUpperThreshold(50);
>      thresholdFilter->SetInsideValue(255);
>      thresholdFilter->SetOutsideValue(0);
>      thresholdFilter->InPlaceOn();
>      thresholdFilter->Update();
>      image = thresholdFilter->GetOutput();
>      // OPTIONAL:
>      // image->DisconnectPipeline();
>     }
>
>     PS: I am not 100% sure if this is the "best practice".
>
>     Hope that helps,
>     Markus
>
>
> Hi Markus,
>
> You are right, if I change the function signature to pass the 'image'
> pointer by reference:
>
> void ApplyThresholding(ImageType::Pointer &image)
>
> and then assign 'image' to the pointer that is the output of the filter:
>
> image = thresholdFilter->GetOutput();
>
> the thresholded image is displayed. However, this works whether or not
> InPlaceOn has been called. What this has done is simply change 'image'
> in the calling function to point to a different image, rather than
> modify the image that 'image' was pointing to originally.
>
> Can anyone clarify the idea/usage of the InPlaceOn option?
>
> Thanks,
>
> David

Hi,

I think the input buffer is

The output image data is constructed by overwriting the input image
data.  BUT: The output bulk data is the same block of memory as the
input bulk data. The filter maintains general pipeline mechanics but use
less memory because the input buffer is reused as the output buffer.
In detail it grafts the input to the filter to the output, and may
transfer ownership of the input bulk data to the output object, which
means that the input object must release its hold on the bulk data (see
AllocateOutputs()).

This is why you must get the Output of the filter.

Cheers, Markus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101025/2ab5b144/attachment.htm>


More information about the Insight-users mailing list