我试图在python中使用Kekres小波变换融合两个图像。
我使用DFT(大小为32 * 32)作为基本矩阵来生成小波矩阵(大小为1024 * 1024)。相同的程序在MATLAB中编写,它正确显示融合结果。
但是这个python程序没有显示融合图像。我无法理解原因。示例图片在这里
MR Image
已注册的CT图像
预期的融合图像
import cv2
import numpy as np
from WaveletMatrix import GenerateWaveletMatrix
import matplotlib.pyplot as plt
import scipy as sp
def dftmatrix(N):
return sp.fft(sp.eye(N))
TranformSize=32
WaveletSize= TranformSize*TranformSize
dftm=dftmatrix(TranformSize);
WaveletMat=GenerateWaveletMatrix(dftm,TranformSize)
FixedImageR = cv2.imread('D:\MyTransforms_HP\DataSet3\MR_LumbarSpineT2Cube00001.jpg',0)
MovingImageR = cv2.imread('D:\MyTransforms_HP\DataSet3\R.jpg',0)
SizeFixedImage=FixedImageR.shape
SizeMovingImage=MovingImageR.shape
if SizeFixedImage!=SizeMovingImage:
print("Images must be of same size")
exit()
FixedImageR=FixedImageR.astype(np.double)
MovingImageR=MovingImageR.astype(np.double)
FixedImage = cv2.resize(FixedImageR,(WaveletSize,WaveletSize),0,0)
MovingImage= cv2.resize(MovingImageR,(WaveletSize,WaveletSize),0,0)
FixedImage=np.ceil(FixedImage)
MovingImage=np.ceil(MovingImage)
#WaveletImage1= np.zeros(shape=(WaveletSize,WaveletSize),dtype=np.double)
#WaveletImage2= np.zeros(shape=(WaveletSize,WaveletSize),dtype=np.double)
WaveletT=WaveletMat.T
WaveletImage1=np.zeros(shape=(WaveletSize,WaveletSize),dtype=np.complex)
WaveletImage2=np.zeros(shape=(WaveletSize,WaveletSize),dtype=np.complex)
WaveletImage1=WaveletMat.dot(FixedImage).dot(WaveletT)
WaveletImage2=WaveletMat.dot(MovingImage).dot(WaveletT)
plt.figure(1)
plt.imshow(np.uint8(WaveletImage1),cmap='gray')
plt.show()
plt.figure(2)
plt.imshow(np.uint8(WaveletImage2),cmap='gray')
plt.show()
FusedImage1=np.zeros(shape=(WaveletSize,WaveletSize),dtype=np.complex)
FusedImage1=(WaveletImage1 + WaveletImage2) / 2
newimg=np.zeros(shape=(WaveletSize,WaveletSize),dtype=np.complex)
mainD=np.zeros(shape=(WaveletSize))
mainD[0:TranformSize]=WaveletSize
mainD[TranformSize:WaveletSize]=TranformSize
for i in range(0,WaveletSize):
for j in range(0,WaveletSize):
newimg[i,j]=(FusedImage1[i,j]/(mainD[i]*mainD[j]))
inverseMAT=(WaveletMat.T).dot(newimg).dot(WaveletMat)
plt.figure(3)
plt.imshow(np.uint8(inverseMAT),cmap='gray')
plt.show()