How to bring the (non-struct array object) pixel data into the right format?

1 view (last 30 days)
I am trying to bring an image volume (181x299x305 double (=FilteredVolume)) from Matlab to the 3D Slicer (with the MatlabBridge Extension). The size of the voxels are [0.0500 0.0500 0.0500]. The number of slides from which the volume was created are 181.
I have used the 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);
--------------------
But now I get the Error:
img =
struct with fields:
ijkToLpsTransform: [4×4 double]
pixelData: [181×299×305 double]
Struct contents reference from a non-struct array object.
Error in (line 19)
cli_imagewrite(img.ijkToLpsTransform.FilteredVolume, img);
Can anybody help me how I should change the structure contents of my matrix to make this code work?
I am working on it quit a long time, so I would be very pleased about any suggestions!

Answers (2)

Walter Roberson
Walter Roberson on 16 Jun 2018
You construct
img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1]
so img.ijkToLpsTransform is a numeric vector.
But then you try
cli_imagewrite(img.ijkToLpsTransform.FilteredVolume, img);
implying that you think img.ijkToLpsTransform is a struct.
Perhaps you wanted
cli_imagewrite(img.FilteredVolume, img);
  10 Comments
Guillaume
Guillaume on 16 Jun 2018
At this point, it's probably easier if you attach to your question the unmodified m file that you're supposed to edit.

Sign in to comment.


Image Analyst
Image Analyst on 16 Jun 2018
Try this:
load('matrixfilteredvolume.mat');
% "img" has now been poofed into memory.
img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];
% Assign the pixelFata field to FilteredVolume.
% We KNOW that FilteredVolume already exists because you got past this line.
img.pixelData=FilteredVolume
% Now write out FilteredVolume:
cli_imagewrite(FilteredVolume, img);
I'm not really sure what your function cli_imagewrite() does since you didn't include it but presumably it wants something like FilteredVolume as the first argument and a structure as the second argument.
  9 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!