function im2BW = Preprocessing(im)
    imGray = rgb2gray(im);
    imGray = medfilt2(imGray,[10 4]);
    %imGray = wiener2(imGray,[3 3]);     
    %imGray = adapthisteq(imGray);
    T = adaptthresh(imGray,0.7,'ForegroundPolarity','dark'); %sensitivity 0.85 default
    %imshow(T)
    im2BW = imbinarize(imGray,T);
   % im2BW = imclearborder(im2BW);
    SE = strel('disk',2);
    im2BW = imclose(im2BW,SE);
    SE2 = strel('rectangle', [10 1]);
    SE3 = strel('rectangle', [1 2]);
    im2BW = imopen(im2BW, SE3);
    im2BW = imclose(im2BW,SE2);
    im2BW = bwareaopen(im2BW, 200);
    im2BW(end,:) = 0;
   %imshow(im2BW);
   %im2BW = imclearborder(im2BW);
    
  
end
