フィルターのクリア

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 Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by