@@ -111,6 +111,8 @@ def write_mask(
111111 inst_map : np .ndarray ,
112112 type_map : np .ndarray = None ,
113113 sem_map : np .ndarray = None ,
114+ compute_centorids : bool = False ,
115+ compute_bboxes : bool = False ,
114116 ) -> None :
115117 """
116118 Write multiple masks to .mat file.
@@ -125,26 +127,34 @@ def write_mask(
125127 The inst_map to be written.
126128 sem_map : np.ndarray, optional
127129 The inst_map to be written.
130+ compute_centroids : bool, optional
131+ Flag to tompute instance centorids.
132+ compute_bboxes : bool, optional
133+ Flag to tompute instance bboxes.
128134 """
129135 path = Path (path )
130136 if not path .suffix == ".mat" :
131137 raise ValueError (f"File suffix needs to be '.mat'. Got { path .suffix } ." )
132138
133139 inst_map = fix_duplicates (inst_map )
134- centroids = get_inst_centroid (inst_map )
135140 inst_types = get_inst_types (inst_map , type_map )
136- inst_ids = list (np .unique (inst_map )[1 :])
137- bboxes = np .array (
138- [bounding_box (np .array (inst_map == id_ , np .uint8 )) for id_ in inst_ids ]
139- )
140141
141142 res = {
142143 "inst_map" : inst_map ,
143144 "inst_type" : inst_types ,
144- "inst_centroid" : centroids ,
145- "inst_bbox" : bboxes ,
146145 }
147146
147+ if compute_centorids :
148+ centroids = get_inst_centroid (inst_map )
149+ res ["inst_centroid" ] = centroids
150+
151+ if compute_bboxes :
152+ inst_ids = list (np .unique (inst_map )[1 :])
153+ bboxes = np .array (
154+ [bounding_box (np .array (inst_map == id_ , np .uint8 )) for id_ in inst_ids ]
155+ )
156+ res ["inst_bbox" ] = bboxes
157+
148158 if type_map is not None :
149159 res ["type_map" ] = type_map
150160
0 commit comments