I have an rgb image (rgb), and I want to set the luminance to make sure that it's constant. I first check the luminance of the original image (greyrgb). I then convert the image to Lab, then setting the L value to 50 (lab50), before converting back to rgb (rgb50). I then compute the luminance of the resulting image (greyrgb50), but it is not constant - it actually seems worse.
import numpy as np
from skimage import color
import matplotlib.pyplot as plt
rgb = np.loadtxt("my_image.txt").reshape((512,512,4))
greyrgb = color.rgb2gray(rgb)
lab = color.rgb2lab(rgb)
lab50 = lab
lab50[:,:,0] = 50
rgb50 = color.lab2rgb(lab50)
greyrgb50 = color.rgb2gray(rgb50)
I find that when I set the luminance to different values, the luminance of the resultant rgb image still varies slightly. Have I set the luminance incorrectly, or am I computing the luminance of the final rgb image incorrectly?