def seg_by_box(
    raw_image_rgb: np.ndarray,
    boxes_filt: np.ndarray,
    segmentor,
    point_coords: np.ndarray = None,
) -> np.ndarray:
    """
    Segment regions within specified boxes in an RGB image.

    Args:
        raw_image_rgb (np.ndarray): The input RGB image.
        boxes_filt (np.ndarray): An array of bounding boxes in the format [x1, y1, x2, y2].
        segmentor: The segmentor object used for segmentation.
        point_coords (np.ndarray): Point coordinates (default: None).

    Returns:
        np.ndarray: The segmented mask image with regions within the specified boxes.
    """
    h, w = raw_image_rgb.shape[:2]

    # Set the image for the segmentor
    segmentor.set_image(raw_image_rgb)

    # Transform the bounding boxes to match the image dimensions
    transformed_boxes = segmentor.transform.apply_boxes_torch(torch.from_numpy(np.expand_dims(boxes_filt, 0)), (h, w)).cuda()

    # Predict masks, scores, etc.
    masks, scores, _ = segmentor.predict_torch(
        point_coords=None,
        point_labels=None,
        boxes=transformed_boxes,
        multimask_output=True,
    )

    # Sum the multi-mask outputs to obtain a single mask
    mask = masks[0]
    mask = torch.sum(mask, dim=0)
    mask = mask.cpu().numpy().astype(np.uint8)
    mask_image = mask * 255

    return mask_image

    Segment regions within specified boxes in an RGB image.

    Args:
        raw_image_rgb (np.ndarray): The input RGB image.
        boxes_filt (np.ndarray): An array of bounding boxes in the format [x1, y1, x2, y2].
        segmentor: The segmentor object used for segmentation.
        point_coords (np.ndarray): Point coordinates (default: None).

    Returns:
        np.ndarray: The segmented mask image with regions within the specified boxes.
    
scripts/easyphoto_utils/tryon_utils.py