[vtkusers] GetCenter of vtkImageData - a possible bug?

Berk Geveci berk.geveci at kitware.com
Wed Mar 19 09:25:13 EDT 2014


According to the VTK convention, you calculation is incorrect. Note that
VTK assign each value of an image to a vertex not to a cell. So if the
dimensions are {2,2,2} and spacing is {1,1,1}, the bounds of the data will
be {0, 1, 0, 1, 0, 1}. So the right way of calculating origin is:

     double origin[3], spacing[3], center[3];
     int dimensions[3];

     imageData->GetOrigin(origin);
     imageData->GetSpacing(spacing);
     imageData->GetDimensions(dimensions);

     for(int i = 0; i < 3; i++)
     {
         center[i] = origin[i] + ((dimensions[i] - 1 ) * spacing[i]))/2;
     }

Best,
-berk



On Wed, Mar 19, 2014 at 7:06 AM, chasank <chasank at gmail.com> wrote:

> Hi,
>
> I have a nifti image that has these features below:
>
>      Dimensions : {301, 370, 316}
>      Origin : {75, 107, -69.5}
>      Spacing : {0.5, 0.5, 0.5}
>
> I want to get center world point of the image. When I use GetCenter method
> of vtkImageData for this purpose, I get {150, 199.25, 9.25}. However, I
> suspected that it seems a bit wrong. And then I tried to calculate the
> center point on my own like below:
>
>      double origin[3], spacing[3], center[3];
>      int dimensions[3];
>
>      imageData->GetOrigin(origin);
>      imageData->GetSpacing(spacing);
>      imageData->GetDimensions(dimensions);
>
>      for(int i = 0; i < 3; i++)
>      {
>          center[i] = origin[i] + ((dimensions[i] / 2) * spacing[i]);
>      }
>
> and center world point becomes {150, 199.5, 9.5}. So which result is true?
> My calculation or GetCenter method?
>
> Best regards.
> Chasan
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/GetCenter-of-vtkImageData-a-possible-bug-tp5726392.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140319/169fe986/attachment.html>


More information about the vtkusers mailing list