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!
回答 (2 件)
Walter Roberson
2018 年 6 月 16 日
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 件のコメント
Katharina Hecker
2018 年 6 月 16 日
Katharina Hecker
2018 年 6 月 16 日
Walter Roberson
2018 年 6 月 16 日
cli_imagewrite(img.pixelData, img);
Guillaume
2018 年 6 月 16 日
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
2018 年 6 月 16 日
Guillaume
2018 年 6 月 16 日
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
2018 年 6 月 16 日
Guillaume
2018 年 6 月 16 日
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
2018 年 6 月 16 日
Image Analyst
2018 年 6 月 16 日
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 件のコメント
Katharina Hecker
2018 年 6 月 16 日
Image Analyst
2018 年 6 月 16 日
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
2018 年 6 月 16 日
Image Analyst
2018 年 6 月 16 日
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
2018 年 6 月 16 日
編集済み: Walter Roberson
2018 年 6 月 16 日
Image Analyst
2018 年 6 月 16 日
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
2018 年 6 月 16 日
編集済み: Image Analyst
2018 年 6 月 16 日
Walter Roberson
2018 年 6 月 16 日
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
2018 年 6 月 16 日
カテゴリ
ヘルプ センター および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!