【发布时间】:2021-06-07 13:11:55
【问题描述】:
我正在做一个照片编辑项目,我很好奇为什么我的新照片会失去亮度。该程序应该从原始照片中获取 2 张照片。其中一个应仅包含 RED 值,而另一个应包含 BLUE 和 GREEN 值。但是当我将它们重新组合在一起时,亮度与原始图片中的不同。
这是我的代码:
import io, re, requests
from PIL import Image, ImageOps, ImageEnhance, ImageChops
import cv2
import numpy as np
imgpth ='image.jpg'
#red image
img2 = Image.open(imgpth).convert('RGB')
source = img2.split()
R, G, B = 0, 1, 2
out = source[G].point(lambda i: i * 0)
source[G].paste(out, None, None)
out = source[B].point(lambda i: i * 0)
source[B].paste(out, None, None)
img2 = Image.merge(img2.mode, source)
#green and blue image
img = Image.open(imgpth).convert('RGB')
source = img.split()
R, G, B = 0, 1, 2
out = source[R].point(lambda i: i * 0)
source[R].paste(out, None, None)
img = Image.merge(img.mode, source)
blend2 = Image.blend(img, img2, 0.5)
blend2.show()
【问题讨论】:
-
您的混合使用 0.5
Image.blend(img, img2, 0.5)的 alpha - 这将两个图像的亮度减半。您需要将图像添加在一起。
标签: python image python-imaging-library image-editing