kaki_img=imread('EDGE1.bmp');
figure(2)
imshow(kaki_img)
title('kaki image');
kaki_red=kaki_img(:,:,1);
figure(3)
imshow(kaki_red)
title('kaki red plane');
thresh=graythresh(kaki_red);
kaki_th=imbinarize(kaki_red,thresh);
figure(4)
imshow(kaki_th);
title('kaki_th');
kaki_th=imfill(kaki_th,'holes');
figure(5)
imshow(kaki_th);
title('kaki_th(内部の穴埋め1回目)');
kaki_th=bwmorph(kaki_th,'remove');
figure(6)
imshow(kaki_th);
title('kaki_th(外周をプロット)');
kaki_th=imdilate(kaki_th,strel('disk',10));
figure(7)
imshow(kaki_th);
title('kaki_th(プロットした点を線で繋ぐ)');
kaki_th=imfill(kaki_th,'holes');
figure(8)
imshow(kaki_th);
title('kaki_th(線内部の塗りつぶし)');
kaki_th=imerode(kaki_th,strel('disk',10));
figure(9)
imshow(kaki_th);
title('kaki_th(画像の収縮)');
cc1=bwconncomp(kaki_th);
main1=regionprops(cc1,'Area');
A=[main1.Area];
[~,biggest]=max(A);
kaki_th(labelmatrix(cc1)~=biggest)=0;
figure(10)
imshow(kaki_th);
title('kaki_th(周囲のノイズ除去)');
kaki_th_edge=edge(kaki_th);
figure(13)
imshow(kaki_th_edge);
[row,col]=find(kaki_th_edge);
for k=1:330
for i=k+1:330
I=((row(k)-row(i)).^2);
J=((col(k)-col(i)).^2);
dist=sqrt(I+J);
distmax=max(dist);
end
Distmax=max(distmax);
end
bwdist=bwdistgeodesic(kaki_th_edge,col(1),row(1),'quasi-euclidean');
bwdistmax=max(bwdist);
tatemax=distmax*pix;
cc2=regionprops(kaki_th,'Centroid');
centroids=cat(1,cc2.Centroid);
figure(11)
imshow(kaki_th);
hold on
plot(centroids(:,1),centroids(:,2),'r*');
hold off
C=imfuse(kaki_th,kaki_img);
figure(12)
imshow(C);
title('kaki_th(元画像との比較)');