金字塔变换的图像融合Matlab源码

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

附录1 金字塔变换图像融合方法程序

% 拉普拉斯金字塔融合函数

function Y = fuse_lap(M1, M2, zt, ap, mp)

% M1、M2为源图像

% zt为融合层数,ap为高频子带图像选择系数,mp为低频子带图像选择系数[z1 s1] = size(M1);

[z2 s2] = size(M2);

if (z1 ~= z2) || (s1 ~= s2)

error('输入源图像大小不一致');

end;

% 高斯窗口函数

w = [1 4 6 4 1] / 16;

E = cell(1,zt);

for i1 = 1:zt

[z s] = size(M1);

zl(i1) = z; sl(i1) = s;

% 图像尺寸为奇数还是偶数

if (floor(z/2) ~= z/2), ew(1) = 1; else ew(1) = 0; end;

if (floor(s/2) ~= s/2), ew(2) = 1; else ew(2) = 0; end;

% 若为奇数,扩展为偶数

if (any(ew))

M1 = adb(M1,ew);

M2 = adb(M2,ew);

end;

% M1与M2低通滤波

G1 = conv2(conv2(es2(M1,2), w, 'valid'),w', 'valid');

G2 = conv2(conv2(es2(M2,2), w, 'valid'),w', 'valid');

% G1与G2下采样、上采样低通滤波后的膨胀序列

M1T = conv2(conv2(es2(undec2(dec2(G1)), 2), 2*w, 'valid'),2*w', 'valid');

M2T = conv2(conv2(es2(undec2(dec2(G2)), 2), 2*w, 'valid'),2*w', 'valid');

% 高频子带图像系数选择

E(i1) = {selg(M1-M1T, M2-M2T, ap)};

% G11与G2下采样

M1 = dec2(G1);

M2 = dec2(G2);

end;

% 低频子带图像系数选择

M1 = selh(M1,M2,mp);

% 图像重构

for i1 = zt:-1:1

M1T = conv2(conv2(es2(undec2(M1), 2), 2*w, 'valid'), 2*w', 'valid');

M1 = M1T + E{i1};

% 选择图像有效区域

M1 = M1(1:zl(i1),1:sl(i1));

end;

Y = M1;

end;

% 对比度金字塔融合函数

function Y = fuse_con(M1, M2, zt, ap, mp)

[z1 s1] = size(M1);

[z2 s2] = size(M2);

if (z1 ~= z2) | (s1 ~= s2)

error('输入图像尺寸大小不一致');

end;

w = [1 4 6 4 1] / 16;

eps = 1e-6;

E = cell(1,zt);

for i1 = 1:zt

[z s] = size(M1);

zl(i1) = z; sl(i1) = s;

if (floor(z/2) ~= z/2), ew(1) = 1; else, ew(1) = 0; end;

if (floor(s/2) ~= s/2), ew(2) = 1; else, ew(2) = 0; end;

if (any(ew))

M1 = adb(M1,ew);

M2 = adb(M2,ew);

end;

G1 = conv2(conv2(es2(M1,2), w, 'valid'),w', 'valid');

G2 = conv2(conv2(es2(M2,2), w, 'valid'),w', 'valid');

M1T = conv2(conv2(es2(undec2(dec2(G1)), 2), 2*w, 'valid'),2*w', 'valid'); M2T = conv2(conv2(es2(undec2(dec2(G2)), 2), 2*w, 'valid'),2*w', 'valid'); E(i1) = {selg(M1./(M1T+eps)-1, M2./(M2T+eps)-1, ap)};

M1 = dec2(G1);

M2 = dec2(G2);

end;

M1 = selh(M1,M2,mp);

for i1 = zt:-1:1

M1T = conv2(conv2(es2(undec2(M1), 2), 2*w, 'valid'), 2*w', 'valid');

M1 = (M1T+eps) .* (E{i1}+1);

M1 = M1(1:zl(i1),1:sl(i1));

end;

Y = M1;

end;

% 梯度金字塔融合函数

function Y = fuse_gra(M1, M2, zt, ap, mp)

[z1 s1] = size(M1);

[z2 s2] = size(M2);

if (z1 ~= z2) | (s1 ~= s2)

error('输入图像大小不一致');

end;

w = [1 4 6 4 1] / 16;

v = [1 2 1] / 4;% 核函数

% 梯度算子

d1 = [1 -1];

d2 = [0 -1; 1 0] / sqrt(2);

d3 = [-1 1];

d4 = [-1 0; 0 1] / sqrt(2);

% 计算导数

d1e = conv2(d1,d1);

d1e = [zeros(1,3); d1e; zeros(1,3)];

d2e = conv2(d2,d2);

d3e = d1e';

d4e = conv2(d4,d4);

E = cell(1,zt);

for i1 = 1:zt

[z s] = size(M1);

zl(i1) = z; sl(i1) = s;

if (floor(z/2) ~= z/2), ew(1) = 1; else, ew(1) = 0; end;

if (floor(s/2) ~= s/2), ew(2) = 1; else, ew(2) = 0; end;

if (any(ew))

M1 = adb(M1,ew);

M2 = adb(M2,ew);

end;

% 梯度金字塔的建立

G1 = conv2(conv2(es2(M1,2), w, 'valid'),w', 'valid');

G2 = conv2(conv2(es2(M2,2), w, 'valid'),w', 'valid');

Z1 = es2(M1+conv2(conv2(es2(M1, 1), v, 'valid'), v', 'valid'), 1); Z2 = es2(M2+conv2(conv2(es2(M2, 1), v, 'valid'), v', 'valid'), 1);

B = zeros(size(M1));

% 方向拉普拉斯金字塔的建立

D1 = conv2(Z1, d1e, 'valid');

D2 = conv2(Z2, d1e, 'valid');

B = B + selg(D1, D2, ap);

D1 = conv2(Z1, d2e, 'valid');

D2 = conv2(Z2, d2e, 'valid');

相关文档
最新文档