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

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 ?

Antworten (1)

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.

Gefragt:

am 18 Okt. 2015

Beantwortet:

am 18 Okt. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by