@@ -111,6 +111,8 @@ def write_mask(
111
111
inst_map : np .ndarray ,
112
112
type_map : np .ndarray = None ,
113
113
sem_map : np .ndarray = None ,
114
+ compute_centorids : bool = False ,
115
+ compute_bboxes : bool = False ,
114
116
) -> None :
115
117
"""
116
118
Write multiple masks to .mat file.
@@ -125,26 +127,34 @@ def write_mask(
125
127
The inst_map to be written.
126
128
sem_map : np.ndarray, optional
127
129
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.
128
134
"""
129
135
path = Path (path )
130
136
if not path .suffix == ".mat" :
131
137
raise ValueError (f"File suffix needs to be '.mat'. Got { path .suffix } ." )
132
138
133
139
inst_map = fix_duplicates (inst_map )
134
- centroids = get_inst_centroid (inst_map )
135
140
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
- )
140
141
141
142
res = {
142
143
"inst_map" : inst_map ,
143
144
"inst_type" : inst_types ,
144
- "inst_centroid" : centroids ,
145
- "inst_bbox" : bboxes ,
146
145
}
147
146
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
+
148
158
if type_map is not None :
149
159
res ["type_map" ] = type_map
150
160
0 commit comments