Code covered by the BSD License

# CIRCLE FIT IN HEART SHAPE

It fits all four circle in Heart Shape Which gives Radius and Center for each

```function HT_SHADOW_READ(fnme)
close all
hold on
axis equal
%Converting to Binary to threshold noise
im=im2bw(im);
%imshow(im)
%Edge detection
BW = edge(im,'canny');
%figure, imshow(BW)

%Finding edge index
[re,ce]=find(BW==1);
ce=ce-round((max(ce)-min(ce))/2);
re=re-round((max(re)-min(re))/2);
pnt=[ce,re];
plot(ce,re,'.');
pnt=stlazimuth(pnt);

end

%Maximum Circle finding itteretion
%Coarse itteretion

i=1;
for wr1=20:5:50
if ang==360
m1=pnt(or(pnt(:,3)<wr1,pnt(:,3)>ang-wr1),1:2);
else
m1=pnt(and(pnt(:,3)>ang-wr1,pnt(:,3)<ang+wr1),1:2);
end
para(i,1:3)=CircleFitT(m1);
para(i,4)=wr1;

%     plot(m1(:,1),m1(:,2),'go')
%     [xm1,ym1]=bcircle(para(i,1),para(i,2),para(i,3));
%     plot(xm1,ym1,'g-')

i=i+1;

end
[v,ind]=max(para(:,3),[],1);
it1=para(ind,:);
para(ind,:)=[];
i=i-1;
%Fine itteretion
for wr1=it1(1,4)-4:1:it1(1,4)+4
if ang==360
m1=pnt(or(pnt(:,3)<wr1,pnt(:,3)>ang-wr1),1:2);
else
m1=pnt(and(pnt(:,3)>ang-wr1,pnt(:,3)<ang+wr1),1:2);
end
para(i,1:3)=CircleFitT(m1);
para(i,4)=wr1;

%plot(m1(:,1),m1(:,2),'go')
%[xm1,ym1]=bcircle(para(i,1),para(i,2),para(i,3));
%plot(xm1,ym1,'g-')
i=i+1;
end
para=sortrows(para,4);
[v,ind]=max(para(:,3),[],1);
it2=para(ind,:);
end

%Minimum Circle finding itteretion
%Coarse itteretion

i=1;
for wr1=20:5:50
if ang==360
m1=pnt(or(pnt(:,3)<wr1,pnt(:,3)>ang-wr1),1:2);
else
m1=pnt(and(pnt(:,3)>ang-wr1,pnt(:,3)<ang+wr1),1:2);
end
para(i,1:3)=CircleFitT(m1);
para(i,4)=wr1;

%     plot(m1(:,1),m1(:,2),'go')
%     [xm1,ym1]=bcircle(para(i,1),para(i,2),para(i,3));
%     plot(xm1,ym1,'g-')

i=i+1;

end
[v,ind]=min(para(:,3),[],1);
it1=para(ind,:);
para(ind,:)=[];
i=i-1;
%Fine itteretion
for wr1=it1(1,4)-4:1:it1(1,4)+4
if ang==360
m1=pnt(or(pnt(:,3)<wr1,pnt(:,3)>ang-wr1),1:2);
else
m1=pnt(and(pnt(:,3)>ang-wr1,pnt(:,3)<ang+wr1),1:2);
end
para(i,1:3)=CircleFitT(m1);
para(i,4)=wr1;

%plot(m1(:,1),m1(:,2),'go')
%[xm1,ym1]=bcircle(para(i,1),para(i,2),para(i,3));
%plot(xm1,ym1,'g-')
i=i+1;
end
para=sortrows(para,4);
[v,ind]=min(para(:,3),[],1);
it2=para(ind,:);
end```