title: Remove unwanted white pixels for plate segmentation Matlab
body: <p>The spatial resolution images that i will be using in this project is 1000x563. My aim in this step is to <strong><em>remove all unwanted white pixel but not the number plate</em></strong> so I could segment the plate accurately. But the problem is I could not remove those unwanted pixels clearly. Can anybody help me to improve the codes?</p>
  
  <p>From:
  <img src="https://i.stack.imgur.com/rsqMw.png" alt="enter image description here">
  Then, 
  <img src="https://i.stack.imgur.com/6fSbE.png" alt="enter image description here">
  Then,
  <img src="https://i.stack.imgur.com/YawSw.png" alt="enter image description here">
  Lastly,
  <img src="https://i.stack.imgur.com/PyVgs.png" alt="enter image description here"></p>
  
  <p>As you observed the last image, there are still quite a number of unwanted white pixels. Please help !! </p>
  
  <pre><code>ab=imread('image4.jpg');
  ab=rgb2gray(ab);
  level=graythresh(ab);
   ab=im2bw(ab,level);
  
  ab=medfilt2(ab,[3 3]);
  
  
  ab=edge(ab,'Canny');
  figure(); imshow(ab);
  
  Tmp = imfill(ab, 'holes'); %flood filling techniques
  Tmp2 = imfill(Tmp-ab, 'holes'); 
  Res = Tmp - imfill(ab &amp; Tmp2, 'holes');
  figure(); imshow(Res,[]); 
  
  
  % keeping the white pixels area between 200 to 1000
  LB = 200;        
  UB = 1000;
  Res = xor(bwareaopen(Res,LB),  bwareaopen(Res,UB));
  figure, imshow(Res,[]);
  
  
  se = strel('disk',2);        
  Res = imerode(Res,se);
  Res=imdilate(Res,se);
  
  
  Res = bwareaopen(Res, 200);
  
  figure();
  imshow(Res,[]);
  </code></pre>