1 HSV
HSV可进行RGB图像到HSV色度空间的变换,用高分辨率的图像代替颜色亮度值波段,自动用最近邻、双线性或三次卷积技术将色度和饱和度重采样到高分辨率像元尺寸,然后再将图像变换回RGB色度空间。输出的RGB图像的像元将与高分辨率数据的像元大小相同。
# https://blog.csdn.net/weixin_45364562/article/details/107130219
def hsv_imgfusion(low, high):
"""
HSV融合低分辨率和高分辨率图像 H色调,S饱和度,V明度
输入:图像三维数组
返回:可绘出图像的utf-8格式的三维数组
"""
hgt, wth = high.shape[:2]
data_low = cv2.resize(low, (wth, hgt), interpolation=cv2.INTER_CUBIC) # 重采样
h_low, s_low, v_low = cv2.split(
cv2.cvtColor(
data_low, cv2.COLOR_BGR2HSV
)
)
h_high, s_high, v_high = cv2.split(
cv2.cvtColor(
high, cv2.COLOR_BGR2HSV
)
)
# 用高分影像的V替换低分影像的V
HSV = cv2.merge([h_low, s_low, v_high])
RGB = Image.fromarray(
cv2.cvtColor(
HSV, cv2.COLOR_HSV2RGB
)
)
return RGB
结果如下:左边是高分辨率,中间是低分辨率,右边是融合图像。
2 IHS
利用IHS变换进行融合,通过正反变换矩阵操作,用高分辨率图像的第一波段替换低分辨率图像,以达到融合效果。
# https://blog.csdn.net/weixin_45364562/article/details/107130857
def ihs_imgfusion(data_l, data_h):
"""
基于IHS变换融合算法
输入:np.ndArray格式的三维数组
返回:可绘出图像的utf-8格式的三维数组
"""
# RGB->IHS正变换矩阵
A = [[1. / 3., 1. / 3., 1. / 3.],
[-np.sqrt(2) / 6., -np.sqrt(2) / 6., 2 * np.sqrt(2) / 6],
[1. / np.sqrt(2), -1. / np.sqrt(2), 0.]]
# IHS->RGB逆变换矩阵
B = [[1., -1. / np.sqrt(2), 1. / np.sqrt(2)],
[1., -1. / np.sqrt(2), -1. / np.sqrt(2)],
[1., np.sqrt(2), 0.]]
A = np.matrix(A)
B = np.matrix(B)
# 输入数据参数
band, w, h = data_h.shape
data_low = data_l.reshape(3, w * h)
data_high = data_h.reshape(3, w * h)
# 正变换
a1 = np.dot(A, np.matrix(data_high))
a2 = np.dot(A, np.matrix(data_low))
# 用高分影像第一波段替换低分影像第一波段
a2[0, :] = a1[0, :]
# 融合影像逆变换
rgb = np.array(np.dot(B, a2))
rgb = rgb.reshape((3, w, h))
min_val = np.min(rgb.ravel())
max_val = np.max(rgb.ravel())
rgb = np.uint8((rgb.astype(np.float) - min_val) / (max_val - min_val) * 255)
rgb = Image.fromarray(cv2.merge([rgb[0], rgb[1], rgb[2]]))
return rgb
3 PCA
融合流程如下:
def PCA_fusion(data_l, data_h):
imageSize = data_l.size
# Todo: for more than two images
allImage = np.concatenate((data_h.reshape(1, imageSize), data_l.reshape(1, imageSize)), axis=0)
covImage = np.cov(allImage)
D, V = np.linalg.eig(covImage)
D = D.tolist()
LD = max(D)
if D.index(LD) == 0:
a = V[:, 0] / V[:, 0].sum()
elif D.index(LD) == 1:
a = V[:, 1] / V[:, 1].sum()
elif D.index(LD) == 2:
a = V[:, 2] / V[:, 2].sum()
elif D.index(LD) == 3:
a = V[:, 3] / V[:, 3].sum()
fusionImage = data_h[0]*a[0] + data_l*a[1]
fusionImage = fusionImage.swapaxes(1, 0)
fusionImage = fusionImage.swapaxes(2, 1)
fusionImage = np.uint8(fusionImage)
return fusionImage
参考:
https://blog.csdn.net/iteye_16040/article/details/82028976
https://blog.csdn.net/weixin_44588584/article/details/129798346
https://blog.csdn.net/LiuKY_123/article/details/124135725
https://blog.csdn.net/nanke_yh/article/details/89481095
https://www.cnblogs.com/suoyike1001/p/15248811.html
https://blog.csdn.net/qq_41730491/article/details/128933113