title: Determine the minimum bounding box to capture an object in MATLAB
body: <p>I have background subtracted images as input.  The idea is to reduce search areas for person detection by using a smaller search area for the HOG algorithm.  The output required is a bounding box around the person and the pixel positions of the box corners.  </p>
  
  <p>This is the input image:</p>
  
  <p><img src="https://i.stack.imgur.com/mRWId.png" alt="input image"></p>
  
  <p>This is the required output:</p>
  
  <p><img src="https://i.stack.imgur.com/jizUj.png" alt="required output"></p>
  
  <p>This is what I have tried so far: </p>
  
  <pre><code>x=imread('frame 0080.png');   
  y=im2bw(x);
  s=regionprops(y);    
  
  imshow(y);    
  hold on
  
  for i=1:numel(s)  
     rectangle('Position',s(i).BoundingBox,'edgecolor','y')
  end
  </code></pre>
  
  <p>This was the output I got:</p>
  
  <p><img src="https://i.stack.imgur.com/sckBq.png" alt="actual output"></p>