Placing a Title on Bounding Box
이전 댓글 표시
I would like to be able to add the title 'Defect' to my bounding box below. I have seen this done in many other applications such as object tracking. But I cannot seem to get it to work. Also, could this be done for multiple bounding boxes. Here is the code I have sof the bounding boxes:
%% Display Bounding Box
figure, imshow(DifferenceOf2),
title('Subtraction of Dialated Edge Template'),
[L ,Num] = bwlabel(DifferenceOf2);
stats = regionprops(DifferenceOf2, 'basic');
stats(1).Area;, ..., stats(end).Area;
stats.Area
allArea = [stats.Area];
s = regionprops(DifferenceOf2, 'all');
s(1)
centroids = cat(2, s.Centroid);
hold on
plot(centroids(:,1), centroids(:,2), 'r*')
for n=1: length(s)
rectangle('Position', s(n).BoundingBox, 'EdgeColor', 'g', 'LineWidth',2), title('Detected Defect')
end
hold off
.

. .
I would like have something like the figure below. I would rather it display the area and/or centroid of the defect as opposed to just 'Defect'.
.
.

. .
Please and Thank you for your help.
채택된 답변
추가 답변 (2개)
Christopher Berry
2014년 8월 6일
What you are looking for is either annotation. You can also you sprintf to get the string formatted with the information you want. For example,
str = sprintf('Defect at (%0.2f,%0.2f)',32.32443,1.1233)
annotation('textbox',[0.2,0.4,0.1,0.1],'String',str)
For your case, you can the the [x y width height] (given in my example as [0.2,0.4,0.1,0.1]) information for the annotation from your bounding box data.
댓글 수: 5
Christopher Berry
2014년 8월 6일
Chad's answer of text will also work in place of annotation, but using sprintf will be helpful in either case.
Amanda Johnson
2014년 8월 6일
Amanda Johnson
2014년 8월 6일
Amanda Johnson
2014년 8월 6일
Christopher Berry
2014년 8월 6일
편집: Christopher Berry
2014년 8월 6일
Haha, I like your text :)
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

