[Insight-users] StatisticsOnImage

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Thu Jun 22 06:08:37 EDT 2006


Hi,

On Thu, 22 Jun 2006 11:23:43 +0200, Stefan Klein <stefan at isi.uu.nl> wrote:

> Hi,
>
> The itkStatisticsOnImageFilter seems to have a small bug. When I run it  
> on
> an a 2D 256x256 image of doubles containing everywhere the same value
> (0.2506507647...), it returns a negative variance and, consequently, an
> undefined standard deviation:
> var:    -3.637423687e-014
> std:    -1.#IND
>
> This is solved by applying the following change at line 297 of the .txx.
>
>    // unbiased estimate
>    variance = (sumOfSquares - (sum*sum / static_cast<RealType>(count)))
>      / (static_cast<RealType>(count) - 1);
>    sigma = vcl_sqrt(variance);
>
> change to:
>
>    // unbiased estimate
>    variance = (sumOfSquares - (sum*sum / static_cast<RealType>(count)))
>      / (static_cast<RealType>(count) - 1);
>    // in case of numerical errors the variance might be <0.
>    variance = vnl_math_max(0.0, variance);
>    sigma = vcl_sqrt(variance);
>
> Furthermore, I have a feature request for this class: Mask support. I've
> added to this email the code that implements this (and fixes the bug).
>

IMHO, the mask support should not be added to this class - the experience  
show that it is much difficult to implement more efficient algorithm with  
that feature, like for the ConnectedComponentImageFilter. Why not use  
LabelStatisticsImageFilter to do that job ?

Gaetan



-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr


More information about the Insight-users mailing list