How can i able to know the start and end x and y co-ordinates boundary box image

1 view (last 30 days)
This is my matlab code
clc;
clear all;
a=imread('i450.jpg');
hsv=rgb2gray(a);
s = hsv(:,:,1);
foreground = s > 0.2; % Or whatever.
foreground = bwareaopen(foreground, 1000); % or whatever.
labeledImage = bwlabel(foreground);
measurements = regionprops(labeledImage,'BoundingBox');
bb = measurements.BoundingBox;
croppedImage = imcrop(a, bb);
c=rgb2gray(croppedImage);
I want to know the start and end coordinates of a boundary box of an image. How can i able to know in which x and y co-ordinate it is starting and where it is ending ?

Answers (1)

Image Analyst
Image Analyst on 18 Oct 2015
I fixed your formatting this time. For next time read this.
The values of the bounding box are [x,y,width, height]. So you would do this:
allBBs = [measurements.BoundingBox];
xLeft = allBBs(1:4:end); % Left edge of all the boxes.
xRight = xLeft + allBBs(3:4:end);
yBottom = allBBs(2:4:end); % Bottom edge of all the boxes.
yTop = yBottom + allBBs(4:4:end);
I don't remember if y=0 is the top of the image (like a row number), or if it's the bottom so you should check on that.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!