python中基于小波变换的图像融合
如何利用小波变换融合两幅图像。有几种方法可用,如主成分分析、高通滤波、IHS等。我想知道如何使用小波变换进行融合。我知道背后的理论,想知道如何用Python实现它python中基于小波变换的图像融合,python,image-processing,wavelet-transform,Python,Image Processing,Wavelet Transform,如何利用小波变换融合两幅图像。有几种方法可用,如主成分分析、高通滤波、IHS等。我想知道如何使用小波变换进行融合。我知道背后的理论,想知道如何用Python实现它 这里是基于小波变换的图像融合链接首先需要下载PyWavelet 然后在图像上运行以下代码: import pywt import cv2 import numpy as np # This function does the coefficient fusing according to the fusion method def
这里是基于小波变换的图像融合链接首先需要下载PyWavelet 然后在图像上运行以下代码:
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)
融合图像是I1和I2融合的结果你说你知道理论,所以请在理论上解释如何进行融合,也许不知道理论的人可以帮助你实现。@AmitayNachmani你能发布两张你想要的图像吗fuse@AmitayNachmani该过程是否针对特定的客户我们使用的图片?没有,但是如果我尝试使用你的图片并给出结果,那么就更容易知道你是否得到了你想要的。在我发布的同一个链接中,有一个指向那里的链接tutorials@Rakshith是的。它不依赖于语言。找到一个C++的小波库,用OpenCV处理图像,你可以在C++中改写它,谢谢你的答案!是在不丢失颜色信息(RGB)通道的情况下执行图像融合的方法吗?例如:通过将图像读取为
I1=cv2.imread('I1.bmp')I2=cv2.imread('I2.jpg')
@Jithin,我不确定,但我认为您可以单独为每个通道执行此操作,然后将通道合并回rgb。