models and NRRD files exported from Slicer don't align in vtkjs/itk

I have NRRD files from which models have been generated in Slicer, in register.

I read them into vtkjs using vtkITKImageReader, ImageMapper, and ImageSlice, following the appropriate example vtkjs code.

The slices and models are generally in the right place and their bounding boxes are aligned. However, the I and J axes seem swapped in the slices so that the image doesn’t align with the model. I’m seeing the same problem in all other data sets from our atlases.

Here’s a demo of the problem. These models and volume align in Slicer. Look at a high K slice to see that the images are mirrored.

I’d like to find the most appropriate place to do the transform or otherwise fix the problem. Thanks.

1 Like

Hi Mike - It sounds like an RAS vs LPS issue. The slicer vtp files will be RAS but the ITK reader probably gives you LPS space. Did you try negating the upper two diagonal elements of the directions?


1 Like

This might be a RAS/LPS difference, since the NRRD is in LPS and the vtp files are likely RAS. I played around with your example, and if you negate the x and y coords of the VTP points and normals, everything lines up. Not sure if Slicer is transforming the image or the polydata before displaying.

EDIT: looks like Steve beat me by a minute :stuck_out_tongue:

1 Like

+1 :slight_smile:

More details on the RAS polydata exported by Slicer can be found in this issue. h/t @jcfr

This is a fantastic demo, btw :clap:

Thanks. To be clear, the models look correct but the images are transposed in I and J.

I did try negating the two elements on the diagonal directions, which worked except it also flipped the volume around its origin so the models were no longer aligned. My next step was to translate the origin. I didn’t want to get too far down this path in case there was something like a NRRD reader bug or something like that.

Shouldn’t NRRD capture this information and keep this problem from happening? Seems like the space should be specified fully. No matter what coordinate space the image is in, we should be able to get the data to display appropriately in world space. If this is a NRRD reader problem, I don’t want to have to un-workaround the problem for DICOM, for instance.


Hi Mike -

I would argue that the image data is ‘correct’ from a vtk.js point of view but the models are wrong, but that’s just a matter of convention. vtp format doesn’t specify a reference space, so slicer’s convention is to write them out in RAS.

The NRRD file does include a reference space, and the ITK readers respect that, so I presume that the ITK-based readers in vtk.js also do that and convert the need directions to LPS.

Of course vtk.js itself could be used with either LPS or RAS, but since you are using the ITK readers it’s probably best to transform the models to match the images.

I changed the demo to reference an abdominal model that includes only structures on the patient’s right (and the liver, which is primarily on the right).

The models appear correct. It’s the images that aren’t correct.

And if it matters, all the NRRD files have the space defined as LPS.

Slicer is moving towards using LPS in all file input/output, but it is not there yet. I’ve already implemented automatic transformation of mesh point coordinates to/from LPS in Slicer’s model importer but I realized that point and cell data may have to be transformed, too, and I did not have time to implement a robust method for distinguishing spatial data from other 3-component floating-point data (such as color). I plan to get back to working on this soon.

I added a flipping i and j hack to the demo. I do:

new_origin = indexToWorld(i_max, j_max, 0);
new_spacing  = (-spacing_i, -spacing_j, spacing_k)

and everything aligns and looks anatomically correct.

Somewhere there’s a coordinate system problem. As I said, the NRRD file is already LPS.

Currently, if you save a model in Slicer using Save dialog then it will be in RAS coordinates system. If you use Segmentation module’s “Export to file” feature then you can choose between RAS and LPS coordinate system.

1 Like