[vtkusers] using vtkLandmarkTransform to align two nii volumes

David Gobbi david.gobbi at gmail.com
Fri Oct 12 10:31:00 EDT 2018


Hi Jon,

The vtkNIFTIImageReader ensures that the vtkImageData that it produces
follows the right-hand-rule, even if the slices were ordered in
reverse in the NIFTI file itself. As the documentation states:

  ...if QFac is -1, then the first slice in the VTK image data is the
last slice in the NIFTI file...

All the details of qfac are documented in the nifti header file:
https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h

Use of the qform in VTK is optional.  Use it if you want to work in
RAS coordinates.  But often it is both simpler and more appropriate to
work in VTK data coordinates instead, and to me it sounds like this is
the case for the original question.  In any case, vtkImageReslice uses
VTK data coordinates (not VTK world coordinates, nor RAS coordinates).

I know this isn't a very clear explanation, but unfortunately it's all
I have time for (and all that my brain is capable of right now, given
the tiny amount of sleep I've had over the past few days).

 - David


On Fri, Oct 12, 2018 at 7:05 AM Jon Haitz Legarreta Gorroño
<jon.haitz.legarreta at gmail.com> wrote:
>
> Hi,
> I'd dare to say that the short answer is yes.
>
> Long answer is that VTK deals with world coordinates, and according to
> the right hand rule. NIfTI uses RAS convention. According to the
> vtkNIFTIImageReader::GetQFormMatrix documentation, NIfTI does not
> ensure that coordinates are stored following that convention, so you
> should definitely use the matrix given.
>
> The following Slicer 3D wiki page and David Gobbi's document be
> helpful to this end:
> https://www.slicer.org/wiki/Coordinate_systems
> http://calgaryimageanalysis.ca/wiki/images/5/52/Image-orientation.pdf
>
> May be David himself can chime in and be able to provide a better or
> cleaner explanation.
>
> HTH,
> JON HAITZ
>
> On Thu, Oct 11, 2018 at 11:05 AM The Merper <msmerps at gmail.com> wrote:
> >
> > Hi VTK experts,
> >    I am trying to using vtkLandmarkTransform  to align two nii volumes and am getting puzzling results. I identify the landmarks in the two 3D volumes by visualizing the volumes in VTK and using the GetPickPosition method. The coordinates I get are in units of mm with the origin being one corner of 3D volume.
> >     I then use vtkLandmarkTransform to get an affine transformation to align the points. The points align great, but when I apply that same transform to the analogous nii volume via vtkImageReslice, the results are wildly off (e.g., the volume is flipped upside down).
> >    Is the qform matrix of each nii file somehow causing this? Do I need to first apply the qform matrix to the landmark points to get them in scanner coordinates before using vtkLandmarkTransform?
> >        thank you for any advice you can provide,
> >             -Ms. Merps


More information about the vtkusers mailing list