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

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)

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

Thanks a lot, but I get from this then the error: Reference to non-existent field 'FilteredVolume'.
I think it can't recognize from this the volume, because it doesn't connect with the matrices...
Katharina Hecker's comment mistakenly posted as an answer moved here:
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!!!
The following code which I was working on gives me the same error from the beginning:
load('matrixfilteredvolume.mat');
img.ijkToLpsTransform = [ 0.05 0 0 0; 0 0.05 0 0; 0 0 0.05 0; 0 0 0 1];
transf = img.ijkToLpsTransform
img.pixelData=FilteredVolume
cli_imagewrite(transf.img.pixelData, img);
Struct contents reference from a non-struct array object.
Error in afterMoritz (line 21) cli_imagewrite(transf.img.pixelData, img);
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.
i follow your example but I must admit that I don't know how to address the 'inputparams' to bypass the overwriting and still put enough arguments... Would it be possible to explain it to me according to my example? Thanks for your understanding!
At this point, it's probably easier if you attach to your question the unmodified m file that you're supposed to edit.

Accedi per commentare.

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

Thanks for your input, but this suggestion I already tried. It can't use the functioncli_imagewrite... I think it is because of the problem with the input parameters (inputparams). I don't know how to adress them correctly
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....
to be more specific: the unmodified m file has the line: cli_imagewrite(inputParams.outputvolume, img); -> which is causing the problem it has to be adjusted to my volume, but I could not find the correct inputParams or rather had too less input arguments... I hope now my problem is explained more clearly
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.
the m file is created from the 3D Slicer like I attached it above. The code which has to be changed accordingly to load matrices inside the Slicer is this one (raw type like in the file above):
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);
I tried to figure out how to change it to not create a module but to actually load data inside the slicer.
Therefore the first line is not needed
img=cli_imageread(inputParams.inputvolume);
the information which is needed is shown as followed:
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
and the function:
cli_imagewrite(inputParams.outputvolume, img);
which has to adjusted according to my data,
Unfortunately that is all I know.
As I said: I could not find the correct inputParams or rather had too less input arguments...
Thanks for your help and understanding!
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.
The m file which I attached is created by the software '3D Slicer'by using the Module 'Matlab Module Generator' so I can't see how the m file which I attached is created.
I just have an additional .bat file, which is also created automatically with the 'Matlab Module Generator', and an xml file, which contains after creation this information:
<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Matlab</category>
<title>matrixvolumeto3dslicer</title>
<description><![CDATA[Perform a simple image processing and image statistics computation in Matlab.]]></description>
<version>0.0.0.1</version>
<documentation-url>http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/MatlabBridge</documentation-url>
<license/>
<contributor>Andras Lasso (PerkLab)</contributor>
<acknowledgements><![CDATA[SparKit is a project funded by Cancer Care Ontarioand the Ontario Consortium for Adaptive Interventions in Radiation Oncology (OCAIRO) to provide free, open-source toolset for radiotherapy and related image-guided interventions.]]></acknowledgements>
<parameters>
<label>Processing Parameters</label>
<description><![CDATA[Parameters for the processing]]></description>
<integer>
<label>Threshold</label>
<description><![CDATA[All voxels below this value will be set to zero]]></description>
<longflag>threshold</longflag>
<default>50</default>
<constraints>
<minimum>-2000</minimum>
<maximum>5000</maximum>
<step>5</step>
</constraints>
</integer>
</parameters>
<parameters>
<label>IO</label>
<description><![CDATA[Input/output parameters]]></description>
<image>
<label>Input Volume</label>
<description><![CDATA[Input volume to be filtered]]></description>
<longflag>inputvolume</longflag>
<channel>input</channel>
</image>
<image>
<label>Output Volume</label>
<description><![CDATA[Output filtered]]></description>
<longflag>outputvolume</longflag>
<channel>output</channel>
</image>
</parameters>
<parameters>
<label>Output</label>
<description>Matlab command output</description>
<double>
<label>Minimum</label>
<description><![CDATA[Image mininum]]></description>
<name>min</name>
<channel>output</channel>
<default></default>
</double>
<double>
<label>Maximum</label>
<description><![CDATA[Image maximum]]></description>
<name>max</name>
<channel>output</channel>
<default></default>
</double>
</parameters>
</executable>
---------
In the m file there are these lines which have to be adjusted according to your data, to import data or to generate a module which process data inside the slicer. These lines are the following:
function outputParams=newforima(inputParams)
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);
More information I don't have. I appreciate your effort to look over my question and thank you for the help!
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.

Accedi per commentare.

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!

Translated by