我有一個黑白圖像和相同的圖像與顏色描邊。我想要做的是提取顏色筆畫,模糊它們,然後將原始圖像與模糊圖像混合。我通過相互減去兩個圖像來提取顏色筆畫,但是我在黑色背景上獲得這些顏色筆畫,而我需要它們在白色上以與原始筆畫混合。這是我的代碼部分:在Python中提取顏色表單圖像
def imageblur(cimg):
return cv2.blur(cimg, (50, 50))
bw = glob('path1')
colorful = glob('path2')
output_dir = 'path3'
index = 0
for i,j in zip(bw, colorful):
img1 = cv2.imread(i)
img2 = cv2.imread(j)
color = cv2.subtract(img1,img2)
color = imageblur(color)
mask = Image.fromarray(np.uint8(color))
img = Image.fromarray(np.uint8(img1))
im = Image.blend(img, mask, 0.5)
#color = img1 + color
im.save(os.path.join(output_dir, str(index) + '.jpg'))
index += 1
print(index)
樣品images
你是怎麼想到要發生什麼? 255(白色) - 255(白色)= 0(黑色)。任何自己的想法,或者你只是想嘗試一種解決方案? – Piglet