How to downsample the 3D matrix in matlab??

Due to computational limitations, I need to downsample the 3D (1500x1500x1700) matrix by a factor of 2. The binning process should merg the 2x2x2 voxels and assign the mean intensity value of the group to the corresponding voxel in the reduced image.

 Respuesta aceptada

Jan
Jan el 24 de Jul. de 2022
X = rand(1500, 1500, 1700); % 28.5 GB - does not run in the forum!
Y = reshape(X, 2, 750, 2, 750, 2, 850);
Z = squeeze(sum(Y, [1,3,5])) / 8;
size(Z)

4 comentarios

Rizwan Khan
Rizwan Khan el 24 de Jul. de 2022
thanks Jan for your quick reply. I am getting an error if the dimension is odd.
One of my matrix is 1212x1212x1561 and the error is: "Size arguments must be real integers"
Jan
Jan el 25 de Jul. de 2022
Editada: Jan el 25 de Jul. de 2022
@Rizwan Khan: What do you wnt to do, if the dimension is odd? Omit the last vector or include it in the output without averaging? I cannot guess, what you need.
X = rand(1501, 1501, 1701);
s = size(X);
s = s - rem(s, 2);
XX = X(1:s(1), 1:s(2), 1:s(3)); % Crop, Needs a lot of memory...
Y = reshape(X, 2, s(1) / 2, 2, s(2) / 2, 2, s(3) / 2);
Z = squeeze(sum(Y, [1,3,5])) / 8;
Rizwan Khan
Rizwan Khan el 25 de Jul. de 2022
Yes, I omitted the last vector before downsampling.
thanks Jan
Kristoffer Walker
Kristoffer Walker el 6 de Jul. de 2024
Brilliant Jan. Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 24 de Jul. de 2022

Comentada:

el 6 de Jul. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by