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:
- Error using rectangle
- Value must be a 4 element vector
The array in question is BoundingBox created by regionprops, which should contain only four elements, however is for some reason containing more. Here is my code (the defaultSegment function returns a binary image):
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 > s(index).Area
index = k+1;
else
index = index;
end
end
figure, imshow(input_image);
rectangle('Position',s(index).BoundingBox);
boundImage = null;
(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)
Thanks!
s(index).BoundingBox
to ensure its a4 element vector
? – slayton