function CS6640_Week10
%

% single parameter shape representation
letters = imread('letters.png');
lettersg = rgb2gray(letters);
letterst = lettersg<70;
P = CS6640_build_params_models(letterst);
classes = CS6640_params_classify(letterst,P);
combo(letterst,classes==26);

% radial Fourier expansion
A = classes==1;
A_b = bwboundaries(A)
B = [A_b{1};A_b{2}];
num_pts = length(B(:,1));
Bm = mean(B)
f = zeros(num_pts,1);
for p = 1:num_pts
    f(p) = norm(B(p,:)-Bm);
end
f = f/max(f);

figure(1);
clf
plot(f);

F = fft(f)/num_pts;
F_amp = abs(F);
[vals,indexes] = sort(F_amp,'descend');
Fr = F;
Fr(indexes(51:end)) = 0;

fr = real(num_pts*ifft(Fr));

hold on
plot(fr,'r');

A1 = imrotate(classes==1,90);
A1_b = bwboundaries(A1)
B1 = [A1_b{1};A_b{2}];
num_pts1 = length(B1(:,1));
Bm1 = mean(B1)
f1 = zeros(num_pts1,1);
for p = 1:num_pts1
    f1(p) = norm(B1(p,:)-Bm1);
end
f1 = f1/max(f1);

figure(1);
clf
plot(f1);
hold on

F1 = fft(f1)/num_pts1;
F_amp1 = abs(F1);
[vals1,indexes1] = sort(F_amp1,'descend');
Fr1 = F1;
Fr1(indexes(51:end)) = 0;

fr1 = real(num_pts1*ifft(Fr1));
plot(fr1,'r');

figure(2)
plot(fftshift(F_amp));
hold on
plot(fftshift(F_amp1),'r');

norm(F_amp-F_amp1)

RFE = CS6640_build_RFE_models(letterst);
imo = CS6640_RFE_classify(letterst,RFE);
combo(letterst,imo==5);

% Statistical moments
Hu = CS6640_build_Hu_models(letterst);
imo = CS6640_Hu_classify(letterst,Hu);
combo(letterst,imo==20);

tch = 0;
