title: Bounding Box in Matlab (regionprops)
body: <p>I am writing a Matlab program to segment an image and then put a bounding box around the segmented image. My code was previously working, however I am now getting the error:</p>
  
  <blockquote>
    <ul>
    <li>Error using rectangle</li>
    <li>Value must be a 4 element vector</li>
    </ul>
  </blockquote>
  
  <p>The array in question is BoundingBox created by regionprops, which <em>should</em> contain only four elements, however is for some reason containing more. Here is my code (the defaultSegment function returns a binary image):</p>
  
  <pre><code>function [ boundImage ] = boundSegment( input_image )
  image = defaultSegment(input_image);
  clear s;
  s = regionprops(image, 'Area', 'BoundingBox');
  numObj = numel(s);
  index = 1;
  for k = 1: numObj-1
      if s(k+1).Area &gt; s(index).Area
          index = k+1;
      else
          index = index;
      end
  end
  figure, imshow(input_image);
  rectangle('Position',s(index).BoundingBox);
  boundImage = null;
  </code></pre>
  
  <p>(I would actually prefer if my code could could directly put the bounding box on the image instead of subplotting it, but I haven't found a way to do that without the vision toolbox)</p>
  
  <p>Thanks!</p>