[vtkusers] vtkImageAccumulate

Odet Christophe christophe.odet at creatis.insa-lyon.fr
Wed Jun 20 10:34:11 EDT 2001


Hi, David,

> This does look like a bug.  But I think that the code should actually read
> 
> outIdx = (int)floor(((float)*inPtrC - origin[idxC]) / spacing[idxC] + 0.5)
> 
> where the '0.5' ensures that the value is rounded, not merely truncated.
> Otherwise there will be an overall shift error of 0.5 in cases where
> either the origin is not an integer or the spacing is not unity.  Does
> this work for you?

This is not clear for me...

If I understand the code, this line computes the integer index in the output array,
where the values are accumulated. Values between origin(included) and
origin + spacing (excluded) are accumulated in bin 0, Values between 
origin+spacing (included) and origin + 2*spacing (excluded) are accumulated in bin 1
and so on.
This is why I suppose floor is needed... even if origin or spacing are not integers.

If you add 0.5 before rounding, this will change the rule and can create problems
at both ends of the histogram with something like "half filled" bins. Am I right ?

Addition of 0.5 means that bin number k contains the accumulated values between
origin+k*spacing-spacing/2 (included) and origin + k*spacing+spacing/2 (excluded) 
with origin+k*spacing representing the center of bin number k.

If I am right, I think that 0.5 is not needed. But....may be I am not!

Thanks

- Christophe





More information about the vtkusers mailing list