I have a set of object annotations in bounding box form. I have the x,y and x2y2 coordinations of these bounding boxes. I wish to preprocess the images and resize them using either Matlab's imresize or opencv/python INTER_AREA. No problems there, but I wish to find the new positions of the bounding box coordinates.
Ideally, I should be able to get the transform matrix from INTER_AREA and apply it to the coordinates but I don't see a way to do this although I have been browsing a ton.
Thanks.
You could represent the bboxes as percentages of the original image, then resize the image and convert the bboxes back to image coordinates.
For example:
function x1p,y1p,x2p,y2p = toPercentage(img_orig, x1,y1,x2,y2)
h,w,c = size(img_orig);
x1p = x1 / w;
x2p = x2 / w;
y1p = y1 / h;
y2p = y2 / h;
Once you have these percentages resize your image and then convert the bbox percentages back to coordinates of the resized image.
function x1,y1,x2,y2 = toImCoord(img_resized, x1p,y1p,x2p,y2p)
h,w,c = size(img_resized);
x1 = x1p * w;
x2 = x2p * w;
y1 = y1p * h;
y2 = y2p * h;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With