Working with 3d matrices
6 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Sean de Wolski
on 5 May 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)
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!