【问题标题】:Why did my new python edited photo lose brightness?为什么我的新 python 编辑照片失去了亮度?
【发布时间】: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()

原图:this is the origianl image

输出图片:enter image description here

【问题讨论】:

标签: python image python-imaging-library image-editing


【解决方案1】:

blend2 = Image.blend(img, img2, 0.5)

第三个参数 0.5 是每一层的 alpha 级别。本质上,您将每个图层设置为 50% 透明。这有效地降低了亮度。相反,你应该读入img1img2,然后将第二个的红色层设置为第一个的红色层。

img2[R] = img1[R]

【讨论】:

  • 它现在给了我这个错误:TypeError: 'Image' object is not subscriptable
  • 对不起。尝试执行 img1.split() 和 img2().split,然后更改我的代码示例中的变量以组合拆分图像。然后从数组中创建一个新图像。
猜你喜欢
  • 2012-06-17
  • 2016-09-28
  • 2021-03-20
  • 1970-01-01
  • 2017-03-23
  • 1970-01-01
  • 1970-01-01
  • 2012-12-14
  • 1970-01-01
相关资源
最近更新 更多