creatumlibre.graphics.filters.enhancers
1# pylint: disable = no-member 2import cv2 3import numpy as np 4 5 6def adjust_brightness(image, factor): 7 """Adjust brightness of the image.""" 8 image = cv2.convertScaleAbs( 9 image, alpha=factor, beta=0 10 ) # Proper brightness scaling 11 return image 12 13 14def adjust_saturation(image, factor): 15 """Adjust saturation of the image.""" 16 hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) 17 hsv[..., 1] = np.clip(hsv[..., 1] * factor, 0, 255) # Adjust saturation channel 18 return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) 19 20 21def adjust_contrast(image, factor): 22 """Adjust contrast of the image.""" 23 return cv2.convertScaleAbs(image, alpha=factor, beta=0) # Adjust contrast 24 25 26def adjust_rgb(image, value, channel): 27 """Adjust RGB channels of the image.""" 28 if channel == "Red": 29 image[..., 2] = np.clip( 30 image[..., 2] + value * 255, 0, 255 31 ) # Adjust Red channel 32 elif channel == "Green": 33 image[..., 1] = np.clip( 34 image[..., 1] + value * 255, 0, 255 35 ) # Adjust Green channel 36 elif channel == "Blue": 37 image[..., 0] = np.clip( 38 image[..., 0] + value * 255, 0, 255 39 ) # Adjust Blue channel 40 return image
def
adjust_brightness(image, factor):
7def adjust_brightness(image, factor): 8 """Adjust brightness of the image.""" 9 image = cv2.convertScaleAbs( 10 image, alpha=factor, beta=0 11 ) # Proper brightness scaling 12 return image
Adjust brightness of the image.
def
adjust_saturation(image, factor):
15def adjust_saturation(image, factor): 16 """Adjust saturation of the image.""" 17 hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) 18 hsv[..., 1] = np.clip(hsv[..., 1] * factor, 0, 255) # Adjust saturation channel 19 return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
Adjust saturation of the image.
def
adjust_contrast(image, factor):
22def adjust_contrast(image, factor): 23 """Adjust contrast of the image.""" 24 return cv2.convertScaleAbs(image, alpha=factor, beta=0) # Adjust contrast
Adjust contrast of the image.
def
adjust_rgb(image, value, channel):
27def adjust_rgb(image, value, channel): 28 """Adjust RGB channels of the image.""" 29 if channel == "Red": 30 image[..., 2] = np.clip( 31 image[..., 2] + value * 255, 0, 255 32 ) # Adjust Red channel 33 elif channel == "Green": 34 image[..., 1] = np.clip( 35 image[..., 1] + value * 255, 0, 255 36 ) # Adjust Green channel 37 elif channel == "Blue": 38 image[..., 0] = np.clip( 39 image[..., 0] + value * 255, 0, 255 40 ) # Adjust Blue channel 41 return image
Adjust RGB channels of the image.