File size: 569 Bytes
f698f1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import numpy as np
import cv2

def overlay_mask(rgb_image: np.ndarray, mask: np.ndarray, alpha=0.45):
    # mask: [H,W] 0/1; resize mask to match image
    h, w = rgb_image.shape[:2]
    mask_rs = cv2.resize(mask.astype(np.uint8), (w, h), interpolation=cv2.INTER_NEAREST)

    overlay = rgb_image.copy()
    # red overlay where crack
    red = np.zeros_like(rgb_image)
    red[..., 0] = 255

    overlay = np.where(mask_rs[..., None] == 1,
                       (alpha * red + (1 - alpha) * overlay).astype(np.uint8),
                       overlay)
    return overlay