Reading Matlab mat file into 3D Slicer

Hello!
I made several X-ray images of a metal ball of different density from different angles.
Then I applied CBCT reconstruction to them and got a *.mat file.
3D Cone beam CT (CBCT) projection backprojection FDK, iterative reconstruction Matlab examples
How can I transfer the received data to a 3D Slicer to render the object and get a 3D model?
Thank you all in advance!

Probably the easiest is to save the reconstructed image as a standard NRRD image file.

There is a Matlab writer for NRRD image files here:

If you want to run Matlab code directly from Slicer, then you can use the MatlabBridge extension.

1 Like

Thank you Andras,
Is it possible to give pixel spacing information too? Where should I put that information?

img.ijkToLpsTransform transform specifies IJK voxel coordinates to LPS anatomical coordinates transform. Pixel spacing is the norm of the columns of the top-left 3x3 submatrix. If volume is axis-aligned then spacing values are in the diagonal of the top-left 3x3 submatrix.

1 Like

I have a 2D matrix and I wanna make it to nrrd but this function doesnt work.
The reason that I want to change it to nrrd is I want enforce the module that I’ve written on Slicer on this matrix.

I’ve just tested the nrrwrite.m script and it works perfectly for 2D images. For example:

a=eye(30)
img.pixelData=a
nrrdwrite("c:/tmp/test.nrrd", img)

Creates an image like this:

NRRD0005
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: double
space: left-posterior-superior
dimension: 3 
sizes: 30  30   1
space directions: (1,0,0) (0,1,0) (0,0,1)
kinds: domain domain domain
endian: little
encoding: raw
...

It gets loaded into Slicer correctly:

image

Note that others may have created scripts called nrrdwrite.m and nrrdread.m and those scripts may or may not work correctly. Make sure you use the scripts that we developed and made available in the Slicer Matlab Bridge repository.