[vtkusers] very newbie question

David Gobbi dgobbi at atamai.com
Wed Jan 17 11:16:45 EST 2007


Hi Luca,

An easy way to calculate the min/max bounding box for an image is with 
GetBounds().  This method only works after you have updated the 
pipeline.  For example, if the name of your vtkChangeInformation filter 
is "changeInformation",

double bounds[6];
vtkImageData *output = changeInformation->GetOutput();
output->UpdateInformation();
output->SetUpdateExtentToWholeExtent();
output->Update();
output->GetBounds(bounds);

double xMin = bounds[0];
double xMax = bounds[1];
double yMin = bounds[2];
double yMax = bounds[3];
double zMin = bounds[4];
double zMax = bounds[5];

There is something that you have to watch out for, not only in VTK but 
with pretty much any 3D image software: the image space coordinates 
specify the position at the centers of the voxels, not at the edges of 
the voxels.  Try this thought experiment: imagine an image that is just 
2x2x1 in size (two voxels by two voxels) and each voxel is 1mm in size.  
What is xMax-xMin for this image?  It will be 1mm, since you are 
measuring from the center of the first voxel to the center of the second 
voxel.  So, then, what is the width of the image?  Is it 1mm, or is it 
2mm?  As counterintuitive as it may seem, the image is 1mm in width, 
when computed using the Bounds, even though it is 2 voxels across.  
Likewise, an image that is 256 voxels across will have a width of 255mm, 
if you measure from the center of the first voxel to the center of the 
last voxel.

 - David



Luca Pamparana wrote:
> Hi everyone,
>
> I have a very simple newbie question for which I apologize.
>
> I have an image that I have read with a vtk reader and based on some 
> command line parameter it might or might not be passed through the 
> vtkImageChangeInformation filter that will center the image around the 
> center of the read volume.
>
> Now, my question is how do I find the extent of the image in mm? So, I 
> want to know the the minimum/maximum x, y and z values but in mm i.e. 
> image space.
>
> Thank you. I hope someone can answer my question. Some pseudocode will 
> be great also!
>
> Thank you to the VTK team for making a fine library :)
>
> Luca Pamparana
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   




More information about the vtkusers mailing list