# 医学图像处理案例（十五）——基于小波变换的医学图像融合

1、基于小波变换的图像融合回顾

1.1、小波分解原理简介

LL：水平低频，垂直低频

LH：水平低频，垂直高频

HL：水平高频，垂直低频

HH：水平高频，垂直高频

1.2、融合规则

2、基于小波变换的多模态医学图像融合代码实现

`pip install PyWavelets`

python版本代码：

```import pywt
import numpy as np
import SimpleITK as sitk

# 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)
return cooef

# Params
FUSION_METHOD1 = 'mean'  # Can be 'min' || 'max || anything you choose according theory
FUSION_METHOD2 = 'max'
I1 = sitk.GetArrayFromImage(I1_itk)
I2 = sitk.GetArrayFromImage(I2_itk)
# First: Do wavelet transform on each image
wavelet = 'db2'
"""
haar family: haar
db family: db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, db11, db12, db13, db14, db15, db16, db17, db18, db19, db20, db21, db22, db23, db24, db25, db26, db27, db28, db29, db30, db31, db32, db33, db34, db35, db36, db37, db38
sym family: sym2, sym3, sym4, sym5, sym6, sym7, sym8, sym9, sym10, sym11, sym12, sym13, sym14, sym15, sym16, sym17, sym18, sym19, sym20
coif family: coif1, coif2, coif3, coif4, coif5, coif6, coif7, coif8, coif9, coif10, coif11, coif12, coif13, coif14, coif15, coif16, coif17
bior family: bior1.1, bior1.3, bior1.5, bior2.2, bior2.4, bior2.6, bior2.8, bior3.1, bior3.3, bior3.5, bior3.7, bior3.9, bior4.4, bior5.5, bior6.8
rbio family: rbio1.1, rbio1.3, rbio1.5, rbio2.2, rbio2.4, rbio2.6, rbio2.8, rbio3.1, rbio3.3, rbio3.5, rbio3.7, rbio3.9, rbio4.4, rbio5.5, rbio6.8
dmey family: dmey
gaus family: gaus1, gaus2, gaus3, gaus4, gaus5, gaus6, gaus7, gaus8
mexh family: mexh
morl family: morl
cgau family: cgau1, cgau2, cgau3, cgau4, cgau5, cgau6, cgau7, cgau8
shan family: shan
fbsp family: fbsp
cmor family: cmor
"""
cooef1 = pywt.wavedecn(I1[:, :], wavelet)
cooef2 = pywt.wavedecn(I2[:, :], wavelet)

# 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_METHOD1))
else:
c4 = fuseCoeff(cooef1[i]['daa'], cooef2[i]['daa'], FUSION_METHOD2)
c6 = fuseCoeff(cooef1[i]['dda'], cooef2[i]['dda'], FUSION_METHOD2)
c7 = fuseCoeff(cooef1[i]['ddd'], cooef2[i]['ddd'], FUSION_METHOD2)
fusedCooef.append(dictobj)
# Third: After we fused the cooefficent we nned to transfor back to get the image
fusedImage = pywt.waverecn(fusedCooef, wavelet)
fusedImage = fusedImage.astype(np.int)
fused_itk = sitk.GetImageFromArray(fusedImage)
fused_itk.SetOrigin(I2_itk.GetOrigin())
fused_itk.SetSpacing(I2_itk.GetSpacing())
fused_itk.SetDirection(I2_itk.GetDirection())
sitk.WriteImage(fused_itk, 'fused_itk.mha')```

3、融合结果

0 条评论

• ### 医学图像处理案例（七）——生成气管三维模型

参考论文《Optimizing parameters of an open-source airway segmentation algorithm using...

• ### Tensorflow入门教程（十三）——医学图像分割案例

在之前的文章中我分享了Tensorflow的基本知识内容，接下来我将会分享如何利用Tensorflow将深度学习应用到医学图像上，今天我会分享深度学...

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

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

• ### Python-one

能够执行的操作,+   -   *  /   %(取余)  //(整除)   **(次方)

• ### 美出口禁令影响下，芯片公司雇佣中国员工越来越难了

据华尔街日报报道，为了保护本土技术知识产权，美国正在放缓国内半导体公司雇佣中国公民从事高级工程师的审批进度。

• ### Python开发（一）

setdefault和get一样，dict.get(key)或是dict[key]

• ### 使用Tensorflow的DataSet和Iterator读取数据！

今天在写NCF代码的时候，发现网络上的代码有一种新的数据读取方式，这里将对应的片段剪出来给大家分享下。

• ### 《笨办法学Python》 第5课手记

《笨办法学Python》 第5课手记 本节内容复习了前两节的内容，并且引入了格式化字符，这节课里的格式化字符与C语言格式化字符，规则没有什么区别。 我把原文代码...

• ### 发布订阅模式：使用 Go 实现简单的事件总线

事件驱动架构是计算机科学中一种高度可扩展的范例。它允许我们可以多方系统异步处理事件。