对图片进行高斯滤波,然后再与原图按照一定比例相加.
import cv2
import numpy as np
from skimage.exposure import exposure
src = cv2.imread(r"7.jpg")
cv2.namedWindow("input", cv2.WINDOW_AUTOSIZE)
cv2.moveWindow("input", 1, 50)
cv2.imshow("input", src)
blur_img = cv2.GaussianBlur(src, (0, 0), 5)
a = 1.3 # 原图比重
b = -0.52 # 高斯模糊图片比重
c = 5 # 这个数值越高,图像越亮
usm = cv2.addWeighted(src, a, blur_img, b, c)
hsv = cv2.cvtColor(usm, cv2.COLOR_RGB2HSV)
print(hsv.shape)
random_br = 1.3
mask = hsv[:, :, 2] * random_br > 255 # hsv[:, :, 2] * random_br HSV 乘以一个系数, 如果大于 255 那就保留其掩码为 mask
v_channel = np.where(mask, 255, hsv[:, :, 2] * random_br) # 这一步就把掩码上 有True的地方用255替代
hsv[:, :, 2] = v_channel # 赋值回来
usm = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB) # 转成RGB
cv2.imwrite('www.jpg', usm)
# figure_adjust_high = exposure.adjust_gamma(usm, 0.5)