Reputation: 2441
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;
Upvotes: 0
Views: 2605
Reputation: 283624
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.
Upvotes: 1