我有一个黑白图像和相同的图像与颜色描边。我想要做的是提取颜色笔画,模糊它们,然后将原始图像与模糊图像混合。我通过相互减去两个图像来提取颜色笔画,但是我在黑色背景上获得这些颜色笔画,而我需要它们在白色上以与原始笔画混合。这是我的代码部分:在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