Indexing a 3d matrix with a 2D matrix

조회 수: 1 (최근 30일)
Kalen
Kalen 2016년 8월 20일
답변: Walter Roberson 2016년 8월 20일
I have a logical mask of locations I want to image. I am using bwconncomp to get the indices of the pixels in each of these objects. What I can't figure out is how to take this information and pull out the 3 dimensional vector for each of these pixels from my larger 3d matrix. I thought I could use ind2sub to convert the pixel locations then do something like the following, but this did not work.
I can solve this with a for loop and just loop through each plane of my 3d matrix, but there must be a more elegant solution out there. Thanks for any advice.
[pixelSubs(:,1),pixelSubs(:,2)]=ind2sub(cc.PixelIdList{objectNum});
threeDVectors=threeDMatrix(pixelSubs(:,1),pixelSubs(:,2),:);

답변 (1개)

Walter Roberson
Walter Roberson 2016년 8월 20일
idx = cc.PixelIdList{objectNum};
pane_size = size(threeDMatrix,1) * size(threeDMatrix,2);
threeDVectors(:,1) = ThreeDMatrix(idx);
threeDVectors(:,2) = ThreeDMatrix(idx + pane_size);
threeDVectors(:,3) = ThreeDMatrix(idx + 2 * pane_size);

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by