小波变换-图像融合matlab代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

X1 = imread('IR.bmp','bmp');
X2 = imread('VIS.bmp','bmp');

%figure(1);
%imshow(X1);

%g1 = 1/255.*X2;
%figure(2);
%imshow(X2);

PIC1 = double(X1);
PIC2 = double(X2);
%PIC2 = X2;
X1 = PIC1;
X2 = PIC2;
%定义滤波窗口;
fw = 1/16.*[1 4 6 4 1];
z =3;

L = cell(1,z);
L1 = cell(1,z);
for i = 1:z % N1
% 计算,保存图像大小
[row column] = size(PIC1);
k1(i) = row;
k2(i) = column;

%检查是否需要扩展
if (floor(row/2) ~= row/2), w(1) = 1; else, w(1) = 0; end;
if (floor(column/2) ~= column/2), w(2) = 1; else, w(2) = 0; end;

% 完成图像的边界扩展;
if (any(w)) % NN1

PIC1 = add_rc(PIC1,w);
PIC2 = add_rc(PIC2,w);
end; % NN1

%将原图像进行沿边界对称扩展

Y2 = add_side(PIC1,2);
Y3 = add_side(PIC2,2);
%对原图像进行低通滤波
G2 = conv2(conv2(Y2, fw, 'valid'),fw', 'valid');
G3 = conv2(conv2(Y3, fw, 'valid'),fw', 'valid');

%将图像进行隔行隔列减半
[a b] = size(G2);
Y4 = G2(1:2:a, 1:2:b);
Y5 = G3(1:2:a, 1:2:b);

%图像隔行隔列插值扩展恢复到原尺寸图像
[c d] = size(Y4);
Y6 = zeros(2*c, 2*d);
Y6(1:2:2*c,1:2:2*d) = Y4;
Y7 = zeros(2*c, 2*d);
Y7(1:2:2*c,1:2:2*d) = Y5;

%将图像进行沿边界对称扩展

Y8 = add_side(Y6,2);
Y9 = add_side(Y7,2);
%对图像进行放大算子运算

PIC3 = conv2(conv2(Y8, 2*fw, 'valid'),2*fw', 'valid');
PIC4 = conv2(conv2(Y9, 2*fw, 'valid'),2*fw', 'valid');


PIC5 = PIC1;
PIC6 = PIC2;
PIC5 = PIC5-PIC3;
PIC6 = PIC6-PIC4;
L1{i} = PIC5;
%拉普拉斯塔式结构(也就是图像融合规则)

%L(i) = {PIC5};
L(i) = {rule2(PIC5,PIC6)};
%L(i) = {rule3(PIC5,PIC6)};
%L(i) = {PIC5};
%if i==3
% L{i}=(p).*PIC5+(1-p).*PIC6;
%else
% L{i}=(p).*PIC5+(1-p).*PIC6;
%end;

%高斯塔形图像
PIC1 = Y4;
PIC2 = Y5;

end;

PIC1 = (PIC1+PIC2)/2;
%PIC1 = PIC1;
%PIC1 = (1/3).*PIC1+(2/3).*PIC2;

for i = z:-1:1

%图像隔行隔列插值扩展恢复到原尺寸图像
[c d] = size(PIC1);
Y10 = zeros(2*c, 2*d);
Y10(1:2:2*c,1:2:2*d) = PIC1;

%将图像进行沿边界对称扩展
Y = zeros(2*c+4, 2*d+4);
Y(3:2+2*c,3:1:2+2*d) = Y10;
Y(3:2+2*c,2:-1:1) = Y10(:,2:1:3);
Y(3:2+2*c,3+2*d:1:2*d+4) = Y10(:,2*d-1:-1:2*d-2);
Y(2:-1:1,3:2*d+2) = Y10(2:1:3,:);
Y(2+2*c+1:1:2*c+4,3:2*d+2) = Y10(2*c-1:-1:2*c-

2,:);

%对图像进行放大算子的运算

PIC3 = conv2(conv2(Y, 2*fw, 'valid'),2*fw','valid');
%第i1级图像重构;
PIC1 = PIC3 + L{i};

%选取图像范围
PIC1 = PIC1(1:k1(i),1:k2(i));

end;
Y = PIC1;

% 得到最后的图像结果并进行数据转换
PIC = 1/255.*Y;
%显示图像
figure(5);
imshow(PIC);


% K = 0;
% %a = 20;
% %b = 460;
% %c = 620;
% %d = 440*600;
% a = 1;
% b = 512;
% c = 512;
% d = 512*512;
% for i = a:b
% for j = a:c
% %if ( ( i>=432 & j>310 ) | ( 432>i>=128 & j>344 ) | ( 128>i>=123 & 580>j>=505 ) | ( 123>i>=120 & j>=580) ) % 480*640 disk1,disk2
% if ( (i<=154 & j<224) | j>=224 ) % 512*512 clock1,clock2
% %if ( (i<=96) | ( i>96 & i<=140 & 11j>16*i+1104 ) | ( i>140 & i<=352 &j>=304 ) | ( i>352 & i<=480 & 128*j>108*i+896 ) ) % 480*640 lab1,lab2
% if (X1(i,j)==0)
% X1(i,j)=1;
% % K = K;
% end;
% %else
% K = K + (abs(X1(i,j) - Y(i,j)))/X1(i,j);
% %end;
% else
% if (X2(i,j)==0)
% X2(i,j)=1;
% % K =K;
% end;
% %else
% K = K + (abs(X2(i,j) - Y(i,j)))/X2(i,j);
% %end;
% end;
% end;
% end;
%
%
% K = K/d
% %求MI
% %X = uint8(Y);
% %X= double(X);
%
% %for k=1:256,
% % p1(k)=0;
% % p2(k)=0;
% %end;
%
% %for i=1:256
% % for j=1:256
% % p3(i,j) = 0;
% % end;
% %end;
% %%
% %for i=a:b,
% % for j=a:c,
% %if ( ( i>=432 & j>310 ) | ( 432>i>=128 & j>344 ) | ( 128>i>=123 & 580>j>=505 ) | ( 123>i>=120 & j>=580) ) % 480*640 disk1,disk2
% %if ( (i<=154 & j<224) | j>=224 )
% % if ( (i<=96) | ( i>96 & i<=140 & 11j>16*i+1104 ) | ( i>140 & i<=352 &j>=304 ) | ( i>352 & i<=480 & 128*j>108*i+896 ) ) % 480*640 lab1,lab2
% % k1 = X2(i,j);
% % p1(k1+1) = p1(k1+1)+1;
% % else
% % k1 = X1(i,j);
% % p1(k1+1) = p1(k1+1)+1;
% % end;
% % k2 = X(i,j);
% % p2(k2+1) = p2(k2+1)+1;
% % p3(k1+1,k2+1) = p3(k1+1,k2+1)+1;
% %end;
% %end;
% %%
% %for k=1:256,
% % p1(k)=p1(k)/(d);
% % p2(k)=p2(k)/(d);
% %end;
%
% %for i=1:256
% % for j=1:256
% % p3(i,j) =p3(i,j)/(d);
% % end;
% %end;
%
% %MI=0;
% %for i=1:256
% % for j=1:256
% % if (p1(i)*p2(j)~=0 & p3(i,j)~=0)
% % z= p3(i,j)/(p1(i)*p2(j));
% % MI =MI+p3(i,j)*log2(z);
% % end;
% % end;
% %end;
%
% %MI

相关文档
最新文档