How can I separate objects with one pixel connected after bwlabel

2 ビュー (過去 30 日間)
Zuhui Wang
Zuhui Wang 2022 年 4 月 22 日
コメント済み: Matt J 2022 年 4 月 23 日
Hi,
I am using bwlabel to label the objects with defined connectivity after edge detection algorithm. But sometimes I encountered the objects are connected with only one pixel. How could I efficiently separate them?
Below is one example of a binary image I want to detect objects. I chose connectivity 4 to detect the objects when using bwlabel
obj_label = bwlabel(BW, 4);
Actually these two are seperate objects that I want, but the one pixel between make them difficult to label when using bwlabel.
Appriciate a lot if any suggestions are provided.

採用された回答

DGM
DGM 2022 年 4 月 22 日
Depending on what the rest of the blobs look like, this may be one way.
% fix the image and return it to what I assume the original size was
[A,map,~] = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/974265/image.png');
A = rgb2gray(ind2rgb(A,map))>0.5;
A = imresize(A,[30 30],'nearest');
imshow(A)
% remove foreground pixels which have at least two
% unconnected BG pixels in their 8-neighborhood
B = ~bwmorph(~A,'bridge');
imshow(B)
  1 件のコメント
Zuhui Wang
Zuhui Wang 2022 年 4 月 23 日
Thank you DGM, that's a very nice solution for this problem. Good to learn how to use bwmorph :D

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

その他の回答 (2 件)

Matt J
Matt J 2022 年 4 月 23 日
load BW
L=watershed(-bwdist(~BW));
BW=BW&L~=0;
imshow(BW)
  1 件のコメント
Zuhui Wang
Zuhui Wang 2022 年 4 月 23 日
Thanks Matt, watershed is also working well in this situation.

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


Image Analyst
Image Analyst 2022 年 4 月 23 日
  2 件のコメント
Zuhui Wang
Zuhui Wang 2022 年 4 月 23 日
Thanks! Will check them out.
Matt J
Matt J 2022 年 4 月 23 日
Seems hard to find a strel that will make imopen work well here.

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by