MCPcopy Create free account
hub / github.com/apple/ml-4m / get_binary_masks

Method get_binary_masks

fourm/data/modality_transforms.py:517–538  ·  view source on GitHub ↗

Creates the binary mask of each instance in the sample.

(self, sample)

Source from the content-addressed store, hash-verified

515 return flipped_sample
516
517 def get_binary_masks(self, sample):
518 """ Creates the binary mask of each instance in the sample.
519 """
520 if self.max_instance_n is None:
521 max_instance_n = len(sample)
522 else:
523 max_instance_n = self.max_instance_n
524 masks = np.zeros((max_instance_n, self.mask_size, self.mask_size))
525 bboxes = np.zeros((max_instance_n, 4))
526 valid = np.full(max_instance_n, False)
527 for i, instance in enumerate(sample):
528 bbox = self.get_bbox(instance)
529 min_h, min_w, max_h, max_w = bbox
530 instance_copy = instance.copy()
531 mask = np.zeros((self.mask_size, self.mask_size), dtype=np.uint8)
532 instance_copy[:,:,0] = (instance_copy[:,:,0] - min_w) / (max_w - min_w) * self.mask_size
533 instance_copy[:,:,1] = (instance_copy[:,:,1] - min_h) / (max_h - min_h) * self.mask_size
534 cv2.drawContours(mask, [instance_copy], 0, (255), thickness=cv2.FILLED)
535 masks[i] = mask / 255.0
536 bboxes[i] = np.array(bbox)
537 valid[i] = True
538 return masks, bboxes, valid
539
540 def load(self, path):
541 sample = np.load(path, allow_pickle=True)

Callers 1

postprocessMethod · 0.95

Calls 1

get_bboxMethod · 0.95

Tested by

no test coverage detected