%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%     水果形状检测    2013年10月10日  zhengrui  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X0s     = zeros(1,7);
Y0s     = zeros(1,7);
RVector = zeros(360,7);

%读取形状数据
imgi = 0;
for imgi=1:7
    %读取彩色图像数据
    IClr = imread(strcat('形状样本/',strcat(num2str(imgi),'.png')), 'png');
    %转为灰度图
    IGry = rgb2gray(IClr);
    [m,n]=size(IGry);
    %获取图像边界序列点，首先检测最左端的边缘点，然后根据邻接性提取所有边缘上的点
    for j=1:1:n
        %遍历每一行
        for j=1:1:m
            %如果像素不为零
            if(IGry(i,j))
                
            end
        end
    end
    %
    
    
    
    %求取质心
    
    
    
    %求取果梗果体交界点
    
    
    
    %重排半径序列
    
    
    %DFT变换
    
    
    %计算与标准形差异
    X0=0;
    Y0=0;
    COUNT=0;
    for i=3:m-3
        for j=3:n-2
            if(IGry(i,j))
                X0=X0+j;
                Y0=Y0+i;
                COUNT = COUNT+1;
            end
        end 
    end
    X0 = round(X0/COUNT);
    Y0 = round(Y0/COUNT);
    
    X0s(1, imgi) = X0;
    Y0s(1, imgi) = Y0;
    
    %
%     sigmanmx = 0;
%     sigmanmy = 0;
%     sigmadem = 0;
%     Xk1=0;
%     Yk1=0;
%     [m,n]=size(IGry);
%     firstflag = 1;
%     for i=1:1:m
%         for j=1:1:n
%            if(IGry(i,j)==255)
%               if(firstflag==1)
%                 Xk1 = j;
%               	Yk1 = i;
%               	firstflag = 0;
%               else
%               	Xk=j;
%               	Yk=i;
%               	sigmanmx = sigmanmx+Yk*(Xk*Xk-Xk1*Xk1)-Xk*Xk*(Yk-Yk1);
%               	sigmanmy = sigmanmy+Yk*Yk*(Xk-Xk1)-Xk*(Yk*Yk-Yk1*Yk1);
%               	sigmadem = sigmadem+Yk*(Xk-Xk1)-Xk*(Yk-Yk1);
%               	Xk1=Xk;
%               	Yk1=Yk;
%               end
%            end
%         end
%     end
%     X0s(1, imgi) = sigmanmx/sigmadem/2;
%     Y0s(1, imgi) = sigmanmy/sigmadem/2;
    figure;
    imshow(IGry);
    axis on;hold on;
    plot([X0s(1, imgi), X0s(1, imgi)],[Y0s(1, imgi)-5, Y0s(1, imgi)+5],'b','linewidth',2);
    plot([X0s(1, imgi)-5, X0s(1, imgi)+5],[Y0s(1, imgi), Y0s(1, imgi)],'b','linewidth',2);
end

%转换为灰度图
