多尺度图像细节提升算法python实现
分为了多个尺度的细节层,然后与原图相加增强细节信息。
论文:DARK IMAGE ENHANCEMENT BASED ON PAIRWISE TARGET CONTRAST AND MULTI-SCALE DETAIL BOOSTING
https://www.cnblogs.com/Imageshop/p/7895008.html
import cv2
import numpy as np
from matplotlib import pyplot as plt
from d import float2int8
def show_rgb(im,r,g,b):
fig = plt.figure()
ax1 = fig.add_subplot(221)
ax1.imshow(im)
ax2 = fig.add_subplot(222)
ax2.imshow(r, )
ax3 = fig.add_subplot(223)
ax3.imshow(g, )
ax4 = fig.add_subplot(224)
ax4.imshow(b, )
plt.show()
if __name__ == "__main__":
file = r'D:\dataset\wang\ccm\2022-06-21-15-10-53_raw_wb.png'
file = r'D:\dataset\noise_img\pp.jpg'
file = r'D:\dataset\ebi_test\1\IMG_0005.jpg'
file = r'D:\dataset\noise_img\015.jpg'
file = r'D:\dataset\dang_yingxiangzhiliangceshi\img\IMG_0008.jpg'
file = r'D:\code\data\kodak\kodim21.png'
image = cv2.imread(file) # 根据路径读取一张图片
h, w, c = image.shape
# h = 600
# w = 600
# image = cv2.resize(image, [h, w])
radiu = 5
B1 = cv2.GaussianBlur(image, (radiu, radiu), 1.0, 1.0)
B2 = cv2.GaussianBlur(image, (2*radiu-1, 2*radiu-1), 2.0, 2.0)
B3 = cv2.GaussianBlur(image, (4*radiu-1, 4*radiu-1), 4.0, 4.0)
B1 = cv2.blur(image, (radiu, radiu))
B2 = cv2.blur(image, (2 * radiu - 1, 2 * radiu - 1))
B3 = cv2.blur(image, (4 * radiu - 1, 4 * radiu - 1))
D1 = image - B1.astype(np.int32)
D2 = B1 - B2.astype(np.int32)
D3 = B2 - B3.astype(np.int32)
factor = 1
w1 = 0.5 * factor
w2 = 0.5 * factor
w3 = 0.25 * factor
show_rgb(image[..., ::-1], B1[..., ::-1], B2[..., ::-1], B3[..., ::-1])
print(B1.dtype, D1.dtype)
D = D1*(D1 > 0) * (1-w1) + D1*(D1 <= 0) * (1+w1) + w2*D2 + w3*D3
im_res = image + D
im_res = np.clip(im_res, 0, 255)
im_res = im_res.astype(np.uint8)
show_rgb(im_res[..., ::-1], np.abs(D1[..., ::-1]) + 20, np.abs(D2[..., ::-1]) + 20, np.abs(D3[..., ::-1]) + 20)
DD = D1 * w1 + w2 * D2 + w3 * D3
im_res2 = image + DD
im_res2 = np.clip(im_res2, 0, 255).astype(np.uint8)
im_res3 = B1 + DD
im_res3 = np.clip(im_res3, 0, 255).astype(np.uint8)
show_rgb(image[..., ::-1], im_res[..., ::-1], im_res2[..., ::-1], im_res3[..., ::-1])
cv2.imwrite('multi_kodim11.jpg', im_res)