I have a program that shows the three major axii of a volume using vtkImageViewer2 and I want to output a single image given the x, y, or z slice number. I've been using vtkImageReslice to accomplish this task. Outputting the XY plane is easy, I just do:
reslicer->setResliceAxesOrigin(0, 0, slice * spacing);
I don't have to transform the plane as XY is default. Then I just set the z of the plane, which in physical space would be the slice number * spacing.
Now to do the same thing but with the YZ plane I do:
reslicer->SetResliceAxesOrigin(0, 0, slice * spacing);
transform->Translate(extent, extent, extent);
transform->Translate(-extent, -extent, -extent);
Note: extent[i] = dim[i] * spacing[i], not vtk's image data extent.
So I transform to the origin, then rotate the plane on the Y axis. I've noticed that the axes origin gets applied after transform so the slice number that would have been on the x axis should be specified as z in SetResliceAxesOrigin. Also to get the correct depth of the slice I need the spacing from the corresponding axis in the image which would be x axis spacing or spacing.
Now the problem is that while the transform works perfectly the slice number isn't the correct one. In fact it's a suspicious number.
With this input image:
Dim = 240, 240, 163
Spacing = 1.0444, 1.0444, 1.0999
Dim with Spacing (size) ~ 249, 249, 179
When I try to export the middle slice, 120, I get the wrong slice. Now I noticed if I swap the spacing with the spacing of the z axis (spacing) then I get the middle slice of the z axis. Slice 81 (163/2 floored). Which makes me think the slice is somehow in z axis scale. So I tried manually rescaling the axesorigin by normalizing the slice. frac = slice / maxslice or 0.5 = 120 / 240. Then frac * size or 0.5 * 163 * 1.0999. But the scaling is still off. While I get the correct slice from 120 all the others are still off.
It's possible to simplify things by using one transformation instead of two: When using SetResliceAxesOrigin(), it's best to use SetResliceAxesDirectionCosines
I'm going to define maxpos instead of extent:
maxpos[i] = (dim[i] - 1) * spacing[i]
The "- 1" is very important: the idea here is that the first slice is at position 0, and the last slice is at position n-1 if "n" is the number of slices. Then we can set up vtkImageReslice as follows:
reslicer->SetOutputOrigin(0.0, 0.0, 0.0);
The "direction cosines" specify the orientation of the extracted slices: in the above example, (0, 1, 0) is in the "y" direction and (0, 0, -1) is in the "-z" direction so it will show a slice from the YZ plane. The third direction (-1, 0, 0) is the slicing direction, and it must be set to the cross product of the other two directions.
The reason that the ResliceAxesOrigin must be set to (slicepos, 0.0, maxpos) in this case is that the "z" component of one of the direction cosines is negative.
On Wed, Jun 14, 2017 at 11:35 PM, Andaharoo <[hidden email]> wrote:
I have a program that shows the three major axii of a volume using
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
Search the list archives at: http://markmail.org/search/?q=vtkusers
Follow this link to subscribe/unsubscribe:
|Free forum by Nabble||Edit this page|