[Insight-developers] Minor Bug in IsoContourDistanceImageFilter

Luis Ibanez luis.ibanez at kitware.com
Fri Feb 4 10:29:23 EST 2005


Hi Zach,

Thanks a lot for your bug report,

and Double thanks for providing the fix   :-)


This issue has been entered in the bug tracker as bug #1581
http://www.itk.org/Bug/bug.php?op=show&bugid=1581&pos=0


and, given that you provided the fix there was no excuse
for delays, so it was fixed right away.

We added castings to both the terms in the lines that you
pointed out, because the iterator was instantiated over the
input image type.

Please let us know if you find any further problems.


    Thanks



        Luis



----------------------
Zachary Pincus wrote:
> Hello,
> 
> There's a minor bug in itkIsoContourDistanceImageFilter.txx that causes  
> it to fail when the input image type is unsigned. (A potentially common  
> case, as this filter can be used as a step in turning a binary mask  
> into a signed distance map.)
> 
> Basically, the filter attempts to perform all its calculations in terms  
> of the output pixel type, which is appropriate. However, a few lines  
> squeaked through where the right hand side of the equation was  
> performed with only terms of the input pixel type. These lines  
> (subtractions) don't work right when the input pixel type is unsigned  
> and the result should be negative.(*)
> 
> The solution is to promote at least one term on the right hand side of  
> all the calculations to the output pixel type, which only makes sense  
> as a float or double for this filter. Then the calculation is performed  
> correctly.
> 
> Here's the patch. Sorry this is so close to the 1.10 deadline (or  
> after! oh well if so).
> 
> diff itkIsoContourDistanceImageFilter.txx  
> itkIsoContourDistanceImageFilter_orig.txx
> 266c266
> <      val0 =  
> inNeigIt.GetPixel(center)-static_cast<PixelType>(m_LevelSetValue);
> ---
>  >      val0 = inNeigIt.GetPixel(center)-m_LevelSetValue;
> 272c272
> <          grad0[ng]=inNeigIt.GetNext(ng,1)- 
> static_cast<PixelType>(inNeigIt.GetPrevious(ng,1));
> ---
>  >         grad0[ng]=inNeigIt.GetNext(ng,1)-inNeigIt.GetPrevious(ng,1);
> 278c278
> <        val1 =  inNeigIt.GetPixel(center+stride[n])- 
> static_cast<PixelType>(m_LevelSetValue);
> ---
>  >        val1 = inNeigIt.GetPixel(center+stride[n])-m_LevelSetValue;
> 286c286
> <                       
> static_cast<PixelType>(inNeigIt.GetPixel(center+stride[n]-stride[ng]));
> ---
>  >                      inNeigIt.GetPixel(center+stride[n]-stride[ng]);
> 
> 
> Zach Pincus
> Department of Biochemistry and Program in Biomedical Informatics
> Stanford University School of Medicine
> 
> (*) Well, actually, on my little-endian platform with gcc, "float a =  
> (unsigned char) 5 - (unsigned char) 10" gives a = -5 , but "float a =  
> (unsigned int) 5 - (unsigned int) 10" blows up. I suspect a strange  
> interaction with unsigned underflow and how the cast operator was  
> implemented. At any rate, this means that this filter, through  
> basically luck, works with input image type unsigned char, but not with  
> unsigned int.
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
> 
> 





More information about the Insight-developers mailing list