【发布时间】:2011-01-11 07:03:13
【问题描述】:
我正在使用 numpy 来构建像素数组。一个 800x600 的图像是一个 uint8、800x600x3 的 3 维数组。我也有一个具有固定模式的类似数组(棋盘格,请参阅here)。我有另一个数组,800x600 的掩码值。在掩码为零的情况下,我想将图案像素复制到图像像素。在掩码不为零的情况下,我想不理会图像像素。
>>> image.shape
(800, 600, 3)
>>> chex.shape
(800, 600, 3)
>>> mask.shape
(800, 600)
感觉应该可以了:
image[mask == 0,...] = chex
但给出“ValueError: array is not broadcastable to correct shape”。
如何将 chex 像素复制到掩码为零的图像像素?
【问题讨论】:
标签: python image-processing numpy