How to draw bounding boxes around the ROI obtained by thresholding.

9 views (last 30 days)
I want to highlight the region of interest using rectangular bounding box on the original image.
Can anyone here help me with this?

Answers (1)

Image Analyst
Image Analyst on 4 Apr 2018
props = regionprops(binaryImage, 'BoundingBox');
for k = 1 : length(props)
thisBB = props(k).BoundingBox;
hold on;
rectangle('Position', thisBB);
end
  2 Comments
Sidra Aleem
Sidra Aleem on 5 Apr 2018
Edited: Sidra Aleem on 6 Apr 2018
@Image Analyst I tried the same code from the link ( https://de.mathworks.com/matlabcentral/answers/87597-rectangle-around-the-object-bounding-box ). but its gives bounding boxes in the thresholded image.
However, I donot want this. I want these bouding boxes at the same position, but on the segmented image as shown in figure1 in my questionj. I want the bounding box around the thresholded image to be in the same position, but on Blood vessel subplot.
I tried to do the following, but its not working.
st = regionprops(Thresholded_image,'BoundingBox'); % Thresholded image in subplot 2
figure,imshow(bloodVessels); %Blood Vessel Image in subplot 3
for k = 1 : length(st)
thisBB = st(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end
As shown the third subplot doesnot have any bounding box.
Image Analyst
Image Analyst on 6 Apr 2018
You have to switch the current axes to the one you want to put the boxes onto. For example call subplot() or axes() before you call rectangle().

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!