
BoundingBox in selected object
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a binary image with 5 objects

I want to draw a boundingbox only in the 3rd object (from the left).How can I do that by using regionprops. I have attached the image. The size and shape of the objects are same.
댓글 수: 0
답변 (1개)
Sourabh
2025년 2월 19일
Hey @rupam baruah
You can draw a boundingbox on the 3rd object from the left using “regionprops” as follows:
1. Ensure the image is 2D binary grayscale
bw = imbinarize(rgb2gray(img));
2. Get properties of each region
stats = regionprops(bw, 'BoundingBox', 'Centroid');
3. Get the bounding box of the 3rd object from the left
boundingBox = stats(3).BoundingBox;
4. Display the image and the bounding box
imshow(bw);
hold on;
rectangle('Position', boundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
hold off;
The final output looks like this:

For more related examples on using “regionprops”, kindly follow the MATLAB documentation:
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!