[Insight-developers] Re: A bug can appear in itkConfidenceConnectedImageFilter.txx

Luis Ibanez luis.ibanez at kitware.com
Mon Jun 20 10:17:30 EDT 2005



Hi Fabien,


Thanks for pointing this out.

This is an interesting case of precision loss.


However, I would disagre with your solution of
taking the Absolute value of the difference.
That value is in itself meaningless, it is just
the subtraction of two errors. Taking its abs
value is as arbitrary as just truncating the value
to zero.


It seems that the real solution here is to make
sure that the computations are done in "double"
instead of floats.


You are probably using an image of "unsigned chars"
whose "RealType" is float.


What I would suggest to do here is to explicitly
compute the mean and variance using "double", and
only at the end return them inside the float
variables of m_Mean and m_Variance.



Please let us know if this option makes sense to
you, and in that case we will make the appropriate
modifications in the CVS repository.



    Regards


       Luis




-----------------------------------
fabien.laizet at free.fr wrote:
> Hi,
> 
> In this filter, at line 169, a variance is computed as below :
> 
> m_Variance -= m_Mean * m_Mean
> 
> If the real value of the variance is very very small (but not equal to zero) :
> 
> m_Variance - m_Mean * m_Mean equals to the difference between computation
> errors. We met such a case with computation errors due to the round of float
> values. As a result the difference may be smaller than zero ( -1.818e-12 in our
> case ) and at lines 172 and 173 sqrt( m_Variance ) return an undefined value.
> 
> In our case, we solved this problem as below :
> 
> sqrt( abs( m_Variance ) )
> 
> At line 257, there is another variance computation. We didn't meet any problem
> at this line but i think that a similar problem could appear.
> 
> Regards,
> 
> Fabien LAIZET
> 
> 
> 





More information about the Insight-developers mailing list