function CS6640_Week9
%

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

% get edges
me = edge(map1g,'sobel');
figure(1)
clf
imshow(me);

% dilate edges
me_d = bwmorph(me,'dilate',5);
imshow(me_d);

% erode edges
me_e = bwmorph(me_d,'erode',2);
combo(me_e,me);

% bottle examples
im1 = imread('image001.jpg');
im1g = rgb2gray(im1);
im1t = im1g<100;
clf
imshow(bwmorph(bwmorph(im1t,'erode',3),'dilate',3));

im3 = imread('image003.jpg');
im3g = rgb2gray(im3);
im3t = im3g<100;
clf
imshow(bwmorph(bwmorph(im3t,'erode',3),'dilate',3));

% open and close
rng('default');
T = CS6640_FFT_texture(double(double(map1g)));
[cidx,ctrs] = kmeans(T,6);
im = reshape(cidx,728,1477);
im5 = im==5;
se = strel('disk',4);
im5_o = imopen(im5,se);
im5_c = imclose(im5,se);
combo(im5,im5_o);
combo(im5_c,im5);

% boundary finding
im3b = bwmorph(bwmorph(im3t,'erode',3),'dilate',3);
clf
imshow(im3b);
im3b_b = imsubtract(im3b,bwmorph(im3b,'erode',1));
combo(im3b,im3b_b);
combo(im3b,bwmorph(im3b_b,'dilate',2));

% skeletonization
combo(map1g,bwmorph(bwmorph(bwmorph(me,'dilate',2),'skel',Inf),'spur',3));

% opening by reconstruction
M = im==5;
A = bwmorph(M,'erode',9);
C = A;
for k = 1:8
    C = bwmorph(C,'dilate',1)&M;
end
clf
combo(im==5,C);

tch = 0;
