title: Extract object from image in Matlab
body: <p>I'm currently learning image processing with Matlab. What I'm trying to do is to find in the following image all the letter <em>a</em>'s and remove all the rest.</p>
  
  <p><img src="https://i.stack.imgur.com/N4nCm.png" alt="a.tiff"></p>
  
  <p>First of all I convert the image to a binary one. Then I try to get rid of the noise by using a median filter. There are some gaps in some of tha a's borders, which I fill by opening the image.
  But then I get stuck, I found some things on the internet (which I do not completely understand) with which I am able to select the gaps from all the a's.</p>
  
  <p>What should I do next?</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>text = imread('http://i.stack.imgur.com/N4nCm.png');
  text = mat2gray(text);
  
  % find threshold and chance to binary image
  border = graythresh(text);
  textbw = im2bw(text, border);
  imshow(textbw);
  
  % remove noise with median filter
  textfilt = medfilt2(textbw);
  
  % remove small holes in the border of the a
  se = strel('disk', 4);
  texter = imopen(textfilt, se);
  
  % find holes
  s = regionprops(texter, 'BoundingBox');
  bb = round(reshape([s.BoundingBox], 4, []).');
  
  % show original image with holes
  imshow(textbw);
  
  for idx = 1 : numel(s)
      rectangle('Position', bb(idx,:), 'edgecolor', 'red');
  end
  </code></pre>