kaki_img=imread('kaki_prototype.jpg');
figure(2)
imshow(kaki_img,'Border','tight','InitialMagnification','fit');
kaki_red=kaki_img(:,:,1);
figure(3)
imshow(kaki_red,'Border','tight','InitialMagnification','fit');
kaki_th=kaki_red>145;
figure(4)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
kaki_th=imfill(kaki_th,'holes');
figure(5)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
kaki_th=bwareafilt(kaki_th,1);
figure(6)
imshow(kaki_th,'Border','tight','InitialMagnification','fit');
BW = kaki_th;
B=bwboundaries(kaki_th,'noholes');
figure(7)
imshow(BW)
hold on
for kk=1:numel(B)
plot(B{kk}(:,2),B{kk}(:,1),'c','LineWidth',2)
end
stats=regionprops('table',BW,'Perimeter');
title(sprintf('boundary length is %d',stats.Perimeter))
sunpo=imread('box_base.jpg');
figure(1)
imshow(sunpo)
[x,y,P]=impixel(sunpo);
[x,y];
Dis1=(((x(2)-x(1))^2)+((y(2)-y(1))^2))^(1/2);
Dis2=(((x(4)-x(3))^2)+((y(4)-y(3))^2))^(1/2);
Dis3=(((x(6)-x(5))^2)+((y(6)-y(5))^2))^(1/2);
Dis4=(((x(8)-x(7))^2)+((y(8)-y(7))^2))^(1/2);
Dis5=(((x(10)-x(9))^2)+((y(10)-y(9))^2))^(1/2);
Disav=(Dis1+Dis2+Dis3+Dis4+Dis5)/5;
pix=20/(Disav);
size=stats.Perimeter*pix;