【问题标题】:Image Fusion Using wavelet transform in python在python中使用小波变换进行图像融合
【发布时间】:2019-03-04 22:30:38
【问题描述】:

如何使用小波变换融合 2 张图像。有几种方法可用,例如主成分分析,高通滤波,IHS等。我想知道如何使用小波变换进行融合。我知道背后的理论,想知道如何在 Python 中实现它。

这里是基于小波变换的图像融合的链接https://www.slideshare.net/paliwalumed/wavelet-based-image-fusion-33185100

【问题讨论】:

  • 你说你知道这个理论,所以请添加一个解释如何在理论上进行融合,也许不知道这个理论的人可以帮助你实现。
  • 你能不能发两张你想融合的图片
  • @AmitayNachmani 该过程是否特定于我们使用的图像?
  • 不,但如果我会尝试使用您的图片并为您提供结果,您将更容易知道您是否得到了所需的内容。

标签: python image-processing wavelet-transform


【解决方案1】:

首先你需要下载 PyWavelet https://pywavelets.readthedocs.io/en/latest/

第二次在你的图片上运行以下代码:

import pywt
import cv2
import numpy as np

# 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)
    else:
        cooef = []

    return cooef


# Params
FUSION_METHOD = 'mean' # Can be 'min' || 'max || anything you choose according theory

# Read the two image
I1 = cv2.imread('i1.bmp',0)
I2 = cv2.imread('i2.jpg',0)

# We need to have both images the same size
I2 = cv2.resize(I2,I1.shape) # I do this just because i used two random images

## Fusion algo

# First: Do wavelet transform on each image
wavelet = 'db1'
cooef1 = pywt.wavedec2(I1[:,:], wavelet)
cooef2 = pywt.wavedec2(I2[:,:], wavelet)

# Second: for each level in both image do the fusion according to the desire option
fusedCooef = []
for i in range(len(cooef1)-1):

    # 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_METHOD)
        c2 = fuseCoeff(cooef1[i][1], cooef2[i][1], FUSION_METHOD)
        c3 = fuseCoeff(cooef1[i][2], cooef2[i][2], FUSION_METHOD)

        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
fusedImage = np.multiply(np.divide(fusedImage - np.min(fusedImage),(np.max(fusedImage) - np.min(fusedImage))),255)
fusedImage = fusedImage.astype(np.uint8)

# Fith: Show image
cv2.imshow("win",fusedImage)

fusedImage 是 I1 和 I2 的融合结果

【讨论】:

  • 在我发布的同一个链接中,有一个指向教程的链接
  • @Rakshith Gb 是的。它不依赖于语言。找一个C++的小波库,用opencv处理图像,你可以用c++重写它
  • 感谢您的回答!是在不丢失颜色信息 (RGB) 通道的情况下执行图像融合的方法吗?例如:通过将图像读取为I1 = cv2.imread('i1.bmp') I2 = cv2.imread('i2.jpg')
  • @Jithin 我不确定,但我认为您可以单独为每个通道执行此操作,然后将通道组合回来以获取 rgb。
猜你喜欢
  • 1970-01-01
  • 2018-10-23
  • 2012-05-23
  • 1970-01-01
  • 2016-02-04
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多