% Wavelet modulus maximum is used for image fusion
clc;clear
X1=imread('lena64.bmp');
X1=imresize(X1,[184 184]);
I1=(X1);% Convert a color image to a grayscale image
figure(1);
subplot(131) ;imshow(I1); %Display image 1
title('MRI');
X2=imread('21.jpg');
X2=imresize(X2,[184 184]);
I2=rgb2gray(X2/2);% Convert a color image to a grayscale image
subplot(132); imshow(I2);% display image 2
title('CT');
I11=im2double(I1);
I22=im2double(I2);
n=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wavelet coefficient decomposition to obtain each frequency component coefficient
[c1,s1]=wavedec2(I11,n,'db4');
[c2,s2]=wavedec2(I22,n,'db4');
% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%% Processing of the first image (MRI):
% [h11,v11,d11]=detcoef2('all',c1,s1,1) ;% Extract the detailed components of the first layer of two-dimensional wavelet decomposition (high frequency coefficients)
% [h12,v12,d12]=detcoef2('all',c1,s1,2);% extract the second layer of two-dimensional wavelet decomposition Detail component (high frequency coefficient)
% [h13,v13,d13]=detcoef2('all',c1,s1,1);% Extract the detail component of the third layer of two-dimensional wavelet decomposition (high frequency coefficient)
%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Processing of the second image (CT):
% [h21,v21,d21]=detcoef2( 'all',c2,s2,1);% extract the detailed components (high frequency coefficients) of the first two-dimensional wavelet decomposition of the first layer
% [h22,v22,d22]=detcoef2('all',c2,s2,2);
[h23,v23,d23]=detcoef2('all',c2,s2,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%% Extract the low-frequency coefficient of the highest layer (third layer)
a31=appcoef2(c1,s1,'db4',1);% Extract the approximate components of multi-layer two-dimensional wavelet decomposition (low frequency coefficients)
a32=appcoef2(c2,s2,'db4',1);%
A3 = (a31 + a32);
X=I22;
[SIZEX,SIZEY]=size(X);% image size
% multi-scale
m=1.0;
delta=2^m;
% constructing the partial derivative of the Gaussian function
N=20;% filter length (need to adjust, Must be an even number)
A=-1/sqrt(2*pi);% amplitude
for index_x=1:N;
for index_y=1:N;
x=index_x-(N+1)/2;
y=index_y-(N +1)/2;
phi_x(index_x,index_y)=A*(x/delta^2).*exp(-(x.*x+y.*y)/(2*delta^2));
phi_y( index_x,index_y)=A*(y/delta^2).*exp(-(x.*x+y.*y)/(2*delta^2));
end
end;
phi_x=phi_x/norm(phi_x );% energy normalization
phi_y=phi_y/norm(phi_y);% energy normalization
% Convolution of rows and columns on the image
Gx=conv2(X,phi_x,'same');
Gy=conv2(X,phi_y, 'same');
% Find the gradient
Grads=sqrt((Gx*Gx)+(Gy*Gy));
% Find the angle (gradient direction)
angle_array=zeros(SIZEX,SIZEY);%
traverse
for i=1:SIZEX;
for j=1:SIZEY
if (abs(Gx(i,j))>eps*100) % The absolute value of x is large enough
p=atan(Gy(i,j)/Gx(i,j))*180/pi;% arctangent to find the angle value (1,4 quadrant)
if (p<0)% negative The argument (4 quadrants)
p=p+360;
end;
if (Gx(i,j)<0 & p>180)% Special treatment for 2 quadrants
p=p-180;
elseif (Gx(i,j) <0 & p<180)% Special treatment for 3 quadrants
p=p+180;
end
else% 90 or 270 degrees
p=90;
end
angle_array(i,j)=p;% argument assignment
end
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Wavelet decomposition of amplitude
n=1
[c4,s4]=wavedec2(Grads,n,'db4');
%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%% only need to extract the high frequency coefficient
% [h41,v41,d41]=detcoef2('all',c4,s4,1); % Extract the detailed components of the first layer of two-dimensional wavelet decomposition (high frequency coefficients)
% [h42,v42,d42]=detcoef2('all',c4,s4,2);% extract the details of the second layer of two-dimensional wavelet decomposition Components (high-frequency coefficients)
[h43,v43,d43]=detcoef2('all',c4,s4,1);% extract the detailed components of the third layer of two-dimensional wavelet decomposition (high-frequency coefficients)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Angle of the CT edge image Perform wavelet decomposition
n=1
[c5,s5]=wavedec2(angle_array,n,'db4');
%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% only need to extract high frequency coefficient
% [h51,v51,d51]=detcoef2('all',c5,s5,1);%extract The detailed components of the first two-dimensional wavelet decomposition (high-frequency coefficients)
% [h52,v52,d52]=detcoef2('all',c5,s5,2);% extract the detailed components of the second two-dimensional wavelet decomposition ( High-frequency coefficients)
[h53,v53,d53]=detcoef2('all',c5,s5,1);% extract the detailed components of the third layer of two-dimensional wavelet decomposition (high-frequency coefficients)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Angle detection
%%%%%%%%% Detection of the third-level horizontal coefficients, where H3(i,j) is the horizontal component of the first-level wavelet coefficients after fusion
%%% determines the direction of the amplitude value through the angle value, and then connects with the adjacent two Point value comparison, take the wavelet coefficient of the original CT image corresponding to the largest value as the wavelet coefficient of the point after fusion
%%% h53 is the horizontal component of the angle, h43 is the horizontal component of the amplitude
[SIZEX,SIZEY]=size(h53);
H3=h23;
for i=2:SIZEX-1
for j=2:SIZEY-1
if ((h53(i,j)>=(-22.5) & h53(i,j)<=22.5) | ...
(h53(i,j)>=(180-22.5) & h53(i,j)<=(180+22.5)))% 0/180
if (h43(i,j)>h43(i+1,j ) & h43(i,j)>h43(i-1,j))
H3(i,j)=h23(i,j);
elseif h43(i+1,j)>h43(i-1,j)
H3(i,j)=h23(i+1,j);
else
H3(i,j)=h23(i-1,j);
end
elseif ((h53(i,j)>=(90-22.5) & h53(i,j)<=(90+22.5)) | ...
(h53(i,j)>=(270-22.5) & h53(i,j)<=(270+22.5))) % 90/270
if (h43(i,j)>h43(i,j+1) & h43(i,j)>h43(i,j-1))
H3(i,j)=h23(i,j);
elseif h43(i,j+1)>h43(i,j-1)
H3(i,j)=h23(i,j+1);
else
H3(i,j)=h23(i,j-1);
end
elseif ((h53(i,j)>=(45-22.5) & h53(i,j)<=(45+22.5)) | ...
(h53(i,j)>=(225-22.5) & h53(i,j)<=(225+22.5))) % 45/225
if (h43(i,j)>h43(i+1,j+1) & h43(i,j)>h43(i-1,j-1))
H3(i,j)=h23(i,j);
elseif h43(i+1,j+1)>h43(i-1,j-1)
H3(i,j)=h23(i+1,j+1);
else
H3(i,j)=h23(i-1,j-1);
end
else % 135/215
if (h43(i,j)>h43(i+1,j-1) & h43(i,j)>h43(i-1,j+1))
H3(i,j)=h23(i,j);
elseif h43(i+1,j-1)>h43(i-1,j+1)
H3(i,j)=h23(i+1,j-1);
else
H3(i,j)=h23(i-1,j+1);
end
end
end
end
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
D-20