image thumbnail

CIRCLE FIT IN HEART SHAPE

by

 

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

HT_SHADOW_READ(fnme)
function HT_SHADOW_READ(fnme)
close all
hold on
axis equal
%Image reading
im=imread(fnme);
%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);

l_wng_rad=drvmaxrad(225,pnt);
[l_wng_rad_x,l_wng_rad_y]=bcircle(l_wng_rad(1),l_wng_rad(2),l_wng_rad(3));
plot(l_wng_rad_x,l_wng_rad_y,'g-')

r_wng_rad=drvmaxrad(315,pnt);
[r_wng_rad_x,r_wng_rad_y]=bcircle(r_wng_rad(1),r_wng_rad(2),r_wng_rad(3));
plot(r_wng_rad_x,r_wng_rad_y,'g-')

l_lob_rad=drvminrad(135,pnt);
[l_lob_rad_x,l_lob_rad_y]=bcircle(l_lob_rad(1),l_lob_rad(2),l_lob_rad(3));
plot(l_lob_rad_x,l_lob_rad_y,'g-')

r_lob_rad=drvminrad(45,pnt);
[r_lob_rad_x,r_lob_rad_y]=bcircle(r_lob_rad(1),r_lob_rad(2),r_lob_rad(3));
plot(r_lob_rad_x,r_lob_rad_y,'g-')

end

function it2=drvmaxrad(ang,pnt)
%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

function it2=drvminrad(ang,pnt)
%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

Contact us