[Insight-users] SubtractImageFilter - Modification

Todd Jensen todd.jensen at ieee.org
Sun May 2 12:14:32 EDT 2010


From: Christian Werner <christian.werner at rwth-aachen.de>


> I need a slightly modified version of the itkSubtractImageFilter that 
> caps the result at 0, such that all negative values will become 0 
> instead. I know I could do that with the actual SubtractImageFilter 
> followed by a ShiftScaleImageFilter, but it is important that this is a 
> one-pass filter since we are working with extremely large (up to 1GB) data.

It would be easier to define your own function and re-use the BinaryFunctorImageFilter...example code:

// A function (not templated at this point, but could be by replacing PixelType) that will calculate difference between two points.
//
class RealDifference
{
        public:
                RealDifference() {};
                ~RealDifference() {};

                bool operator!=( const RealDifference& ) const
                {
                        return false;
                }

                bool operator==( const RealDifference& other ) const
                {
                        return !( *this != other );
                }

                inline PixelType operator()( const PixelType& A, const PixelType& B )
                {
                        return vnl_max( itk::NumericTraits< PixelType >::Zero, A - B );
                }
};

typedef itk::BinaryFunctorImageFilter< ImageType, ImageType, ImageType, RealDifference > RealDifferenceFilter;

RealDifferenceFilter::Pointer differenceFilter = RealDifferenceFilter::New();
differenceFilter->InPlaceOff(); // will re-use first input buffer as output buffer if "on".
differenceFilter->SetInput1( image1Ptr ); // A
differenceFilter->SetInput2( image2Ptr ); // B
differenceFilter->Update();

differenceImage = differenceFilter->GetOutput( 0 );


Todd Jensen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100502/05f2d0c3/attachment.htm>


More information about the Insight-users mailing list