How to bring the (non-struct array object) pixel data into the right format?
Mostra commenti meno recenti
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!
Risposte (2)
Walter Roberson
il 16 Giu 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 Commenti
Katharina Hecker
il 16 Giu 2018
Katharina Hecker
il 16 Giu 2018
Walter Roberson
il 16 Giu 2018
cli_imagewrite(img.pixelData, img);
Guillaume
il 16 Giu 2018
yes I tried that as well,the problem is that you have than the error:
undefined fuction of the variable: 'cli_imagewrite'.
This is I guess because of the original generated functional structure, which is developed by the 3D Slicer: cli_imagewrite(inputParams.outputvolume, img);
The 3D Slicer generates for you automatically three documents: - .m file - .xml file and - .bat file
with a raw code structure which you have to change to load your data inside the software. In my case you have to change the .m file to bring the mentioned volume from Matlab to the 3D Slicer. If anyone has an idea how to solve this error of the variable 'cli_imagewrite' I would be really thankful!!!
Katharina Hecker
il 16 Giu 2018
Guillaume
il 16 Giu 2018
undefined fuction or variable xxx
From your code, it is clear that cli_imagewrite is not a variable. It is a function. You get the error because the m file where it is defined ( cli_imagewrite.m) is not on matlab path. It has nothing to do with the inputs or how you generate them.
Maybe you changed the current folder, maybe you didn't install properly whichever toolbox you're using, maybe you mistyped the function name, ....
Struct contents reference from a non-struct array object
Look, it's simple. If you create
a.b.c = ...
a is a structure with field b, that field itself is a structure with field c. If you've never created field d, then when you do
dosomething(a.b.d)
then you're going to get the error reference to non-existant field d as you got earlier and if you do
a.b = [1 2 3]
then b is not a structure anymore and
dosomething(a.b.d)
is then going to error with struct contents reference from a non-struct array since b is not a structure.
Therefore in your case either transf or transf.img is not a structure.
Katharina Hecker
il 16 Giu 2018
Guillaume
il 16 Giu 2018
At this point, it's probably easier if you attach to your question the unmodified m file that you're supposed to edit.
Katharina Hecker
il 16 Giu 2018
Image Analyst
il 16 Giu 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 Commenti
Katharina Hecker
il 16 Giu 2018
Image Analyst
il 16 Giu 2018
How can we possibly know how to fix it when you're not sharing the cli_imagewrite() function with us? http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Since you're not sharing that, I guess you're on your own. Happy to look at it if you want to give us the code....
Katharina Hecker
il 16 Giu 2018
Image Analyst
il 16 Giu 2018
Everything you attached in your other comment for cli_imagewrite is just comments - there is no actual code there, and it's not clear to me from the comments what it's expecting. Apparently it might be able to take a lot of different things, but seeing the actual code, rather than just the comments, might help.
Katharina Hecker
il 16 Giu 2018
Modificato: Walter Roberson
il 16 Giu 2018
Image Analyst
il 16 Giu 2018
The m-file I see in this link does not have any code where "the m file is created", meaning the cli_imagewrite() function m-file is created. In fact, it would be highly unusual for an m-file to create another m-file. I still don't know what type of variables it expects.
Katharina Hecker
il 16 Giu 2018
Modificato: Image Analyst
il 16 Giu 2018
Walter Roberson
il 16 Giu 2018
It appears to me that you need to download https://github.com/PerkLab/SlicerMatlabBridge and make sure that the directories are on your MATLAB path.
Katharina Hecker
il 16 Giu 2018
Categorie
Scopri di più su Convert Image Type in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!