wrong dimensions on a 3D array

4 visualizzazioni (ultimi 30 giorni)
cameron lord
cameron lord il 29 Nov 2020
Commentato: cameron lord il 30 Nov 2020
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

Risposta accettata

Walter Roberson
Walter Roberson il 29 Nov 2020
%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

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by