MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / mask_to_bbox

Function mask_to_bbox

preprocess/track_FrameINO.py:194–211  ·  view source on GitHub ↗
(mask)

Source from the content-addressed store, hash-verified

192
193
194def mask_to_bbox(mask):
195 # Mask shape is (1, height, width)
196 mask = mask[0]
197
198 # Find rows and columns where the mask is not zero
199 rows = np.any(mask, axis=1)
200 cols = np.any(mask, axis=0)
201
202 if not rows.any() or not cols.any():
203 # If there are no nonzero values in the mask, return None
204 return None
205
206 # Find the bounding box's edges
207 ymin, ymax = np.where(rows)[0][[0, -1]]
208 xmin, xmax = np.where(cols)[0][[0, -1]]
209
210 # Return the bounding box coordinates
211 return int(xmin), int(ymin), int(xmax), int(ymax)
212
213
214

Callers 1

SAM2_RefineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected