

im = imread('objects.jpg');
im = sum(im,3);
im = im/max(im(:));

im = im > .5;
se=strel('square',3);

im2 = imopen(im,se);
im2 = im2 == 0;
im2 = imopen(im2,se);

bwl = bwlabel(im2, 8);

for i=1:max(bwl(:))
    im3 = bwl == i;
    y = floor(find(im3,1)/size(im3,1))+1;
    x = mod(find(im3,1),size(im3,1));
    if (x == 0)
        x = size(im3,1);
    end
    B = bwtraceboundary(im3,[x y],'N');
    
    clear dist
    
    for j = 1:size(B,1)
        dist(j) = norm(B(j,:)-mean(B));
    end

    Y = abs(fft(dist));
    if (size(Y,2) > 50)
        Yt(i,1:49) = Y(2:50) ./ Y(1);
    else
        Yt(i,1:size(Y,2)-1) = Y(2:1:size(Y,2)) ./ Y(1);
    end
    
    X = 11:1:49;
    Ytm(i) = mean(Yt(i,11:49));
    v = dot(X,(Yt(i,11:49)-Ytm(i)).^2);
    Yts(i) = sqrt(v);
    FSm(i) = dot(X, Yt(i,11:49));
    
end

Yt1 = Yt(1,1:10);
for i = 2:max(bwl(:))
    Yt2 = Yt(i,1:10);
    Ytd(i) = norm(Yt1-Yt2);
    Ytlms(i) = (Yts(1) - Yts(i))^2;
end

[sorted indx1] = sort(Ytd);
[sorted indx2] = sort(Ytlms);
[sorted indx3] = sort(Yts,'descend');

for i=1:max(bwl(:))
    imtest = bwl == i;
    imshow(imtest);
    pause;
end
