im = imread('d:\comp vision\Images\travis.jpg');

gim = rgb2gray(im);
BW = gim > 135;

imwrite(gim,'gim.png');
imwrite(BW,'bw.png');


SE1 = circularstruct(2);
SE2 = ones(3);
SE3 = ones(2, 5);
SE4 = eye(5) | rot90(eye(5));
  
BW1 = imerode(imdilate(BW, SE1),SE1); % imclose
BW2 = imdilate(imerode(BW, SE2),SE2); % imopen
BW3 = imerode(imdilate(BW, SE3),SE3); % imclose
BW4 = imdilate(imerode(BW, SE4),SE4); % imopen


BW5 = imopen(imclose(BW, SE1), SE1);
BW6 = imclose(imopen(BW, SE1), SE1);

imwrite(BW1,'imSE1.png');
imwrite(BW2,'imSE2.png');
imwrite(BW3,'imSE3.png');
imwrite(BW4,'imSE4.png');
imwrite(BW5,'imcloseopen.png');
imwrite(BW6,'imopenclose.png');
