function CS6640_P2_A4
%

% P2
% should explore the use of methods covered (with focus on new material)
%  applied to your project:
%    * representative values (in RGB, HSV, or general feature vector)
%    * edge detection
%    * nonlinear filers
%    * feature vectors:
%      - texture (Laws)
%      - histograms (edge magnitudes, orientations)

br1 = imread('brodatz3.bmp');
br2 = imread('brodatz14.bmp');
br3 = imread('brodatz20.bmp');
br4 = imread('brodatz48.bmp');
br = [br1,br2;br3,br4];

map1 = imread('map1.jpg');
map1g = rgb2gray(map1);

bot1 = imread('image001.jpg');
imo = CS6640_cap(bot1,15);
figure(1);
clf
subplot(2,1,1);
imshow(bot1);
subplot(2,1,2);
imshow(imo<800);
bot2 = imread('image025.jpg');
imo = CS6640_cap(bot2,15);
figure(1);
clf
subplot(2,1,1);
imshow(bot2);
subplot(2,1,2);
imshow(imo<800);

imo = CS6640_mean_var(double(map1g),15);
X = reshape(imo,728*1477,2);
[cidx,ctrs] = kmeans(X,4);
im = reshape(cidx,728,1477);
figure(1);
clf
subplot(2,2,1);
combo(map1,~(im==1));
subplot(2,2,2);
combo(map1,~(im==2));
subplot(2,2,3);
combo(map1,~(im==3));
subplot(2,2,4);
combo(map1,~(im==4));

% A4
figure(1);
clf
map1gF = fft2(map1g);
imagesc(abs(map1gF));
% can't see anything
im1 = abs(fftshift(map1gF));
im1 = imresize(im1,[300,300]);
imagesc(im1);
surf(im1);

map1gi = ifft2(map1gF);
imshow(mat2gray(map1gi));

% Spatial filtering to frequency domain
f = fspecial('average',15);
[M,N] = size(map1g);
f_p = zeros(2*M,2*N);
f_p(1:15,1:15) = f;
f_F = fft2(f_p);

map1g_p = zeros(2*M,2*N);
map1g_p(1:M,1:N) = map1g;
map1g_F = fft2(map1g_p);

f_map1gF = f_F.*map1g_F;
map1g_pi = ifft2(f_map1gF);
imshow(mat2gray(real(map1g_pi)));

% Frequency Domain Filter Development
B = zeros(M,N);
r_ctr = floor(M/2);
c_ctr = floor(N/2);
B(r_ctr-50:r_ctr+50,c_ctr-50:c_ctr+50) = 1;
imshow(B);
B = fftshift(B);
imshow(B);

map1gF = fft2(double(map1g));
B_map1gF = B.*map1gF;
map1gFi = ifft2(B_map1gF);
imshow(mat2gray(real(map1gFi)));

tch = 0;
