How do I get only the width and height?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Image Analyst
2015-11-15
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 个评论
Image Analyst
2015-11-17
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.
更多回答(2 个)
Image Analyst
2015-11-15
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!