From f80270767df240c14542335390801fedbef4eccf Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sat, 30 Dec 2023 16:58:27 +0900 Subject: [PATCH] Use tight bounding box to represent bbox for shape_type="mask" --- labelme/widgets/canvas.py | 8 ++++---- setup.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/labelme/widgets/canvas.py b/labelme/widgets/canvas.py index 8d3e79758..9a476f3f3 100644 --- a/labelme/widgets/canvas.py +++ b/labelme/widgets/canvas.py @@ -768,12 +768,12 @@ def paintEvent(self, event): points=[[point.x(), point.y()] for point in drawing_shape.points], point_labels=drawing_shape.point_labels, ) - y1, x1, y2, x2 = imgviz.instances.mask_to_bbox([mask])[0].astype(int) + y1, x1, y2, x2 = imgviz.instances.masks_to_bboxes([mask])[0].astype(int) drawing_shape.setShapeRefined( shape_type="mask", points=[QtCore.QPointF(x1, y1), QtCore.QPointF(x2, y2)], point_labels=[1, 1], - mask=mask[y1:y2, x1:x2], + mask=mask[y1 : y2 + 1, x1 : x2 + 1], ) drawing_shape.selected = True drawing_shape.paint(p) @@ -818,12 +818,12 @@ def finalise(self): points=[[point.x(), point.y()] for point in self.current.points], point_labels=self.current.point_labels, ) - y1, x1, y2, x2 = imgviz.instances.mask_to_bbox([mask])[0].astype(int) + y1, x1, y2, x2 = imgviz.instances.masks_to_bboxes([mask])[0].astype(int) self.current.setShapeRefined( shape_type="mask", points=[QtCore.QPointF(x1, y1), QtCore.QPointF(x2, y2)], point_labels=[1, 1], - mask=mask[y1:y2, x1:x2], + mask=mask[y1 : y2 + 1, x1 : x2 + 1], ) self.current.close() diff --git a/setup.py b/setup.py index 4cfd95d63..704e054f0 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def get_version(): def get_install_requires(): install_requires = [ "gdown", - "imgviz>=0.11", + "imgviz>=1.7.5", "matplotlib", "natsort>=7.1.0", "numpy",