Drawing a rectangle on top of an image

48 ビュー (過去 30 日間)
med-sweng
med-sweng 2013 年 12 月 19 日
コメント済み: DGM 2022 年 2 月 26 日
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.

回答 (1 件)

Image Analyst
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
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
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 ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by