MATLAB Answers

Obtaining 3D matrix /image from voxel array with co-ordinates X,Y and Z with the intensity ?

1 view (last 30 days)
Jabir Mohamed Abdi
Jabir Mohamed Abdi on 27 Jul 2021
I have a voxel array of size 4089906 X 4 and I want to change it to 3D image/matrix and its size should be based on the co-ordinates X,Y and Z of the voxel array. In the diagram 1=X co-ordinate 2=Y co-ordinate 3=Z- co-ordinate and 4= Intensity. The ranges for the co-ordinates are X=[-550:1:300] Y= [-1350:1:-550] and Z= [2080:8:2120]

Answers (1)

Image Analyst
Image Analyst on 28 Jul 2021
I know it's kind of obvious, but did you try a nested for loop?
x = squeeze(n(:, 1));
y = squeeze(n(:, 2));
z = squeeze(n(:, 3));
gl = squeeze(n(:, 4));
xMin = min(x);
xMax = max(x);
yMin = min(y);
yMax = max(y);
zMin = min(z);
zMax = max(z);
[rows, columns] = size(n)
outputRows = yMax - yMin;
outputCols = xMax - xMin;
outputSlices = zMax - zMin;
outputImage = zeros(outputRows, outputCols, outputSlices);
for k = 1 : rows
col = x(k) + xMin;
row = y(k) + yMin;
slice = z(k) + zMin;
outputImage(row, col, slice) = gl(k);
end
  1 Comment
Jabir Mohamed Abdi
Jabir Mohamed Abdi on 28 Jul 2021
I tried my version of nested loop but didnt work. Your way of the nested loop works and thank you for your assistance!.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by