Example of how to adjust the brightness of a PS Image Using Python.

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.