Skip to content

Commit 70ee7f2

Browse files
committed
release convert upleft-butright --> centroid, w, h API
1 parent 2f815ca commit 70ee7f2

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

docs/modules/prepro.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Some of the code in this package are borrowed from Keras.
6868
obj_box_coords_rescale
6969
obj_box_coord_scale_to_pixelunit
7070
obj_box_coord_centroid_to_upleft_butright
71+
obj_box_coord_upleft_butright_to_centroid
7172
obj_box_coord_centroid_to_upleft
7273
obj_box_coord_upleft_to_centroid
7374

@@ -351,6 +352,10 @@ Coordinate [x_center, x_center, w, h] to up-left button-right
351352
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
352353
.. autofunction:: obj_box_coord_centroid_to_upleft_butright
353354

355+
Coordinate up-left button-right to [x_center, x_center, w, h]
356+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
357+
.. autofunction:: obj_box_coord_upleft_butright_to_centroid
358+
354359
Coordinate [x_center, x_center, w, h] to up-left-width-high
355360
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
356361
.. autofunction:: obj_box_coord_centroid_to_upleft

tensorlayer/prepro.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ def obj_box_coord_scale_to_pixelunit(coord, shape=(100, 100, 3)):
15421542
# exit()
15431543

15441544
def obj_box_coord_centroid_to_upleft_butright(coord, to_int=False):
1545-
""" Convert one coordinate [x_center, y_center, w, h] to [x, y, x2, y2] in up-left and botton-right format.
1545+
""" Convert one coordinate [x_center, y_center, w, h] to [x1, y1, x2, y2] in up-left and botton-right format.
15461546
15471547
Examples
15481548
---------
@@ -1551,8 +1551,8 @@ def obj_box_coord_centroid_to_upleft_butright(coord, to_int=False):
15511551
"""
15521552
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
15531553
x_center, y_center, w, h = coord
1554-
x = x_center - w / 2
1555-
y = y_center - h / 2
1554+
x = x_center - w / 2.
1555+
y = y_center - h / 2.
15561556
x2 = x + w
15571557
y2 = y + h
15581558
if to_int:
@@ -1564,14 +1564,27 @@ def obj_box_coord_centroid_to_upleft_butright(coord, to_int=False):
15641564
# print(coord) [20, 30, 40, 50]
15651565
# exit()
15661566

1567+
def obj_box_coord_upleft_butright_to_centroid(coord):
1568+
""" Convert one coordinate [x1, y1, x2, y2] to [x_center, y_center, w, h].
1569+
It is the reverse process of ``obj_box_coord_centroid_to_upleft_butright``.
1570+
"""
1571+
assert len(coord) == 4, "coordinate should be 4 values : [x1, y1, x2, y2]"
1572+
x1, y1, x2, y2 = coord
1573+
w = x2 - x1
1574+
h = y2 - y1
1575+
x_c = x1 + w / 2.
1576+
y_c = y1 + h / 2.
1577+
return [x_c, y_c, w, h]
1578+
1579+
15671580
def obj_box_coord_centroid_to_upleft(coord):
15681581
""" Convert one coordinate [x_center, y_center, w, h] to [x, y, w, h].
15691582
It is the reverse process of ``obj_box_coord_upleft_to_centroid``.
15701583
"""
15711584
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
15721585
x_center, y_center, w, h = coord
1573-
x = x_center - w / 2
1574-
y = y_center - h / 2
1586+
x = x_center - w / 2.
1587+
y = y_center - h / 2.
15751588
return [x, y, w, h]
15761589

15771590
def obj_box_coord_upleft_to_centroid(coord):
@@ -1580,8 +1593,8 @@ def obj_box_coord_upleft_to_centroid(coord):
15801593
"""
15811594
assert len(coord) == 4, "coordinate should be 4 values : [x, y, w, h]"
15821595
x, y, w, h = coord
1583-
x_center = x + w / 2
1584-
y_center = y + h / 2
1596+
x_center = x + w / 2.
1597+
y_center = y + h / 2.
15851598
return [x_center, y_center, w, h]
15861599

15871600
##

0 commit comments

Comments
 (0)