1. 需求
把mask叠加到原图上,像这个样子。
实现很简单,用cv2.addWeighted()就OK。
但是我就不想调现成函数,就不想import cv2(主要还是记不住函数名)
2. 用np实现
思路: img_with_mask = weight * img + (1-weight) * mask
patch_img_path = "TCGA-S3-AA15-01Z-00-DX1.png"
patch_mask_path = "TCGA-S3-AA15-01Z-00-DX1m.png"
img = io.imread(patch_img_path)
mask = io.imread(patch_mask_path) # np.unique(mask)的结果是1和2
mask_1 = np.zeros_like(img)
mask_1[mask == 1, 1] = 255 # green
mask_2 = np.zeros_like(img)
mask_2[mask == 2, 0:2] = 255 # yellow
img_add_weight = 0.7 * img + 0.3 * (mask_2 + mask_1)
img_add_weight /= 255.0
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(6,4), subplot_kw&