%基于改进方法的图象融合源代码:
M2=imread('tm.jpg');
IHS=rgb2hsi(M2);
H=IHS(:,:,1);
S=IHS(:,:,2);
I=IHS(:,:,3);
N=imread('spot.jpg');
J=imhist(I);
J=imhist(I);
N1=histeq(N,J);
%对I分量进行小波分解
[C1,S1]=wavedec2(I,2,'bior3.7');
%提取分解后的近似和细节系数:
cIA1=appcoef2(C1,S1,'bior3.7',1);
cIA2=appcoef2(C1,S1,'bior3.7',2);
[cIH2,cIV2,cID2]=detcoef2('all',C1,S1,2);
[cIH1,cIV1,cID1]=detcoef2('all',C1,S1,1);
%从系数C1重构第二层近似
IA1=wrcoef2('a',C1,S1,'bior3.7',1);
IA2=wrcoef2('a',C1,S1,'bior3.7',2);
%从系数C1重构第一、第二层细节:
IH1=wrcoef2('h',C1,S1,'bior3.7',1);
IV1=wrcoef2('v',C1,S1,'bior3.7',1);
ID1=wrcoef2('d',C1,S1,'bior3.7',1);
IH2=wrcoef2('h',C1,S1,'bior3.7',2);
IV2=wrcoef2('v',C1,S1,'bior3.7',2);
ID2=wrcoef2('d',C1,S1,'bior3.7',2);
%对N1(高分辨率图象)进行小波分解:
[C2,S2]=wavedec2(N1,2,'bior3.7');
%提取分解后的近似和细节系数:
cNA1=appcoef2(C2,S2,'bior3.7',1);
cNA2=appcoef2(C2,S2,'bior3.7',2);
[cNH2,cNV2,cND2]=detcoef2('all',C2,S2,2);
[cNH1,cNV1,cND1]=detcoef2('all',C2,S2,1);
%从系数C2重构第二层近似
NA1=wrcoef2('a',C2,S2,'bior3.7',1);
NA2=wrcoef2('a',C2,S2,'bior3.7',2);
%从系数C2重构第一、第二层细节:
NH1=wrcoef2('h',C2,S2,'bior3.7',1);
NV1=wrcoef2('v',C2,S2,'bior3.7',1);
ND1=wrcoef2('d',C2,S2,'bior3.7',1);
NH2=wrcoef2('h',C2,S2,'bior3.7',2);
NV2=wrcoef2('v',C2,S2,'bior3.7',2);
ND2=wrcoef2('d',C2,S2,'bior3.7',2);
%对分解系数进行融合
[m1,n1]=size(cIH1);
for i=1:m1
for j=1:n1
if (abs(cIH1(i,j))>abs(cNH1(i,j)))
CH1(i,j)=cIH1(i,j);
else
CH1(i,j)=cNH1(i,j);
end
end
end
for i=1:m1
for j=1:n1
if (abs(cIV1(i,j))>abs(cNV1(i,j)))
CV1(i,j)=cIV1(i,j);
else
CV1(i,j)=cNV1(i,j);
end
end
end
for i=1:m1
for j=1:n1
if (abs(cID1(i,j))>abs(cND1(i,j)))
CD1(i,j)=cID1(i,j);
else
CD1(i,j)=cND1(i,j);
end
end
end
[m2,n2]=size(cIH2);
for i=1:m2
for j=1:n2
if (abs(cIH2 (i,j))>abs(cNH2(i,j)))
CH2(i,j)=cIH2(i,j);
else
CH2(i,j)=cNH2(i,j);
end
end
end
for i=1:m2
for j=1:n2
if (abs(cIV2 (i,j))>abs(cNV2(i,j)))
CV2(i,j)=cIV2(i,j);
else
CV2(i,j)=cNV2(i,j);
end
end
end
for i=1:m2
for j=1:n2
if (abs(cID2 (i,j))>abs(cND2(i,j)))
CD2(i,j)=cID2(i,j);
else
CD2(i,j)=cND2(i,j);
end
end
end
[m3,n3]=size(cIA2);
for i=1:m3
for j=1:n3
if (abs(cIA2 (i,j))>abs(cNA2(i,j)))
CA2(i,j)=cIA2(i,j);
else
CA2(i,j)=cNA2(i,j);
end
end
end
[s1,s2]=size(CA2); S11=s1*s2;
B(1:S11)=CA2;
[s1,s2]=size(CH2); S22=s1*s2;
B1(1:S22)=CH2;
[s1,s2]=size(CV2); S3=s1*s2;
B2(1:S3)=CV2;
[s1,s2]=size(CD2); S4=s1*s2;
B3(1:S4)=CD2;
[s1,s2]=size(CH1); S5=s1*s2;
B4(1:S5)=CH1;
[s1,s2]=size(CV1); S6=s1*s2;
B5(1:S6)=CV1;
[s1,s2]=size(CD1); S7=s1*s2;
B6(1:S7)=CD1;
c(1:S11)=B(1:S11);
c(S11+1:S11+S22)=B1(1:S22);
c(S11+S22+1:S11+S22+S3)=B2(1:S3);
c(S11+S22+S3+1:S11+S22+S3+S4)=B3(1:S4);
c(S11+S22+S3+S4+1:S11+S22+S3+S4+S5)=B4(1:S5);
c(S11+S22+S3+S4+S5+1:S11+S22+S3+S4+S5+S6)=B5(1:S6);
c(S11+S22+S3+S4+S5+S6+1:S11+S22+S3+S4+S5+S6+S7)=B6(1:S7);
%应用融合系数进行图象重构并显示
I1=waverec2(c,S1,'bior3.7');
I2=I1/256;
IHS3(:,:,1)=H;
IHS3(:,:,2)=S;
IHS3(:,:,3)=I2;
M3=hsi2rgb(IHS3);
figure
subplot(2,2,1);
imshow(M2);
title('原始高光谱图象');
subplot(2,2,2);
imshow(N1);
title('原始高分辨率图象');
subplot(2,2,3);
imshow(I2);
title('新的I分量');
subplot(2,2,4);
imshow(M3);
title('算法改进后的融合图象');
figure(2)
imshow(I2);
title('新的I分量');
figure(3)
imshow(M3);
title('算法改进后的融合图象');
imwrite(M3,'hisxiao.jpg','jpg');
评论0