![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175146/image.png)
merge binary regions to get a bigger object
2 views (last 30 days)
Show older comments
Elysi Cochin
on 30 Sep 2016
Commented: Elysi Cochin
on 6 Oct 2016
when i do segmentation i get bboxes such as
bboxes =
85 76 75 79
90 79 55 78
57 168 48 19
91 92 38 67
how can i merge all the regions of the bounding box to one single object.... i want all the regions in one bounding box....
0 Comments
Accepted Answer
Image Analyst
on 30 Sep 2016
Try this
bboxes = [...
85 76 75 79
90 79 55 78
57 168 48 19
91 92 38 67]
allx1 = bboxes(:, 1)
ally1 = bboxes(:, 2)
allx2 = allx1 + bboxes(:, 3)
ally2 = ally1 + bboxes(:, 4)
maxWidth = max(allx2) - min(allx1)
maxHeight = max(ally2) - min(ally1)
overallBBox = [min(allx1), min(ally1), maxWidth, maxHeight]
% Display every individual box.
for k = 1 : size(bboxes, 1)
rectangle('Position', bboxes(k, :), 'EdgeColor', 'k', 'LineWidth', 5);
hold on;
end
% Display the overall box.
rectangle('Position', overallBBox, 'EdgeColor', 'r', 'LineWidth', 3);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175146/image.png)
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!