作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<分区>
我有两个形状为 (256, 256, 4) 的 numpy 数组。我想将第四个 256 x 256 平面视为 alpha 级别,并导出这些阵列已被覆盖的图像。
代码示例:
import numpy as np
from skimage import io
fg = np.ndarray((256, 256, 4), dtype=np.uint8)
one_plane = np.random.standard_normal((256, 256)) * 100 + 128
fg[:,:,0:3] = np.tile(one_plane, 3).reshape((256, 256, 3), order='F')
fg[:, :, 3] = np.zeros((256, 256), dtype=np.uint8)
fg[0:128, 0:128, 3] = np.ones((128, 128), dtype=np.uint8) * 255
fg[128:256, 128:256, 3] = np.ones((128, 128), dtype=np.uint8) * 128
bg = np.ndarray((256, 256, 4), dtype=np.uint8)
bg[:,:,0:3] = np.random.standard_normal((256, 256, 3)) * 100 + 128
bg[:, :, 3] = np.ones((256, 256), dtype=np.uint8) * 255
io.imsave('test_fg.png', fg)
io.imsave('test_bg.png', bg)
这会创建两个图像,fg:
和背景:
:
我希望能够将 fg 叠加到 bg 上。也就是说,最终图像应该在左上角有灰色(因为 fg 的 alpha 为 1),在右下角混合了灰色和彩色噪声,在其他象限中有纯色噪声。我正在寻找类似 add 函数的东西,它可以给我一个新的 np 数组。
请注意,我不认为这与 this answer 相同,它使用 matplotlib.pyplot.plt 来覆盖图像和摆弄彩色 map 。我认为我不需要在这里摆弄彩色 map ,但也许答案是我需要。
我希望操作返回一个新的 np.array 的原因是因为我想用许多图像迭代地执行此操作,按顺序叠加。
我是一名优秀的程序员,十分优秀!