File size: 405 Bytes
c336648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from __future__ import annotations

import numpy as np
import cv2
from PIL import Image


def resize_with_mask(
    img: Image.Image, w, h, t, b, l, r,
) -> tuple[Image.Image, Image.Image]:
    new_img = Image.new("RGB", (w, h))
    new_img.paste(img, (l, t))

    mask = Image.new("L", (w, h), 255)
    mask_none = Image.new("L", (r-l, b-t), 0)
    mask.paste(mask_none, (l, t))
    return new_img, mask