Drawing a rectangle on top of an image
조회 수: 181 (최근 30일)
이전 댓글 표시
Say I have a rectangle with some dimensions. If I want to draw a rectangle over an image using for instance `plot`, if I start as follows:
hold on
imshow(img)
Then, regarding `plot` and my rectangle. How would they fit in this process?
Thanks.
댓글 수: 0
답변 (1개)
Image Analyst
2013년 12월 19일
imshow(img);
hold on;
% Then, from the help:
rectangle('Position',[0.59,0.35,3.75,1.37],...
'Curvature',[0.8,0.4],...
'LineWidth',2,'LineStyle','--')
댓글 수: 4
Katia-Renae Purnell
2022년 2월 25일
I see you calculate the size of the image, but I don't see where it is used. How do you calculate the offset so that the rectangle is actually drawn over the image?
DGM
2022년 2월 26일
As to how you find the correct offset, that certainly might be a function of the image height and width as you suspect. The problem with writing a generalized example is that there are multiple ways to find an offset for an arbitrary location in space. In some case, you might want to draw a rectangle over some text to censor it. In some example, you might want to draw a rectangle around a peak value. In the above example, the rectangle is drawn around a face. Programmatic solutions to these three tasks would be significantly different and some are individually involved enough that it's arguable that they're beyond the scope of a simple rectangle() demo.
I don't know for certain how Image Analyst found the face, but I imagine that if I needed to draw a rectangle over one such image, I would probably just use a datatip or impixelinfo() to fetch an approximate set of coordinates.
If your're implicitly asking how you can programmatically get the offsets to place a rectangle() object in a certain spot on various images, you'll need to start with a good description of what your images look like and what your goals are. Depending on the scope of the problem, it may be best to open a new question so as to get more eyes on it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!