使用cv2调整图片亮度和饱和度,比PS还方便!
import numpy as np
import cv2
# 加载图片 读取彩色图像归一化且转换为浮点型
image = cv2.imread('./imgs/2.jpg', cv2.IMREAD_COLOR).astype(np.float32) / 255.0
# 颜色空间转换 BGR转为HLS
hlsImg = cv2.cvtColor(image, cv2.COLOR_BGR2HLS)
# 滑动条最大值
MAX_VALUE = 10
MAX_VALUE2 = 100
# 滑动条最小值
MIN_VALUE = 0
# 调节饱和度和亮度的窗口
cv2.namedWindow("lightness and saturation", cv2.WINDOW_GUI_NORMAL)
# 创建滑动块
cv2.createTrackbar("lightness", "lightness and saturation",
MIN_VALUE, MAX_VALUE, lambda x:x)
cv2.createTrackbar("saturation", "lightness and saturation",
MIN_VALUE, MAX_VALUE2, lambda x:x)
# 调整饱和度和亮度
while True:
# 复制原图
hlsCopy = np.copy(hlsImg)
# 得到 lightness 和 saturation 的值
lightness = cv2.getTrackbarPos('lightness', 'lightness and saturation')
saturation = cv2.getTrackbarPos('saturation', &