[vtkusers] ComputeTransformedOrigin bug in vtkImageReader.cxx

Josh Snyder jsnyder at nmr.mgh.harvard.edu
Tue Apr 20 15:15:02 EDT 2004


I've run into a problem using vtkImageReader with the SetTransform 
functionality, and I think it's due to the line of code referenced in 
the post below (line 495 in the current CVS version). It seems to me 
that the older version (w/out the +1) was correct. My understanding is 
that if the Transform specifies an axis reversal, the order of the 
voxels along that axis needs to be reversed, and the origin coordinate 
for that axis needs to be shifted so that the voxels originally 
occurring at negative locations become positive and vice versa. The 
former step is handled by the inverse transform of the increments during 
the vtkImageReaderUpdate2 method, and the latter by the code mentioned 
below. I think the +1 addition is a bug. For example, consider the case 
where the extent in the y direction consists of a single voxel situated 
at y = -1, and the Transform specifies that this axis be reversed. This 
line should translate the origin to +1, so that the voxel is newly 
situated at +1.

In this case, the variables would be set as follows:
original origin[1] = -1
original spacing[1] = 1

Transform =
1 0 0 0
0 -1 0 0
0 0 1 0
0 0 0 1

yields

transformedOrigin[1] = 1
transformedSpacing[1] = -1

transformedExtent[3] = 0
transformedExtent[2] = 0
i = 1

The current code:
origin[i] = transformedOrigin[i] + 
transformedSpacing[i]*(transformedExtent[i*2+1] -  
transformedExtent[i*2] + 1)
= 1 + (-1 * (0 - 0 + 1)) = 1 - 1 = 0

The old (correct?) code:
origin[i] = transformedOrigin[i] + 
transformedSpacing[i]*(transformedExtent[i*2+1] -  transformedExtent[i*2])
= 1 + (-1 * (0 - 0)) = 1 + 0 = 1

Is my understanding of this correct, or is there something I'm missing?

Josh

>Simon,
>
>I checked in your corrections this morning. I also fixed graphics/vtkVolume16Reader. Its logic was
>also flawed.
>
>Thanks,
>
>Bill
>
>-----Original Message-----
>From: Simon Warfield [mailto:warfield at bwh.harvard.edu <mailto:warfield%20at%20bwh.harvard.edu>]
>Sent: Sunday, July 08, 2001 7:09 PM
>To: vtkusers at public.kitware.com <mailto:vtkusers%20at%20public.kitware.com>
>Subject: [vtkusers] bug in vtkImageReader.cxx ?
>
>
>
>I notice that if I read some image data using vtkImageReader and transform
>it to correct for patient orientation using the vtkImagerReader::SetTransform
>function, then the new origin is at an unexpected location.
>
>I get data looking like:
># vtk DataFile Version 3.0
>vtk output
>BINARY
>DATASET STRUCTURED_POINTS
>DIMENSIONS 256 256 90
>SPACING 0.703125 0.703125 1.5
>ORIGIN -90 -89.2969 -67.5
>CELL_DATA 5787225
>POINT_DATA 5898240
>
>When I expect to get data looking like:
># vtk DataFile Version 3.0
>vtk output
>BINARY
>DATASET STRUCTURED_POINTS
>DIMENSIONS 256 256 90
>SPACING 0.703125 0.703125 1.5
>ORIGIN -90 -90 -67.5
>CELL_DATA 5787225
>POINT_DATA 5898240
>
>  I think the problem is that line 936 of imaging/vtkImageReader.cxx should not
>read
>          (transformedExtent[i*2+1] -  transformedExtent[i*2]);
>but instead should be:
>          (transformedExtent[i*2+1] -  transformedExtent[i*2]+1);
>
>  This part of vtkImageReader.cxx in the latest vtk nightly is doing a shift 
>of the origin when an axis is reflected, but seems to be using one less
>than the width of the data to compute the new origin. I think the width
>of the data should be used.
>
>  Could someone check this, and make the change to the CVS repository if it
>should be fixed ?
>
>-- 
>Simon Warfield, Ph.D. warfield at bwh.harvard.edu <mailto:warfield%20at%20bwh.harvard.edu> Phone:617-732-7090
>http://www.spl.harvard.edu/~warfield <http://www.spl.harvard.edu/%7Ewarfield>           FAX:  617-582-6033
>Thorn 329, Brigham and Women's Hospital, Harvard Medical School
>Department of Radiology, 75 Francis St, Boston, MA, 02115
>




More information about the vtkusers mailing list