Get inidces for specific conditions from binary mask

1 回表示 (過去 30 日間)
PA
PA 2021 年 10 月 31 日
コメント済み: PA 2021 年 11 月 1 日
Dear MATLAB-Community,
I have a binary mask M (attached).
I would like to get the indices that match the following condition: Find all "1" that have at least one "0" as a neighboring entry.
I have tried a lot the last days but did not find a solution. It would be great if someone could help me with that.
Best regards!

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 31 日
NC = conv2(M, [1 1 1; 1 0 1; 1 1 1], 'same');
mask = M & (NC < 8);
%now you can find() on mask
  1 件のコメント
PA
PA 2021 年 11 月 1 日
Thank you very much for your help, this worked just fine!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 10 月 31 日
There is a built-in function for this in the Image Processing Toolbox. It's called bwperim(). Full demo:
s = load('m.mat')
M = s.M;
subplot(2, 1, 1);
imshow(M, [])
axis('on', 'image')
% Find all 1 that have a zero as a neighbor.
% We can use bwperim() for this
perimImage = bwperim(M);
subplot(2, 1, 2);
imshow(perimImage, [])
axis('on', 'image')
  1 件のコメント
PA
PA 2021 年 11 月 1 日
Thank you very much for your help, this worked just fine!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAuthor Block Masks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by