numpy 实现mask叠加原图

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={"x
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值