wrong dimensions on a 3D array

4 次查看(过去 30 天)
Hi, I am new to MATLAB
I have been given a file with 72 images that are 51*51 that opens in matlab as a 72*51*51 3D matrix, however I can't seem to index out the individual images.
I would like to be able to isolate each of the images so I can multiply them element wise with another 51*51 filter matrix I made but the way I am doing it gives me an image that is the wrong size to multiply.
thanks

采纳的回答

Walter Roberson
Walter Roberson 2020-11-29
%the below needs R2020b or later
re_arranged = permute(Matrix, [2 3 1]);
filtered = pagetimes(re_arranged, filter_matrix);
The result will be 51 x 51 x 72.
For earlier releases, there is a File Exchange contribution to do page-wise multiplication. Or you can loop:
re_arranged = permute(Matrix, [2 3 1]);
filtered = zeros(size(re_arranged));
for P = 1 : size(re_arranged,3)
filtered(:,:,P) = pagetimes(re_arranged(:,:,P), filter_matrix);
end
The permute is not strictly necessary. You could skip it and use
filtered = zeros(size(Matrix));
n = size(Matrix,2);
for P = 1 : size(Matrix,1)
filtered(P, :, :) = reshape( reshape(Matrix(P,:,:), [n, n]) * filter_matrix, [1, n, n]);
end
The output would be 72 x 51 x 51

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by