Working with 3d matrices
조회 수: 12 (최근 30일)
이전 댓글 표시
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
채택된 답변
Sean de Wolski
2011년 5월 5일
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!