brails.processors.vlm_segmenter.segment_anything.automatic_mask_generator module
- class brails.processors.vlm_segmenter.segment_anything.automatic_mask_generator.SamAutomaticMaskGenerator(model, points_per_side=32, points_per_batch=64, pred_iou_thresh=0.88, stability_score_thresh=0.95, stability_score_offset=1.0, box_nms_thresh=0.7, crop_n_layers=0, crop_nms_thresh=0.7, crop_overlap_ratio=0.3413333333333333, crop_n_points_downscale_factor=1, point_grids=None, min_mask_region_area=0, output_mode='binary_mask')
Bases:
object- generate(image)
Generates masks for the given image.
- Parameters:
image (np.ndarray) – The image to generate masks for, in HWC uint8 format.
- Returns:
- A list over records for masks. Each record is
- a dict containing the following keys:
- segmentation (dict(str, any) or np.ndarray): The mask. If
output_mode=’binary_mask’, is an array of shape HW. Otherwise, is a dictionary containing the RLE.
bbox (list(float)): The box around the mask, in XYWH format. area (int): The area in pixels of the mask. predicted_iou (float): The model’s own prediction of the mask’s
quality. This is filtered by the pred_iou_thresh parameter.
- point_coords (list(list(float))): The point coordinates input
to the model to generate this mask.
- stability_score (float): A measure of the mask’s quality. This
is filtered on using the stability_score_thresh parameter.
- crop_box (list(float)): The crop of the image used to generate
the mask, given in XYWH format.
- Return type:
list(dict(str, any))
- static postprocess_small_regions(mask_data, min_area, nms_thresh)
Removes small disconnected regions and holes in masks, then reruns box NMS to remove any new duplicates.
Edits mask_data in place.
Requires open-cv as a dependency.