66 BinaryMaskSegmentation ,
77 RLEDecoderEncoder ,
88)
9- from labelformat .model .bounding_box import BoundingBox
9+ from labelformat .model .bounding_box import BoundingBox , BoundingBoxFormat
1010
1111
1212class TestBinaryMaskSegmentation :
@@ -25,20 +25,23 @@ def test_from_binary_mask(self) -> None:
2525
2626 def test_from_rle (self ) -> None :
2727 binary_mask_segmentation = BinaryMaskSegmentation .from_rle (
28- rle_row_wise = [1 , 1 , 4 , 2 , 1 , 3 , 2 , 1 , 5 ],
28+ rle_row_wise = [6 , 1 , 4 , 2 , 1 , 3 , 2 , 1 ],
2929 width = 5 ,
3030 height = 4 ,
3131 bounding_box = None ,
3232 )
3333 assert binary_mask_segmentation .width == 5
3434 assert binary_mask_segmentation .height == 4
35- assert binary_mask_segmentation .bounding_box == BoundingBox (0 , 0 , 4 , 2 )
35+ assert binary_mask_segmentation .bounding_box == BoundingBox (0 , 1 , 5 , 4 )
36+ assert binary_mask_segmentation .bounding_box .to_format (
37+ format = BoundingBoxFormat .XYWH
38+ ) == [0 , 1 , 5 , 3 ]
3639 expected : NDArray [np .int_ ] = np .array (
3740 [
41+ [0 , 0 , 0 , 0 , 0 ],
3842 [0 , 1 , 0 , 0 , 0 ],
3943 [0 , 1 , 1 , 0 , 1 ],
4044 [1 , 1 , 0 , 0 , 1 ],
41- [0 , 0 , 0 , 0 , 0 ],
4245 ],
4346 dtype = np .int_ ,
4447 )
@@ -142,7 +145,7 @@ def test_compute_bbox_from_rle() -> None:
142145 width = 4 ,
143146 height = 3 ,
144147 )
145- assert bbox == BoundingBox (xmin = 0 , ymin = 0 , xmax = 3 , ymax = 2 )
148+ assert bbox == BoundingBox (xmin = 0 , ymin = 0 , xmax = 4 , ymax = 3 )
146149
147150 # 0011
148151 # 0000
@@ -151,7 +154,7 @@ def test_compute_bbox_from_rle() -> None:
151154 width = 4 ,
152155 height = 2 ,
153156 )
154- assert bbox == BoundingBox (xmin = 2 , ymin = 0 , xmax = 3 , ymax = 0 )
157+ assert bbox == BoundingBox (xmin = 2 , ymin = 0 , xmax = 4 , ymax = 1 )
155158
156159 # 0011
157160 # 1000
@@ -160,12 +163,12 @@ def test_compute_bbox_from_rle() -> None:
160163 width = 4 ,
161164 height = 2 ,
162165 )
163- assert bbox == BoundingBox (xmin = 0 , ymin = 0 , xmax = 3 , ymax = 1 )
166+ assert bbox == BoundingBox (xmin = 0 , ymin = 0 , xmax = 4 , ymax = 2 )
164167
165168 # 1111
166169 bbox = binary_mask_segmentation ._compute_bbox_from_rle (
167170 rle_row_wise = [0 , 4 ],
168171 width = 4 ,
169172 height = 1 ,
170173 )
171- assert bbox == BoundingBox (xmin = 0 , ymin = 0 , xmax = 3 , ymax = 0 )
174+ assert bbox == BoundingBox (xmin = 0 , ymin = 0 , xmax = 4 , ymax = 1 )
0 commit comments