%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%     水果大小检测    2013年10月10日  zhengrui   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%读取水果图像
IClr = imread('sideviewclr.png', 'png');
%转换为灰度图
IGry = rgb2gray(IClr);
%用中值滤波去除椒盐噪声
IFltM = medfilt2(IGry,[3 3]);
%创建高斯滤波模板
H = fspecial('gaussian',[3,3],0.5);
%用高斯滤波器对原图像进行平滑
IFltG = filter2(H,IFltM);
%获得Sobel边缘图像
ISbl = edge(IFltG,'sobel'); 
imshow(ISbl);
%估算形心位置
[m,n]=size(ISbl);
X0=0;
Y0=0;
COUNT=0;
for i=3:m-3
    for j=3:n-2
        if(ISbl(i,j))
            X0=X0+j;
            Y0=Y0+i;
            COUNT = COUNT+1;
        end
    end 
end
X0 = round(X0/COUNT);
Y0 = round(Y0/COUNT);
%获取精确边缘
IfineEdge = ISbl;
R1=115;R2=55;



       


