Example of how to adjust the brightness of a PS Image Using Python.
This article describes how to adjust the brightness of a PS Image Using Python. We will share this with you for your reference. The details are as follows:
Here we use Python to adjust the brightness of PS images:
We know that the general non-linear RGB brightness adjustment is only achieved by adding and reducing a certain amount based on the original R, G, and B values, the brightness adjustment principle of PS must be found from the previous formula. We will adjust the formula for positive brightness:
RGB = RGB + (255-RGB) * value/255
Convert
RGB = (RGB * (255-value) + 255 * value)/255,
If the value is 1, the maximum value is 255.
RGB = RGB * (1-value) + 255 * value,
What can we see? Anyone who knows about image synthesis knows this formula. In fact, the brightness adjustment of PS adopts the Alpha synthesis method. Here the value is Alpha, and the first part of the formula is RGB * (1-value) the image part is followed by the 255 * value part, which is a white shadow layer. The greater the brightness, the greater the Alpha of the Shadow layer, the more the image is discussed, and vice versa. The negative adjustment of brightness is done by a black shadow layer. Negative 100% is all black. The full picture is displayed only when Alpha = 0, or the brightness value is 0.
Brightness adjustment, using the compositing Layer
If alpha is greater than 0, it is equivalent to merging with a white mask layer.
RGB = RGB * (1-alpha) + 255 * alpha;
If alpha is less than 0, it is equivalent to merging with a black mask layer.
RGB = RGB * (1 + alpha) + 0 * alpha;
import matplotlib.pyplot as pltfrom skimage import iofile_name='D:/Visual Effects/PS Algorithm/4.jpg';img=io.imread(file_name)# -255.0 - 255.0 alpha -1.0 - 1.0Increment = 105.0;alpha = Increment/255.0;def Illumi_adjust(alpha, img): if alpha > 0 : img_out = img * (1 - alpha) + alpha * 255.0 else: img_out = img * (1 + alpha) return img_out/255.0img_out = Illumi_adjust(alpha, img)plt.figure()plt.imshow(img)plt.axis('off')plt.figure(2)plt.imshow(img_out)plt.axis('off')plt.show()
Source image
Brightness increase: