[vtkusers] vtkImageAccumulate
David Gobbi
dgobbi at irus.rri.ca
Wed Jun 20 13:53:33 EDT 2001
On Wed, 20 Jun 2001, Odet Christophe wrote:
> 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.
>
> This is not clear for me...
It might just be a matter of convention. One way to build histograms
is to place the bins at 0.5, 1.5, 2.5, etc. and then the bin at 0.5 collects
values in the range [0,1), the bin at 1.5 collects the range [1,2). This
makes more sense to me, because the position of the bin corresponds to
the center of the range.
> 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 ?
Not if you set the 'origin' at e.g. 0.5, -32768.5, etc (assuming the
spacing is 1.0)
> 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.
This is all correct. That is exactly how I like the histogram-binning
math to work, with the bin located at the center of the range.
> If I am right, I think that 0.5 is not needed. But....may be I am not!
Unless we get a third opinion, we might never know ;)
- David
More information about the vtkusers
mailing list