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

2 visualizzazioni (ultimi 30 giorni)
%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;

Risposte (1)

KSSV
KSSV il 26 Giu 2018
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')

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by