IHS图像融合方法+Python代码

    技术2026-02-24  18

    IHS图像融合方法+Python代码

    1、方法原理

    HIS为:亮度(I )、色调(H)、饱和度(S);

    强度表示光谱的整体亮度大小,对应于图像的空间分辨率;

    传统的IHS图像融合方法基本思想是将IHS空间中的低分辨率亮度用高分辨率的图像的亮度成分所代替;

    首先是正变换:

       

                                                         

                                                         

    2、方法代码

    def IHS(data_low,data_high): """ 基于IHS变换融合算法 输入:np.ndArray格式的三维数组 返回:可绘出图像的utf-8格式的三维数组 """ 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.]] #RGB->IHS正变换矩阵 B = [[1.,-1./np.sqrt(2),1./np.sqrt(2)],[1.,-1./np.sqrt(2),-1./np.sqrt(2)],[1.,np.sqrt(2),0.]] #IHS->RGB逆变换矩阵 A = np.matrix(A) B = np.matrix(B) band , w , h = data_high.shape pixels = w * h data_low = data_low.reshape(3,pixels) data_high = data_high.reshape(3,pixels) 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 def imresize(data_low,data_high): """ 图像缩放函数 输入:np.ndArray格式的三维数组 返回:np.ndArray格式的三维数组 """ band , col , row = data_high.shape data = np.zeros(((band,col,row))) for i in range(0,band): data[i] = smi.imresize(data_low[i],(col,row)) return data def gdal_open(path): """ 读取图像函数 输入:图像路径 返回:np.ndArray格式的三维数组 """ data = gdal.Open(path) col = data.RasterXSize#读取图像长度 row = data.RasterYSize#读取图像宽度 data_array_r = data.GetRasterBand(1).ReadAsArray(0,0,col,row).astype(np.float)#读取图像第一波段并转换为数组 data_array_g = data.GetRasterBand(2).ReadAsArray(0,0,col,row).astype(np.float)#读取图像第二波段并转换为数组 data_array_b = data.GetRasterBand(3).ReadAsArray(0,0,col,row).astype(np.float)#读取图像第三波段并转换为数组 data_array = np.array((data_array_r,data_array_g,data_array_b)) return data_array

    执行代码:

    def main(path_low,path_high): data_low = gdal_open(path_low) data_high = gdal_open(path_high) data_low = imresize(data_low,data_high) RGB = IHS(data_low,data_high) RGB.save("IHS.png",'png') if __name__ == "__main__": path_low = 'RGB.tif' path_high = 'Band8.tif' main(path_low,path_high)

    3、执行结果

    高分全色波段:

    RGB影像:

    IHS融合结果:

    Processed: 0.015, SQL: 9