【发布时间】:2019-10-16 15:19:14
【问题描述】:
如何将二进制蒙版图像数组 (this_mask - shape:4,4) 与预定义的颜色数组 (mask_color, shape:3) 结合起来
this_mask = np.array([
[0,1,0,0],
[0,0,0,0],
[0,0,0,0],
[0,0,0,0],
])
this_mask.shape # (4,4)
mask_color = np.array([128, 128, 64])
mask_color.shape # (3)
要获得一个新的彩色蒙版图像数组(this_mask_colored, shape:4,4,3)?
this_mask_colored = # do something with `this_mask` and `mask_color`
# [
# [
# [0,128,0],
# [0,0,0],
# [0,0,0],
# [0,0,0]
# ],
# [
# [0,128,0],
# [0,0,0],
# [0,0,0],
# [0,0,0]
# ],
# [
# [0,64,0],
# [0,0,0],
# [0,0,0],
# [0,0,0]
# ],
# ]
this_mask_colored.shape # (4,4,3)
我尝试逐像素循环,当图像为 225x225 时会很慢,最好的方法是什么?
对于每张图片,我都有多层蒙版,每个蒙版层需要有不同的预定义颜色。
【问题讨论】:
标签: python numpy image-processing