extracting and filtering images from a 3D matrix?

6 vues (au cours des 30 derniers jours)
Saul Franks
Saul Franks le 8 Nov 2021
Modifié(e) : Dave B le 8 Nov 2021
Hello there, i am a noob to coding/matlab and would appreciate some help.
I have a 3d matrix (72x51x51) composed of 72 images. I am trying to determine a neurons preference for each of the images.
To do this i need to make a for loop that indexes each image from the 3d matrix, reshapes it into a 2d matrix and then performs a matrix multiplication on the image with a gabor filter. I then need to reshape it again into a one D matrix and sum the values of all the elements to recieve the firing rate of the neuron.
I know how to do this manually but cant get the right syntax for automating it into a loop.
Here is my code:
image7 = ms(13006:15606)
TwoDimage7 = reshape(image7,[51 51])
gfimage7 = gaborfilter .* TwoDimage7
OneDgfimage7 = reshape(gfimage7.',1,[])
nfr7 = sum(OneDgfimage7)
thank you.

Réponses (1)

Dave B
Dave B le 8 Nov 2021
Modifié(e) : Dave B le 8 Nov 2021
If you have a 3d matrix, can you do this simpler approach?
[edit: updated for the first dimension being slice/image]
nfr = nan(size(ms, 1), 1);
for i = 1:size(ms, 1)
im = squueze(ms(i,:,:)) % rather than using linear indexing and reshape, just pull the 2d 'slice' out
im_f = gaborfilter .* im; % This copies your syntax, but assumes gaborfilter is the same size as each image...consider imfilter here?
nfr(i) = sum(im_f, 'all'); % No need to reshape to take the grand sum, but you could also do sum(im_f(:)) if you really want to
end

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by