Working with 3d matrices

6 visualizaciones (últimos 30 días)
Geva Tal
Geva Tal el 5 de Mayo de 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?

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 5 de Mayo de 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 comentario
Geva Tal
Geva Tal el 5 de Mayo de 2011
Works great, thanks alot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by