[英]IndexError with PIL Image and Numpy Array (Alpha Channel Blending)
嘗試運行此程序時遇到錯誤。 它獲取一個“標記”圖像,並將標記的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'是偏移的,因為標記在特定的矩形中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.