今天将介绍使用小波变换和自适应脉冲耦合神经网络来对多模态图像进行融合。1、小波变换融合回顾小波变换融合算法基本思想:首先对源图像进行小波变换,然后按照一定规则对变换系数进行合并;最后对合并后的系数进行小波逆变换得到融合图像。1.1、小波分解原理简介e085cae4b3e08eda96c114fac2604a08.pngLL:水平低频,垂直低频LH:水平低频,垂直高频HL:水平高频,垂直低频HH:水平高频,垂直高频其中,L表示低频,H表示高频,下标1、2表示一级或二级分解。在每一分解层上,图像均被分解为LL,LH,HH和HL四个频带,下一层的分解仅对低频分量LL进行分解。这四个子图像中的每一个都是由原图与一个小波基函数的内积后,再经过在x和y方向都进行2倍的间隔采样而生成的,这是正变换,也就是图像的分解;逆变换,也就是图像的重建,是通过图像的增频采样和卷积来实现的。1.2、融合规则规则一:系数绝对值较大法该融合规则适合高频成分比较丰富,亮度、对比度比较高的源图像,否则在融合图像中只保留一幅源图像的特征,其他的特征被覆盖。小波变换的实际作用是对信号解相关,并将信号的全部信息集中到一部分具有大幅值的小波系数中。这些大的小波系数含有的能量远比小系数含有的能量大,从而在信号的重构中,大的系数比小的系数更重要。规则二:加权平均法权重系数可调,适用范围广,可消除部分噪声,源图像信息损失较少,但会造成图像对比度的下降,需要增强图像灰度。2、脉冲耦合神经网络(PCNN)回顾PCNN模型用于处理二维图像时,可以用数学离散形式来描述,如下公式所示。40ee602919b2b905aa4112978d4bca59.png其中Sij为外部信号,αL和αθ分别是线性连通输入Lij和动态临界值θij的衰减定值,VL和Vθ分别是连通倍数系数和临界值倍数系数,Wijkl是线性连通输入Lij的加权系数,βij为连接强度,决定了线性连通输入Lij对内部参数Uij的贡献。3、基于小波变换和自适应脉冲耦合神经网络的图像融合代码实现我将分享python版本代码来融合红外和可见光图像,融合策略是低频图像采用平均值法,高频图像采用自适应PCNN最大值法,PCNN参数设置:链接系数为5,链接参数为图像拉普拉斯能量和,计算公式如下所示,迭代次数为200。941d2ca6e03a11d5f22781bbbb77d98d.pngpython版本中需要用到PyWavelets库,可以使用下面命令来安装。
pip install PyWavelets
python版本代码:
import pywtimport cv2import numpy as npimport mathfrom scipy import signaldef pcnn(img, link=5, beta=0.1, iteration=200):    """    PCNN generate fire maps image    :param img:source image    :param link:pcnn link parm    :param beta:pcnn link coefficient    :param iteration:pcnn iteration number    :return:fire maps image    """    m, n = np.shape(img)[0], np.shape(img)[1]    alpha_L = 1    alpha_Theta = 0.2    vL = 1.0    vTheta = 20    center_x = round(link / 2)    center_y = round(link / 2)    W = np.zeros((link, link))    for i in range(link):        for j in range(link):            if i == center_x and j == center_y:                W[i, j] = 0            else:                W[i, j] = 1. / math.sqrt(pow(i - center_x, 2) + pow(j - center_y, 2))    imgf = img.astype(np.float)    F = abs(imgf)    L = np.zeros((m, n))    Y = np.zeros((m, n))    Theta = np.zeros((m, n))    img_pcnn = np.zeros((m, n))    for i in range(iteration):        K = signal.convolve2d(Y, W, mode='same')        L = math.exp(-alpha_L) * L + vL * K        Theta = math.exp(-alpha_Theta) * Theta + vTheta * Y        U = np.multiply(F, 1 + np.multiply(beta, L))        Y = U > Theta        Yf = Y.astype(np.float)        img_pcnn = img_pcnn + Yf    return img_pcnn# This function does the coefficient fusing according to the fusion methoddef fuseCoeff(cooef1, cooef2, method):    if (method == 'mean'):        cooef = (cooef1 + cooef2) / 2    elif (method == 'min'):        cooef = np.minimum(cooef1, cooef2)    elif (method == 'max'):        cooef = np.maximum(cooef1, cooef2)    elif (method == 'pcnn'):        pcnn1 = pcnn(cooef1, 5, 0.1, 200)        pcnn2 = pcnn(cooef2, 5, 0.1, 200)        pcnn_cooef = np.maximum(pcnn1, pcnn2)        cooef1[pcnn1 != pcnn_cooef] = 0        cooef2[pcnn2 != pcnn_cooef] = 0        cooef = cooef1 + cooef2    elif (method == 'auto_pcnn'):        W = [[-1, -4, -1], [-4, 20, -4], [-1, -4, -1]]        K1 = signal.convolve2d(cooef1, W, mode='same')        K2 = signal.convolve2d(cooef2, W, mode='same')        beta1 = np.sum(np.multiply(K1, K1))        beta2 = np.sum(np.multiply(K2, K2))        pcnn1 = pcnn(cooef1, 5, beta1, 200)        pcnn2 = pcnn(cooef2, 5, beta2, 200)        pcnn_cooef = np.maximum(pcnn1, pcnn2)        cooef1[pcnn1 != pcnn_cooef] = 0        cooef2[pcnn2 != pcnn_cooef] = 0        cooef = cooef1 + cooef2    return cooef# ParamsFUSION_METHOD = 'mean'  # Can be 'min' || 'max || anything you choose according theoryFUSION_METHOD1 = 'auto_pcnn'# Read the two imageI1 = cv2.imread('IR1.png', 0)I2 = cv2.imread('VIS1.png', 0)# First: Do wavelet transform on each imagewavelet = 'db2'cooef1 = pywt.wavedec2(I1[:, :], wavelet, level=1)cooef2 = pywt.wavedec2(I2[:, :], wavelet, level=1)# Second: for each level in both image do the fusion according to the desire optionfusedCooef = []for i in range(len(cooef1)):    # The first values in each decomposition is the apprximation values of the top level    if (i == 0):        fusedCooef.append(fuseCoeff(cooef1[0], cooef2[0], FUSION_METHOD))    else:        # For the rest of the levels we have tupels with 3 coeeficents        c1 = fuseCoeff(cooef1[i][0], cooef2[i][0], FUSION_METHOD1)        c2 = fuseCoeff(cooef1[i][1], cooef2[i][1], FUSION_METHOD1)        c3 = fuseCoeff(cooef1[i][2], cooef2[i][2], FUSION_METHOD1)        fusedCooef.append((c1, c2, c3))# Third: After we fused the cooefficent we nned to transfor back to get the imagefusedImage = pywt.waverec2(fusedCooef, wavelet)# Forth: normmalize values to be in uint8fusedImage1 = np.multiply(np.divide(fusedImage - np.min(fusedImage), (np.max(fusedImage) - np.min(fusedImage))), 255)fusedImage1 = fusedImage1.astype(np.uint8)# Fith: Show imagecv2.imwrite("win.bmp", fusedImage1)
4、融合结果下图是红外图像和可见光图像。03dbdde3f3960be15c32b6cec5a15fa5.png6be580664af7261bb3f345ab597a71a8.png小波变换自适应脉冲耦合神经网络融合结果0cf781401cafdb930e354e50cbd7ff69.png如果碰到任何问题,随时留言,我会尽量去回答的。
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐