如何在 Matlab R2018b 中的图像上使用 4 个角绘制矩形?

How to draw a rectangle using 4 corners on an image in Matlab R2018b?

在Matlab中,有rectangle('Position',[x,y,w,h])画一个矩形对象,wh分别是宽度和高度(这个link)。当我尝试使用 4 个角在图像上绘制矩形时:min_xmax_xmin_ymax_y,它们在下图中指定。

例如:

min_x = 193; max_x = 220; min_y = 168; max_y = 190;

我看到了这个 link 之类的,但他们帮不了我。有什么方法可以画出4个角的矩形吗?

A = imresize( imread('peppers.png'),0.6);%resizing for better visibility

min_x = 193; max_x = 220; min_y = 168; max_y = 190;

x = min_x;
y = min_y;
w = max_x-min_x;
h = max_y-min_y;

imshow(A)
rectangle('Position',[x,y,w,h],'EdgeColor','r','Linewidth',3);
% Or insert shape to bitmap:
% B = insertShape(A,'rectangle',[x,y,w,h]);
% imshow(B)