필터 지우기
필터 지우기

How can I index Image pixel with 2d logical mtrix ?

조회 수: 9 (최근 30일)
MINHOON KIM
MINHOON KIM 2020년 10월 21일
답변: Walter Roberson 2020년 10월 22일
I want to index image with 2d matrix logical indexing data.
I attaced the file please help me...
  댓글 수: 1
Akira Agata
Akira Agata 2020년 10월 22일
What do you mean by "index image" with 2d logical matrix?
Is that something like this?
imshowpair(BEV,Red_idx)

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 10월 22일
output = BEV(Red_idx);
is valid MATLAB, and gives a 64x1 vector.
When you index an array by a smaller logical vector, the missing entries are assumed to be false (not selected), so it is valid MATLAB to index a 3D array by a 2D logical array, and the result would be the same as indexing the first pane of the 3D array by the 2D logical array.
If you have a hard requirement to not use more than two dimensions in the logical array index, and you want to get all three of the image panes, then you will need to do something like
temp = BEV(:,:,1);
output(:,1) = temp(Red_idx);
temp = BEV(:,:,2);
output(:,2) = temp(Red_idx);
temp = BEV(:,:,3);
output(:,3) = temp(Red_idx);
but I would recommend that you instead give up indexing with a 2D logical array and make it a 3D logical array instead:
output = reshape(BEV(repmat(Red_idx,1,1,3)), [], 3);
It would not be common that you would want to do this kind of indexing. More common by far would be:
output = BEV.*repmat(uint8(Red_idx),1,1,3);
which would create an RGB array the same size as BEV but with the pixels not selected set to black.
Also common would be to crop out the section corresponding to the selected pixels, such as
mask = any(Red_idx,1);
fc = find(mask,1);
lc = find(mask,1,'last');
mask = any(Red_idx,2);
fr = find(mask,1);
lr = find(mask,1,'last');
output = BEV(fr:lr, fc:lc, :);

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by