【发布时间】:2016-03-14 04:57:43
【问题描述】:
我在尝试运行此程序时遇到错误。它采用“标记”图像并将标记的 RGB 值与原始图像的 RGB 值混合。它使用 PIL 和 Numpy 使用图像的 Alpha 通道值混合两个几乎相同图像的 RGB 值。我遇到的错误是:
File "wip.py", line 87, in mark
apixel[channel] = ((apixel[channel]*(apixel[3]/255))+(oapixel[channel]*(oapixel[3]/255)))/2
IndexError: index 3 is out of bounds for axis 0 with size 3
而相关代码为:
img = np.array(marked)
orig_img = np.array(original_image)
for x in range(wmark_w):
for y in range(wmark_h):
if img[x][y][3] < 255:
apixel = img[x][y]
oapixel = orig_img[x+int(0.02*width)][y+int(0.02*width)]
for channel in range(4):
apixel[channel] = ((apixel[channel]*(apixel[3]/255))+(oapixel[channel]*(oapixel[3]/255)))/2
marked = PIL.Image.fromarray(img)
del img; del orig_img
'oapixel' 是偏移的,因为标记位于特定的矩形中
【问题讨论】:
标签: python numpy python-imaging-library