# How do I get only the width and height?

2 views (last 30 days)
Leonard Yeo on 15 Nov 2015
Edited: Leonard Yeo on 17 Nov 2015
I have a set a minimum width = 300 and height = 300 for the bounding box. I need to compare the width and height that is above 300. But right now, I am unable to compare them as I could not return the width or height values in each row. May I know how can I achieve that? Thanks.
bbox =
1174 557 63 66
1692 1517 74 78
1157 467 69 73
1123 1447 72 77
887 1572 77 82
1586 1275 93 100
1589 1517 89 95
706 1300 115 122
540 1309 122 130
496 1718 1262 1342

Image Analyst on 15 Nov 2015
To get the overall bounding box:
bbox = [
1174 557 63 66
1692 1517 74 78
1157 467 69 73
1123 1447 72 77
887 1572 77 82
1586 1275 93 100
1589 1517 89 95
706 1300 115 122
540 1309 122 130
496 1718 1262 1342]
% Find the xRight columns
xRight = bbox(:, 1) + bbox(:, 3)
% Find the yBottom rows
yBottom = bbox(:, 2) + bbox(:, 4)
% Find the overall left-most x value
xLeft = min(bbox(:, 1))
% Find the overall right-most x value
xRight = max(xRight)
% Find the overall top-most y value
yTop = min(bbox(:, 2))
% Find the overall right-most x value
yBottom = max(yBottom)
% Get the overall bounding box
overallBox = [xLeft, yTop, xRight-xLeft, yBottom-yTop]
% Plot the individual boxes
for row = 1 : size(bbox, 1)
rectangle('Position', bbox(row, :), 'EdgeColor', 'b', 'LineWidth', 2);
hold on;
end
% Plot the overall bounding box in red.
rectangle('Position', overallBox, 'EdgeColor', 'r', 'LineStyle', '--', 'LineWidth', 2);
axis equal
xlim([0,2000]);
ylim([0,3500]);
##### 3 CommentsShow 1 older commentHide 1 older comment
Image Analyst on 17 Nov 2015
If you just want to remove them from the bbox array, you can do
smallBoxIndexes = bbox(:, 3) < 300; % Find rows.
bbox(smallBoxIndexes, :) = []; % Remove rows.
It's a whole different answer if you're talking about imaging and a binary image and labeled image. You can use ismember() to get a new labeled image, then remeasure the blobs that are left:
bigBoxIndexes = find(bbox(:, 3) > 300); % Find rows.
labeledImage = ismember(labeledImage, bigBoxIndexes);
measurements = regionprops(labeledImage, 'BoundingBox'); % Re-measure what's left.
Or, you might want to use bwareaopen() before labeling to get rid of blobs based on areas.
Leonard Yeo on 17 Nov 2015
Edited: Leonard Yeo on 17 Nov 2015
This is what I need! Thank you very much!

Andrei Bobrov on 15 Nov 2015
bbox(3);
##### 3 CommentsShow 1 older commentHide 1 older comment
Andrei Bobrov on 15 Nov 2015
Leonard Yeo on 15 Nov 2015
Edited: Leonard Yeo on 15 Nov 2015
I have a set a minimum width = 300 and height = 300 for the bounding box. I need to compare the width and height that is above 300. But right now, I am unable to compare them as I could not return the width or height values in each row.
bbox =
1174 557 63 66
1692 1517 74 78
1157 467 69 73
1123 1447 72 77
887 1572 77 82
1586 1275 93 100
1589 1517 89 95
706 1300 115 122
540 1309 122 130
496 1718 1262 1342
So if I were to put bbox(3), it only returns 1157 instead of 69.
>> bbox(3)
ans =
1157

Image Analyst on 15 Nov 2015
Try this:
bbox = [
1174 557 63 66
1692 1517 74 78
1157 467 69 73
1123 1447 72 77
887 1572 77 82
1586 1275 93 100
1589 1517 89 95
706 1300 115 122
540 1309 122 130
496 1718 1262 1342]
% Set min width in column 3 to 300
bbox(:, 3) = max(300, bbox(:, 3))
% Set min height in column 4 to 300
bbox(:, 4) = max(300, bbox(:, 4))
The final result:
bbox =
1174 557 300 300
1692 1517 300 300
1157 467 300 300
1123 1447 300 300
887 1572 300 300
1586 1275 300 300
1589 1517 300 300
706 1300 300 300
540 1309 300 300
496 1718 1262 1342
Leonard Yeo on 15 Nov 2015
Hi, sorry but there will be setting the bbox width and height to 300. But, there is not the objective of it. My goal is to filter out bounding box size which are too small to be classified as an object and only put a bounding box which are of certain sizes.