I am working on a photo editing project and I am curious about why did my new photo lose it's brightness. The program shoud get 2 photos out of the original one. One of them shoud contain only RED value and the other shoud contain BLUE and GREEN values. But when I put them back together the brightness is not the same as in original picture.
Here is my code:
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()
Original image : this is the origianl image
Output image: enter image description here
blend2 = Image.blend(img, img2, 0.5)
The third argument, 0.5, is the alpha level of each layer. Essentially, you are setting each layer to be 50% transparent. This effectively reduces the brightness. Instead, you should read in img1
and img2
and then set the red layer of the second to the red layer of the first.
img2[R] = img1[R]