Switching elements in 3D image(xy) dataset to export yz and xz images
2 views (last 30 days)
Show older comments
I am working on (x*y)*z (eg. 300x300x300 pixel) binary image data set that gets imported as a multidimentional array.
For directional open porosity calculation I need to export YZ and XZ images for further calculation
A rough example on the layout(the numbers here would be 0 or 1 in actual data):
M(:,:,1) = [1 2 3; 4 5 6; 7 8 9];
M(:,:,2) = [10 11 12; 13 14 15; 16 17 18];
M(:,:,3) = [19 20 21; 22 23 24; 25 26 27];
for t1=1:size(M,3)
for i1=1:size(M,3)
YZ(i1,:,:)=M(:,:,i1);
end
end
for t2=1:size(M,3)
for i2=1:size(M,3)
XZ(:,t2,:)=M(i2,t2,:);
end
end
This produces the images in the YZ.
YZ(:,:,1) = [1 4 7; 10 13 16; 19 22 25];
YZ(:,:,2) = [2 5 8; 11 14 17; 20 23 26];
YZ(:,:,3) = [3 6 9; 12 15 18; 21 24 27];
I am facing the problem in the XZ planes, the last section produces only the required first page of the multidimentional array
the current output is
7 8 9
16 17 18
25 26 27
The required outout would be something like
XZ(:,:,1) = [7 8 9; 16 17 18; 25 26 27];
XZ(:,:,2) = [4 5 6; 13 14 15; 22 23 24];
XZ(:,:,3) = [1 2 3; 10 11 12; 19 20 21];
or the reverse
XZ(:,:,1) = [1 2 3; 10 11 12; 19 20 21];
XZ(:,:,2) = [4 5 6; 13 14 15; 22 23 24];
XZ(:,:,3) = [7 8 9; 16 17 18; 25 26 27];
I saw this question https://nl.mathworks.com/matlabcentral/answers/302683-switch-elements-of-the-2nd-and-3d-dimension-in-3d-matrix
But in my case permute() is not generating the required layout.
Any info would be really helpful!
0 Comments
Answers (1)
Aditya
on 20 Jan 2025
Edited: Aditya
on 20 Jan 2025
Hi Ujjwal,
To extract the 'YZ' and 'XZ' planes from your 3D matrix 'M', you can use the 'permute' function as follows:
% For YZ plane
YZ = permute(M, [3, 1, 2]);
% For XZ plane
XZ = permute(M, [3, 2, 1]);
This will give you the correct layouts for your directional porosity calculations. If the order isn't as expected, you might need to use `flip` to adjust it.
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!