Extensions/MatlabBridge: Send transform (4x4 matrix) from Matlab to 3D Slicer

Probably the simplest is to revert all your changes in the .xml and .m file and just modify these lines in your .m file:

img.pixelData = some3DArray;
img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];

thank you very much.
so just to understand it correctly: I use not theis part anymore:

img=cli_imageread(inputParams.inputvolume);

outputParams.min=min(min(min(img.pixelData)));
outputParams.max=max(max(max(img.pixelData)));

img.pixelData=(double(img.pixelData)>inputParams.threshold)*100;

cli_imagewrite(inputParams.outputvolume, img);

instead I just add:

img.pixelData = some3DArray;
img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];

and leave the XML file like it is.

I really appreciate your effort. it is so important for me

cli_imageread reads data from Slicer. If your image is taken from a different source then this part is not needed.

cli_imagewrite writes the volume so that Slicer can read it, so that is still needed.

You have to take care of replacing some3DArray with actual data that you get from somewhere.

ok thanks I will try it out.
The xml-file i dont change at all?

Dear Mr. Lasso,
I was running the following code:

load ‘matrixfilteredvolume.mat’

Matrix = FilteredVolume

cli_imagewrite(inputParams.Matrix)

img.pixelData = Matrix;
img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];

cli_imagewrite(onputParams.Matrix, img)

and I´m getting the error:
Not enough input arguments
error in: cli_imagewrite(inputParams.Matrix)

Which kind of inputParams I should change or which parameters are actually missing?

Thank you so much for your help!

Dear Mr. Lasso,
I was thinking over my code again and came to the following conclusion, which I took from your poster:

http://perk.cs.queensu.ca/sites/perkd7.cs.queensu.ca/files/Lasso2014b-poster.pdf

I tried to adjust all the parameter and tried to run this code:

load(‘matrixfilteredvolume.mat’)

Volume = (FilteredVolume)

Matrixin=cli_imagewrite(inputParams.Volume);

img.pixelData = Matrixin;
img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];

outputvol = Matrixin

cli_imagewrite(inputParams.outputvolume, outputvol);

image

I would be very pleased about any suggestions!

PS: Error Not enough input arguments in line:

Matrixin=cli_imagewrite(inputParams.Volume);

after looking over the whole discussion, I’m coming to this conclusion:

matlab code:

load(‘matrixfilteredvolume.mat’);

img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];

img.pixelData=FilteredVolume

cli_imagewrite(img.ijkToLpsTransform.FilteredVolume, img);


it seems to be the right path but I still got one error to solve:

img =

struct with fields:

ijkToLpsTransform: [4×4 double]
        pixelData: [181×299×305 double]

Struct contents reference from a non-struct array object.

Error in afterMoritz (line 19)
cli_imagewrite(img.ijkToLpsTransform.FilteredVolume, img);

I am thankful for all kind of suggestions!

There is no such thing as img.ijkToLpsTransform.FilteredVolume. Follow the working example more closely. Something like this should work:

cli_imagewrite(inputParams.outputvolume, img);

Thanks a lot Sir for your reply! I did now everything which you said:

load(‘matrixfilteredvolume.mat’); #loading of matrix

img.pixelData = FilteredVolume #using the codes you suggested

outputParams.min=min(min(min(img.pixelData))); #following the working example more closely
outputParams.max=max(max(max(img.pixelData)));

img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];

cli_imagewrite(inputParams.outputvolume, img); #use the cli_imagewrite code to import the data like you said in the last post

Still I seem to miss something out, since the error appears:

Not enough input arguments.

Error in matrixvolumeto3dslicer (line 23)
cli_imagewrite(inputParams.outputvolume, img);

I really appreciate your effort and am very thankful for your suggestions.

Modifying an example script to use your data instead of similar sample data should be a site straightforward Matlab programming task. You should be able to find a solution by reflecting on the error message, experimenting, Google searching, or asking someone in your group to sit down with you and go through your code.

If you are just starting to learn Matlab, then I would recommend to consider learning Python instead, as most likely you’ll benefit from that more in the long term.

2 Likes