在 Matlab 中将点列表转换为边界框

Convert List of Points to a Bounding Box in Matlab

我有一个边界框:

 bbox = [10 20 50 60];

我使用以下方法将边界框转换为点列表:

 points = bbox2points(bbox);

然后我使用 affine2dtransformPointsForward 对点应用旋转。现在我有了转换点,如何将它们转换回边界框?是否有一些等同于 "points2bbox" 的内置函数?谢谢。

现已排序。我只是以各种方式翻转图像,然后使用旋转角度和原始图像的尺寸(保持不变)计算新的边界框位置。

如果您只想从点制作一个 bbox 而不必担心转换,请执行此操作。我刚做了这个,而且很管用。

function bbox = points2bbox(roi)
% This is a function that takes in an roi (a set of four points) and
% outpouts a bbox (which is in for form of x,y,w,h, where x and y
% correspond to the lower left of the coordinates for the points. 

% MAKE SURE THAT YOUR POINTS MAKE A RECTANGLE! 
% THIS IS WHAT BBOX HERE DESCRIBES!

% Getting x and y data
x = roi(:,1);
y = roi(:,2);

% Getting width and height
width = max(x) - min(x);
height = max(y) - min(y);

% Constructing bbox
bbox = [min(x) min(y) width height]
end

其中 roi(我研究中的感兴趣区域)是一组点,第一列为 x 坐标,第二列为 y 坐标。