简体   繁体   中英

Rescale rectangle (Top, Left, Bottom, right)

Original question: Original question

I have an image I1 of size height x width = (1500,500) resized to (500,300) .

I1 contains bounding boxes characterized by their coordinates (Top, Left, Bottom, Right) .


How can rescale the coordinates of the bounding boxes when The size of I1 is changed? are these formulas correct?

   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;

In general:

Sizes scale by the factor (new-size)/(old-size).

Coordinates are a bit more complex:

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

where left and width , etc describe the location of the entire image. x and y describe the feature being transformed. In your case, corners of the bounding boxes are features.

If left1 , left2 , top1 , top2 are all zero, you will get expressions similar to yours.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM