imgaug
imgaug copied to clipboard
Bounding boxes from center x, center y, center height, center width
Might be a good feature if we can write something like this
bb = BoundingBox(center_x=center_x, center_y=center_y, center_height=center_height, center_width=center_width)
rather than
bb = BoundingBox(
x1=center_x - center_width / 2,
y1=center_y + center_height / 2,
x2=center_x + center_width / 2,
y2=center_y - center_height / 2,
)
I guess that if you have to do that for a lot of boxes it would be worth it to write a subclass
import imgaug as ia
class CWHBoundingBox(ia.BoundingBox):
def __init__(self, center_x, center_y,
width, height, label = None):
super().__init__(
x1=center_x - width / 2,
y1=center_y + height / 2,
x2=center_x + width / 2,
y2=center_y - height / 2,
label = label
)
my_bb = ia.BoundingBox(x1=7, y1=8, x2=13, y2=12, label=None)
my_box = CWHBoundingBox(center_x = 10, center_y = 10, width = 6, height = 4)
print(my_box)
# BoundingBox(x1=7.0000, y1=8.0000, x2=13.0000, y2=12.0000, label=None)
my_box.width
# 6.0
Going back to this issue and wondering if there could be a more elegant way to do this i found that you could add a class method to do this (so you don't actually make a new class and just add the functionality to the BoundingBox class)
snippet showing ow it could be done:
import imgaug as ia
def bb_from_cw(cls, center_x, center_y, width, height, label=None):
obj = cls(
x1=center_x - width / 2,
y1=center_y + height / 2,
x2=center_x + width / 2,
y2=center_y - height / 2,
label=label,
)
return obj
setattr(ia.BoundingBox, "from_cw", classmethod(bb_from_cw))
my_box = ia.BoundingBox.from_cw(center_x=10, center_y=10, width=6, height=4)
print(my_box)
# BoundingBox(x1=7.0000, y1=8.0000, x2=13.0000, y2=12.0000, label=None)
Hope it helps and I think the class method could be added as a in a PR. Up to @aleju if you think it would be useful
I think that this feature will be very nice to have, especially if you work with YOLO models. @aleju any updates on this feature?
@victor1cea The project has not been active for a while now. @aleju has not been active for a while and I am not aware of any co-maintainer ... i think it is stable enough to be used as is but to be completely honest I would not expect any new updates anytime soon.... sorry
I don't know if it would be time to fork it...
Going back to this issue and wondering if there could be a more elegant way to do this i found that you could add a class method to do this (so you don't actually make a new class and just add the functionality to the BoundingBox class)
snippet showing ow it could be done:
import imgaug as ia def bb_from_cw(cls, center_x, center_y, width, height, label=None): obj = cls( x1=center_x - width / 2, y1=center_y + height / 2, x2=center_x + width / 2, y2=center_y - height / 2, label=label, ) return obj setattr(ia.BoundingBox, "from_cw", classmethod(bb_from_cw)) my_box = ia.BoundingBox.from_cw(center_x=10, center_y=10, width=6, height=4) print(my_box) # BoundingBox(x1=7.0000, y1=8.0000, x2=13.0000, y2=12.0000, label=None)
Hope it helps and I think the class method could be added as a in a PR. Up to @aleju if you think it would be useful
As bounding boxes are top-left and bottom-right corner coordinates. y1
and y2
should be changed in bb_from_cw
method, right ?
@Digital2Slave I think it doe snot really matter ... :P having said that ... since this project is currently in an orphan state, I think it would be a good call to start using something else for the time being.
@Digital2Slave I think it doe snot really matter ... :P having said that ... since this project is currently in an orphan state, I think it would be a good call to start using something else for the time being.
Okay, that's right. The author do not active for a long time. :disappointed: