前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >医学图像处理案例(十七)——基于小波变换和自适应脉冲耦合神经网络的图像融合

医学图像处理案例(十七)——基于小波变换和自适应脉冲耦合神经网络的图像融合

作者头像
医学处理分析专家
发布2020-06-29 15:46:35
9941
发布2020-06-29 15:46:35
举报

今天将介绍使用小波变换和自适应脉冲耦合神经网络来对多模态图像进行融合。

1、小波变换融合回顾

小波变换融合算法基本思想:首先对源图像进行小波变换,然后按照一定规则对变换系数进行合并;最后对合并后的系数进行小波逆变换得到融合图像。

1.1、小波分解原理简介

LL:水平低频,垂直低频

LH:水平低频,垂直高频

HL:水平高频,垂直低频

HH:水平高频,垂直高频

其中,L表示低频,H表示高频,下标1、2表示一级或二级分解。在每一分解层上,图像均被分解为LL,LH,HH和HL四个频带,下一层的分解仅对低频分量LL进行分解。这四个子图像中的每一个都是由原图与一个小波基函数的内积后,再经过在x和y方向都进行2倍的间隔采样而生成的,这是正变换,也就是图像的分解;逆变换,也就是图像的重建,是通过图像的增频采样和卷积来实现的。

1.2、融合规则

规则一:系数绝对值较大法

该融合规则适合高频成分比较丰富,亮度、对比度比较高的源图像,否则在融合图像中只保留一幅源图像的特征,其他的特征被覆盖。小波变换的实际作用是对信号解相关,并将信号的全部信息集中到一部分具有大幅值的小波系数中。这些大的小波系数含有的能量远比小系数含有的能量大,从而在信号的重构中,大的系数比小的系数更重要。

规则二:加权平均法

权重系数可调,适用范围广,可消除部分噪声,源图像信息损失较少,但会造成图像对比度的下降,需要增强图像灰度。

2、脉冲耦合神经网络(PCNN)回顾

PCNN模型用于处理二维图像时,可以用数学离散形式来描述,如下公式所示。

其中Sij为外部信号,αL和αθ分别是线性连通输入Lij和动态临界值θij的衰减定值,VL和Vθ分别是连通倍数系数和临界值倍数系数,Wijkl是线性连通输入Lij的加权系数,βij为连接强度,决定了线性连通输入Lij对内部参数Uij的贡献。

3、基于小波变换和自适应脉冲耦合神经网络的图像融合代码实现

我将分享python版本代码来融合红外和可见光图像,融合策略是低频图像采用平均值法,高频图像采用自适应PCNN最大值法,PCNN参数设置:链接系数为5,链接参数为图像拉普拉斯能量和,计算公式如下所示,迭代次数为200。

python版本中需要用到PyWavelets库,可以使用下面命令来安装。

pip install PyWavelets

python版本代码:

import pywt
import cv2
import numpy as np
import math
from scipy import signal


def 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 method
def 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


# Params
FUSION_METHOD = 'mean'  # Can be 'min' || 'max || anything you choose according theory
FUSION_METHOD1 = 'auto_pcnn'
# Read the two image
I1 = cv2.imread('IR1.png', 0)
I2 = cv2.imread('VIS1.png', 0)
# First: Do wavelet transform on each image
wavelet = '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 option
fusedCooef = []
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 image
fusedImage = pywt.waverec2(fusedCooef, wavelet)
# Forth: normmalize values to be in uint8
fusedImage1 = np.multiply(np.divide(fusedImage - np.min(fusedImage), (np.max(fusedImage) - np.min(fusedImage))), 255)
fusedImage1 = fusedImage1.astype(np.uint8)
# Fith: Show image
cv2.imwrite("win.bmp", fusedImage1)

4、融合结果

下图是红外图像和可见光图像。

小波变换自适应脉冲耦合神经网络融合结果

如果碰到任何问题,随时留言,我会尽量去回答的。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-02-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 最新医学影像技术 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档