【发布时间】:2019-10-18 14:41:57
【问题描述】:
我正在尝试使用 numpy 将二进制掩码应用于 RGB 图像
我找到了这个https://stackoverflow.com/a/26843467/4628384,但我还没有写评论的权限。 无论如何,我遇到了问题;非常感谢任何帮助。
def masktoRGB(self,image,image_mask):
# create mask with same dimensions as image
mask = np.zeros_like(image)
# copy your image_mask to all dimensions (i.e. colors) of your image
for i in range(3):
mask[:,:,i] = image_mask.copy()
# apply the mask to your image
# tried to swap axes, not a solution
#image = image.swapaxes(0,1)
#this gives the error:
masked_image = image[mask]
print(mask.shape)
print(image.shape)
print(image_mask.shape)
return masked_image
这给了我:
IndexError:索引 213 超出轴 0 的范围,大小为 212
打印输出:
(188, 212, 3) (188, 212, 3) (188, 212)
image和image_mask是同一张图片,只不过第一个是RGB,第二个是mode L
【问题讨论】:
标签: python-3.x numpy python-imaging-library