重新缩放矩形(顶部,左侧,底部,右侧)

时间:2014-09-15 13:46:32

标签: c# rectangles bounding-box rescale

原始问题:Original question

我的图片 I1 大小为height x width = (1500,500),已调整为(500,300)

I1 包含以坐标(Top, Left, Bottom, Right)为特征的边界框。


I1 的大小发生变化时,如何重新缩放边界框的坐标?这些公式是否正确?

   double newTop = Math.Ceiling((top) * (double)pictureBox1.Height / (double)image1.Height);
   double newLeft = Math.Ceiling((left) * (double)pictureBox1.Width / (double)image1.Width);
   double newBottom = Math.Ceiling((bottom + 1) * (double)pictureBox1.Height / (double)image1.Height) - 1;
   double newRight = Math.Ceiling((right + 1) * (double)pictureBox1.Width / (double)image1.Width) - 1;

1 个答案:

答案 0 :(得分:1)

一般来说:

尺寸按因子(新尺寸)/(旧尺寸)缩放。

坐标有点复杂:

x2 = left2 + (x1 - left1) * width2 / width1
y2 = top2 + (y1 - top1) * height2 / height1

其中leftwidth等描述整个图像的位置。 xy描述了正在转换的功能。在您的情况下,边界框的角是功能。

如果left1left2top1top2都为零,您将获得与您类似的表达式。

相关问题