Working with 3d matrices
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I am trying to sum a group of pixels in an RGB picture represented by heightXwidthX3 matrix. i have a 2d matrix of logical values and im trying to sum those.
exmp in this code: %% Pic = ones(3,3,3); index = logical([1 0 0;0 1 0;0 0 1]); %% %i tried to pull out the wanted pixels like this: pixels = Pic(index,:)
but that didnt work since matlab decides to reshapes the matrix to a vector from 1 to 3*3*3 for some reason. the error i got was: "??? Index exceeds matrix dimensions."
can anyone help me with the right way to do that?
0 Commenti
Risposta accettata
Sean de Wolski
il 5 Mag 2011
Pic = repmat(magic(3),[1 1 3]); %magic square so we can see that it works
index = logical(eye(3)); %example logical index
the_sum = sum(reshape(Pic(repmat(index,[1 1 3])),[],3),2) %sum (example function: note it's called along the 2nd dimension)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating 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!