Drawing a rectangle on top of an image
51 次查看(过去 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 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!