Working with 3d matrices

12 Ansichten (letzte 30 Tage)
Geva Tal
Geva Tal am 5 Mai 2011
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?

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 5 Mai 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)
  1 Kommentar
Geva Tal
Geva Tal am 5 Mai 2011
Works great, thanks alot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by