[Insight-users] "In place" filtering

Markus Neuner neuner.markus at gmx.net
Mon Oct 25 15:43:21 EDT 2010


On 25.10.2010 17:43, David Doria wrote:
> On Mon, Oct 25, 2010 at 1:44 AM, Dan Mueller <dan.muel at gmail.com> wrote:
>   
>> Hi David,
>>
>> As Karthik says, a true "in-place" filter overwrites each pixel of the
>> input buffer with the resultant output pixel value and then passes the
>> input buffer as its output. All filters capable of this should inherit
>> from itk::InPlaceImageFilter (if you find one that doesn't, please let
>> us know). You to turn on/off this functionality eg.
>> filter->InPlaceOn(), filter->InPlaceOff().
>>
>> The itk::MeanImageFilter does not inherit from
>> itk::InPlaceImageFilter, the reason being it is a neighbourhood
>> operation; neighbourhood operations *cannot* be run in-place (the
>> output for one pixel may be used as the input for another pixel!).
>>
>> The best you can do is use the ReleaseDataFlagOn() method Karthik
>> described first.
>>
>> HTH
>>
>> Cheers, Dan
>>     
> Ok, lets take filters that do derive from InPlaceImageFilter for the moment.
>
> Here is the structure:
> http://www.itk.org/Wiki/ITK/Examples/Broken/Images/InPlace
>
> The image that is displayed is still the non-thresholded version even
> though I set InPlaceOn in the threshold filter in the
> ApplyThresholding function.
>
> It seems like the reader is trying to set the readers output and the
> ApplyThresholding function is also trying to set that same data. Is
> there 1) a way to separate 'image' from the reader before sending it
> for filtering? or 2) a way to do this inplace filtering without
> breaking off from the pipeline?
>
> Thanks for your help so far,
>
> David
>   

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




More information about the Insight-users mailing list