Reputation: 26
Problem:
I am trying to construct a vtk polydata model from a CT Nifity volume using marching cube method.
What I did:
So far I can produce a perfectly-to-scale skull model using vtk's polydata writer. However, the skull.vtk is rotated and translated rigidly when compared to the original ct.nii volume. I understand that Nifities have a QForm matrix to map voxel data to real world and vktPolyData do not have this data explicitly. However, the result of applying the QForm matrix to the vtkPolyData is not even close to perfect overlapping.
Does anyone know why this happens?
Upvotes: 0
Views: 447
Reputation: 1383
VTK and Nifty images do not share the same axis. To solve this, before using vtk,apply on your image the nibabel.as_closest_canonical()
function which reorders axis in a VTK fashion. The affine matrix is updated accordingly.
Upvotes: 0
Reputation: 434
I think the reason is that the y-axis is inverted in VTK. Most likely applying a rotation matrix of [-1 0 0; 0 -1 0; 0 0 1] (row-major) will solve your problem.
A quick and easy check is to use an external tool, e.g. 3D Slicer or Paraview, to apply the rotation. For example in paraview, you can do the following:
-Load the polydata and your image in Paraview.
-Change the rotation to (180, 180, 0) degrees (equivalent to above rotation matrix)
-See if the polydata and image line up
I have attached an example image that shows how to do this in paraview. The red is the result of applying rotation to the original blue polydata. The location of the rotation parameters is given in the green box.
Upvotes: 0