Skip to content Skip to sidebar Skip to footer

How Can I Convert Form [xmin Ymin Xmax Ymax] To [x Y Width Height] Normalized In Image?

I am building a custom vision application with Microsoft's CustomVision.ai. I am using this tutorial. When you tag images in object detection projects, you need to specify the regi

Solution 1:

Assuming x/ymin and x/ymax are your bounding corners, top left and bottom right respectively. Then:

x = xmin
y = ymin
w = xmax - xmin
h = ymax - ymin

You then need to normalize these, which means give them as a proportion of the whole image, so simple divide each value by its respective size from the values above:

x = xmin / width
y = ymin / height
w = (xmax - xmin) / width
h = (ymax - ymin) / height

This assumes a top-left origin, you will have to apply a shift factor if this is not the case.

Solution 2:

Here's a function that converts the values and normalizes them for the image size:

def convert(xmin, ymin, xmax, ymax, img_w, img_h):
    dw = 1./(img_w)
    dh = 1./(img_h)
    x = (xmin + xmax)/2.0 - 1
    y = (ymin + ymax)/2.0 - 1
    w = xmax - xminh= ymax - yminx= x*dww= w*dwy= y*dhh= h*dh
    return(x,y,w,h)

And for your example above:

my_xmin = 159
my_ymin = 15
my_xmax = 396
my_ymax = 302
my_img_w = 410
my_img_h = 400
convert(my_xmin, my_ymin, my_xmax, my_ymax, my_img_w, my_img_h)

Post a Comment for "How Can I Convert Form [xmin Ymin Xmax Ymax] To [x Y Width Height] Normalized In Image?"