Show boundingbox and label around segmented image

Hi everyone
I am doing detection using segmentation. I want to know how can I draw boundingbox with a label around segmented image when I do testing of image. I show the image using this code :
I = readimage(img,1);
C = semanticseg(I, net);
cmap=(data.gTruth.LabelDefinitions.LabelColor);
B = labeloverlay(I,C,'Colormap',cmap,'Transparency',0.4);
imshow(B)
pixelLabelColorbar(cmap, classes);
so the result I got after testing a image is shown below. I want to show the bounding boxes and labels too, and I also want that my detector shows the score, etc.

Answers (1)

If C is your labeled image, untested code:
props = regionprops(C, 'BoundingBox');
hold on;
% Display all bounding boxes over the image one at a time.
for k = 1 : numel(props)
thisBB = props(k).BoundingBox; % Get this bounding box as [x,y,width,height]
rectangle('Position', thisBB, 'EdgeColor', 'r'); % Draw the rectangle over the image.
end
Attach your img with the paperclip icon if you want/need more help.

9 Comments

still nor show boxes my model just detect and show segmented images as above
I did not understand your comment. Did you understand mine when I said: "Attach your img with the paperclip icon if you want/need more help."
i am saying that i want boundingi boxes and labels on my teat image that i give to my model trained on sematic segment dataset.
it give this image with no labels no bounding box displayed on images
i want to show my segmentic segment image like this with bounding box and labels
I don't think you've attached the ORIGINAL RGB image.
my origional image is 4.jpg and image after using detector is image.jpg
Let's not have this go on over more days. Give me everything I need to run your code the first time. This does not work
I = readimage(img,1);
C = semanticseg(I, net);
cmap=(data.gTruth.LabelDefinitions.LabelColor);
B = labeloverlay(I,C,'Colormap',cmap,'Transparency',0.4);
imshow(B)
pixelLabelColorbar(cmap, classes);
Where did you read in 4.jpg? Did you call imread? Did it go into img? What is net? Can you attach it in a .mat file?
ahmad
ahmad on 15 Sep 2023
Edited: ahmad on 15 Sep 2023
4.jp is my test image from desktop folder.
net is my trained model which i training on training data.
attach my code and matfile.
please aslo tell be how can i show label on detected image.

Sign in to comment.

Asked:

on 14 Sep 2023

Edited:

on 15 Sep 2023

Community Treasure Hunt

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

Start Hunting!