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

조회 수: 2 (최근 30일)
%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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by