stack up 3D images into a 4D matrix

Hello,
I have multiple 3D images and I should stack up these images into a 4D matrix and use it as an input for another code for feature extraction. I have tested this method : cat(4,im1,im2,im3) but it doesn't work well as input. How can I convert these images into 4D matrix ?

9 Kommentare

Rik
Rik am 3 Jul. 2020
What sizes images are you trying to concatenate? If the first 3 dimensions don't match between all images, what should the end result be?
SaHaR
SaHaR am 3 Jul. 2020
all images are : 216x256x10 uint8
Rik
Rik am 3 Jul. 2020
Then the cat function should work as expected. What error did you get?
SaHaR
SaHaR am 3 Jul. 2020
Bearbeitet: SaHaR am 3 Jul. 2020
I didn't get any error when using cat function. But when I gave the result of cat to other code for feature extraction I got an error: ' please make sure you have converted multiple images correctly into a 4D matrix '
I just want to know if there is another approach to convert multiple 3D images into a 4D matrix !
Rik
Rik am 3 Jul. 2020
Since you haven't told us anything about the origin of your data, its meaning, or what assumptions your later code makes, we can't help you.
Your other code has to index it properly of course. Like if you have a 4-D image called image4d, then to extract image #8 from it you should do
this3DImage = image4d(:,:,:,8); % Extract a 3-D image
whos this3DImage % Show dimensions
SaHaR
SaHaR am 3 Jul. 2020
Bearbeitet: SaHaR am 3 Jul. 2020
Thank you for your reply.
In fact, I have multiple images and every image has three ROI (Region of Interest). It's a Cine MRI image of heart and ROIs related to the segmentation of the left ventricle, right ventricle, and myocardium. Also, I have a code for feature extraction which loads each image and its corresponding ROI and then extracts features. But this code is developed for just 1 ROI and for multiple ROIs I should manipulate the code.
I think I should extract separately each ROI as a 3D binary matrix and then load them one by one by the code for feature extraction and then stack them up into a 4D matrix. Something like this ( ROI-vol# is loaded ROI) :
ROIcollection4D = zeros(dxROI-vol,dyROI-vol,dzROI-vol,3,'uint8')
ROIcollection4D(:,:,:,1)=ROI-vol1
ROIcollection4D(:,:,:,2)=ROI-vol2
ROIcollection4D(:,:,:,3)=ROI-vol3
I have understood the concept but since I am a beginner, I don't know how to manipulate the code!
I would appreciate it if you could help me with this problem.
Image Analyst
Image Analyst am 3 Jul. 2020
Looks like it should work as long as vol1, vol2, vol3, and ROI are all 3-D arrays whose lengths match in every dimension.
Note that arrays are not indexed (x,y,z) they are indexed (rows, columns, slices) so the convention is that y, which is rows, comes first, not x as you have it.
(rows, columns, slices) is (y, x, z).
So if you're getting an error, or the images look transposed, check that the order of your dimensions is correct.
SaHaR
SaHaR am 4 Jul. 2020
Thank you.
problem solved :)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Gefragt:

am 3 Jul. 2020

Kommentiert:

am 4 Jul. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by