How to connect non-continuous boundary and fill the object in binary image

6 ビュー (過去 30 日間)
AniCnx
AniCnx 2019 年 3 月 1 日
コメント済み: AniCnx 2019 年 3 月 2 日
I have a binary image that contains the boundary of the object. The plots of boundary are not continuous, how can I connect those points? Moreover, how can I fill value in this object?
m.png

採用された回答

KSSV
KSSV 2019 年 3 月 1 日
編集済み: KSSV 2019 年 3 月 1 日
An vague attempt....it can be further refined or a more legant solution would be possible.
I = imread('m.png') ;
I1 = rgb2gray(I) ;
I1 = imcrop(I1) ;
[y,x] = find(I1) ;
imshow(I1) ;
hold on
% plot(x,y,'.r')
[nx,ny] = size(I1) ;
P1 = [x(x<=nx/2) y(x<=nx/2)] ;
P2 = [x(x>nx/2) y(x>nx/2)] ;
P = P1'; % coordinates / points
c = mean(P,2); % mean/ central point
d = P-c ; % vectors connecting the central point and the given points
th = atan2(d(2,:),d(1,:)); % angle above x axis
[th, idx] = sort(th); % sorting the angles
P = P(:,idx); % sorting the given points
P = [P P(:,1)]; % add the first at the end to close the polygon
plot( P(1,:), P(2,:), 'r');
P = P2'; % coordinates / points
c = mean(P,2); % mean/ central point
d = P-c ; % vectors connecting the central point and the given points
th = atan2(d(2,:),d(1,:)); % angle above x axis
[th, idx] = sort(th); % sorting the angles
P = P(:,idx); % sorting the given points
P = [P P(:,1)]; % add the first at the end to close the polygon
plot( P(1,:), P(2,:), 'b');
  3 件のコメント
KSSV
KSSV 2019 年 3 月 1 日
YOu need not to use boundary.......edited the code.
AniCnx
AniCnx 2019 年 3 月 2 日
Thank you very much. I sorted it out.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePoint Cloud Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by