how to draw a circle with radius as maximum distance from centroid to border points

2 ビュー (過去 30 日間)
sreerag kanhangad
sreerag kanhangad 2018 年 6 月 26 日
編集済み: sreerag kanhangad 2018 年 6 月 26 日
%extract border
im=imread('2.jpg');
bord=rgb2gray(im);
bord1=imbinarize(bord);
S= strel('disk',2,0);
bord1=imopen(bord1,S);
BW3=imerode(bord1,S);
bord=bord1-BW3;
BW2=imfill(bord,'holes');
s=strel('disk',3,0);
BW2=bwmorph(BW2,'remove');
F=imerode(BW2,s);
bord2=BW2-F;
%calculation of centroid
st = regionprops(bord2, 'BoundingBox','Centroid');
xc=st(1).Centroid(1);
yc=st(1).Centroid(2);
c=1;
%calculation of euclidean distance to each border points
for ii=1:size(bord2,1)
for jj=1:size(bord2,2)
pixel(ii,jj)=bord2(ii,jj);
if(pixel(ii,jj)==1)
X = [xc yc;ii jj];
r1(c) = pdist(X,'euclidean');
c=c+1;
end
end
end
rd=max(r1);%maximum distance to centroid from the border point
axes(handles.axes1);
hold on;
centers=[xc,yc];
disp(rd);
imshow(pixel);
plot(st(1).Centroid(1),st(1).Centroid(2),'r.');
plot(rd,'b*');
viscircles(centers,rd);%cirlce with radius as maximum distance from center
hold off;

回答 (1 件)

KSSV
KSSV 2018 年 6 月 26 日
I = imread('peppers.png') ;
[nx,ny,d] = size(I) ;
C = round([ny,nx]/2) ; % center of circle
R = min([ny-C(1),nx-C(2)]) ;
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
imshow(I)
hold on
plot(C(1),C(2),'*r')
plot(xc,yc,'b')

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by