import cv2 import copy import numpy as np from matplotlib import pyplot as plt
读入图像并显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
image_list = [ 'images/Balloon-01.jpg', 'images/Balloon-02.jpg', 'images/Balloon-03.jpg', 'images/Balloon-04.jpg', ] images = np.stack([cv2.imread(name) for name in image_list])
# show sequence plt.figure(figsize=(16, 12)) for i, im inenumerate(images): plt.subplot(2,2,i+1) im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) plt.xticks([]) plt.yticks([]) plt.title('image-0{}'.format(i)) plt.imshow(im)
# 计算图像的拉普拉斯金字塔 images_LPyrs = [] for i inrange(len(images)): LPyrs = laplace_pyramid(images[i], layers_nr) images_LPyrs.append(LPyrs) layers_info_print(images_LPyrs[0], 'images_LPyrs')
# 计算权重的高斯金字塔 weight_GPyrs = [] for i inrange(len(weights)): GPyrs = gaussian_pyramid(weights[i], layers_nr) weight_GPyrs.append(GPyrs) layers_info_print(weight_GPyrs[0], 'weight_GPyrs')
# 计算融合的拉普拉斯金字塔 fused_LPyrs = [np.sum([images_LPyrs[k][n] * np.atleast_3d(weight_GPyrs[k][layers_nr - n -1]) for k inrange(len(images))], axis=0) for n inrange(layers_nr)]
Mertens, Tom, Jan Kautz, and Frank Van Reeth. “Exposure fusion.” Computer Graphics and Applications, 2007. PG’07. 15th Pacific Conference on. IEEE, 2007.