[Insight-developers] SubtractImageFilter strange behavior ?

Karthik Krishnan Karthik.Krishnan at kitware.com
Wed Nov 16 12:59:48 EST 2005



Gaetan Lehmann wrote:

>
> Hi,
>
> I have done a morphological gradient image filter in which I use a  
> SubtractImageFilter. Everything seems to work fine, but
> when  I tried to remove the subtract filter and do the subtraction by  
> hand, I don't get the same result.
>
> This part of code:
>
>   // Need to subtract the eroded image from the dialted one
>   typename SubtractImageFilter<TInputImage, TInputImage,  
> TOutputImage>::Pointer
>     
> subtract=SubtractImageFilter<TInputImage,TInputImage,TOutputImage>::New(); 
>
>   subtract->SetInput1( dilate->GetInput() );

should be dilate->GetOutput();   , shouldn't it   ........

>   subtract->SetInput2( erode->GetOutput() );
>
>   // graft our output to the subtract filter to force the proper regions
>   // to be generated
>   subtract->GraftOutput( this->GetOutput() );
>
>   progress->RegisterInternalFilter(subtract,.1f);
>
>   dilate->Update(); // needed to have the right progress values
>   subtract->Update();
>
>   // graft the output of the subtract filter back onto this filter's
>   // output. this is needed to get the appropriate regions passed
>   // back.
>   this->GraftOutput( subtract->GetOutput() );
>
>
> and this one
>
>   dilate->Update();
>   erode->Update();
>
>   const TInputImage* inputPtr1 = dilate->GetOutput();
>   const TInputImage* inputPtr2 = erode->GetOutput();
>   const TInputImage* inputPtr = this->GetInput();
>   TOutputImage* outputPtr = this->GetOutput();
>
>   ImageRegionConstIterator<TInputImage> inputIt1(inputPtr1,  
> inputPtr->GetRequestedRegion());
>   ImageRegionConstIterator<TInputImage> inputIt2(inputPtr2,  
> inputPtr->GetRequestedRegion());
>
>   ImageRegionIterator<TOutputImage> outputIt(outputPtr,  
> inputPtr->GetRequestedRegion());
>
>   inputIt1.GoToBegin();
>   inputIt2.GoToBegin();
>   outputIt.GoToBegin();
>
>   while( !inputIt1.IsAtEnd() )
>     {
>     outputIt.Set( static_cast< typename TOutputImage::PixelType
> ( inputIt1.Get() - inputIt2.Get() ) );
>     ++inputIt2;
>     ++inputIt1;
>     ++outputIt;
>     }
>
>
> does not produce the same output.
>
> Am I doing something wrong ?
> Or is it a problem in SubtractImageFilter ?
>
> Attached gradient.png is the result with the subtract filter.
> http://voxel.jouy.inra.fr/darcs/contrib-itk/gradient/gradient.png is 
> the  result without the subtract filter.
> The full code is available at  
> http://voxel.jouy.inra.fr/darcs/contrib-itk/gradient/
>
> Regards,
>
> Gaetan
>


More information about the Insight-developers mailing list