[vtkusers] vtkImageAccumulate

David Gobbi dgobbi at irus.rri.ca
Tue Jun 19 12:56:31 EDT 2001


Hi Christophe,

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?

 - David

--
  David Gobbi, MSc                       dgobbi at irus.rri.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Tue, 19 Jun 2001, Odet Christophe wrote:

>  Hi,
>
> when using vtkImageAccumulate to build histogram, I found a problem(bugs) when the image data has
> positive and negative values (signed short for example). In this case values between -1 and 1
> (after division by spacing) are grouped together in bin number 0
> due to the way "int" does its rounding in the following line (vtkImageAccumulate.cxx):
>
>   outIdx = (int)(((float)*inPtrC - origin[idxC]) / spacing[idxC]);
>
> In this case the number of values in bin 0 is approx. twice the expected number. This create a spurious
> pulse in the output histogram.
>
> I apparently solve the problem using the floor function.
>
>   outIdx = (int)floor(((float)*inPtrC - origin[idxC]) / spacing[idxC]);
>
> It can also be solved using origin and the input extent but not so easily.
>
> Am I rigth ? If yes, this is a bug and could be corrected in a next release.
>
> Thanks
>
> --
> ********************************************************************
> ODET Christophe
> CREATIS, INSA 502, F-69621 Villeurbanne cedex (France)
> tel 04 72 43 85 62
> Fax 04 72 43 85 26
> Email: christophe.odet at creatis.insa-lyon.fr
> URL:http://www.creatis.insa-lyon.fr
> ********************************************************************
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>





More information about the vtkusers mailing list