Import displacement field from Matlab

Hi everyone.

I was wondering if on 3D Slicer it was possible to import a registration matrix that I obtained with Matlab (using an optical flow algorithm), so to apply it to a segment.
In my case I have three 512x512x306 matrices (pixel * pixel * number of slices), each one containing the displacements of each pixel respectively in x, y, z direction.

Thank you very much,
kind regards

Yes, you can import a displacement field into Slicer very easily. All you need is to save the displacement field matrix into a nrrd file using nrrdwrite.m and load that file into Slicer as a Transform.

I tried with my 4D matrix 512x512x205x3 (where 3 is x, y, z displacement), and I got this error:

Undefined function ‘nrrdaddmetafield’ for input arguments of type ‘struct’.

Error in nrrdwrite (line 117)

  • img = nrrdaddmetafield(img,‘MultiVolume.NumberOfFrames’,size(img.pixelData,4));*

Error in PROVAnrrd (line 45)
nrrdwrite(‘testOutput_x.nrrd’, img);

So I divided the 4D displacement matrix into three 3D displacement matrices (512x512x205), each one containing x or y or z displacements. In this case nrrdwrite works.

However when I import one of these three matrices into 3D slicer I get this:
image

Despite the grid origin, grid size … are correct (comparing with others transformation, for example by Elastix).