A1=imread('light.jpg');
A1=double(A1);
Xrgb=0.2990*A1(:,:,1)+0.5870*A1(:,:,2)+0.1140*A1(:,:,3);
NbColors=255;
X1=wcodemat(Xrgb,NbColors);
map=pink(NbColors);
figure(1);
subplot(2,1,1);
title('可见光图像');
image(X1);colormap(map);
colorbar;
A2=imread('peizhunhou.jpg');
A2=double(A2);
Xrgb=0.2990*A2(:,:,1)+0.5870*A2(:,:,2)+0.1140*A2(:,:,3);
NbColors=255;
X2=wcodemat(Xrgb,NbColors);
map=pink(NbColors);
subplot(2,1,2);
title('配准后图像');
image(X2);colormap(map);
colorbar;
%高斯分解
Gp=X1;
w=1/256*[1 4 6 4 1;4 16 24 16 4;6 24 36 24 6;4 16 24 16 4;1 4 6 4 1];
Bl=conv2(w,Gp);
figure(2)
subplot(4,1,1)
image(Bl);
colormap(map)
title('第0层:140×258')
axis([0 258 0 140])
axis off
B1l(70,258)=0;
for r=1:70
B1l(r,:)=Bl(2*r-1,:);
end
B2l(70,129)=0;
for l=1:129
B2l(:,l)=B1l(:,2*l-1);
end
subplot(4,1,2)
image(B2l);
colormap(map)
title('第1层:70×129')
axis([0 258 0 140])
axis off
C1l(35,129)=0;
for r=1:35
C1l(r,:)=B2l(2*r-1,:);
end
C2l(35,65)=0;
for l=1:65
C2l(:,l)=C1l(:,2*l-1);
end
subplot(4,1,3)
image(C2l)
colormap(map)
title('第2层:35×65')
axis([0 258 0 140])
axis off
D1l(18,65)=0;
for r=1:18
D1l(r,:)=C2l(2*r-1,:);
end
D2l(18,33)=0;
for l=1:33
D2l(:,l)=D1l(:,2*l-1);
end
subplot(4,1,4)
image(D2l)
colormap(map)
title('第3层:18×33')
axis([0 258 0 140])
axis off
Gp=X2;
w=1/256*[1 4 6 4 1;4 16 24 16 4;6 24 36 24 6;4 16 24 16 4;1 4 6 4 1];
Bh=conv2(w,Gp);
figure(3)
subplot(4,1,1)
image(Bh);
colormap(map)
title('第0层:140×258')
axis([0 258 0 140])
axis off
B1h(70,258)=0;
for r=1:70
B1h(r,:)=Bh(2*r-1,:);
end
B2h(70,129)=0;
for l=1:129
B2h(:,l)=B1h(:,2*l-1);
end
subplot(4,1,2)
image(B2h);
colormap(map)
title('第1层:70×129')
axis([0 258 0 140])
axis off
C1h(35,129)=0;
for r=1:35
C1h(r,:)=B2h(2*r-1,:);
end
C2h(35,65)=0;
for l=1:65
C2h(:,l)=C1h(:,2*l-1);
end
subplot(4,1,3)
image(C2h)
colormap(map)
title('第2层:35×65')
axis([0 258 0 140])
axis off
D1h(18,65)=0;
for r=1:18
D1h(r,:)=C2h(2*r-1,:);
end
D2h(18,33)=0;
for l=1:33
D2h(:,l)=D1h(:,2*l-1);
end
subplot(4,1,4)
image(D2h)
colormap(map)
title('第3层:18×33')
axis([0 258 0 140])
axis off
%拉普拉斯分解
figure(4)
Lp3l=D2l;
subplot(4,1,1)
image(Lp3l)
colormap(map)
axis([0 258 0 140])
axis off
title('3层:18×33')
F1l=interp2(D2l,'spline');
Lp2l=C2l-F1l;
subplot(4,1,2)
image(Lp2l)
colormap(map)
axis([0 258 0 140])
axis off
title('2层:35×65')
F2l=interp2(C2l,'spline');
F2l(70,129)=0;
Lp1l=B2l-F2l;
subplot(4,1,3)
image(Lp1l)
colormap(map)
axis([0 258 0 140])
axis off
title('1层:70×129')
F3l=interp2(B2l,'spline');
F3l(140,258)=0;
Lp0l=Bl-F3l;
subplot(4,1,4)
image(Lp0l)
colormap(map)
axis([0 258 0 140])
axis off
title('0层:140×258')
figure(5)
Lp3h=D2h;
subplot(4,1,1)
image(Lp3h)
colormap(map)
axis([0 258 0 140])
axis off
title('3层:18×33')
F1h=interp2(D2h,'spline');
Lp2h=C2h-F1h;
subplot(4,1,2)
image(Lp2h)
colormap(map)
axis([0 258 0 140])
axis off
title('2层:35×65')
F2h=interp2(C2h,'spline');
F2h(70,129)=0;
Lp1h=B2h-F2h;
subplot(4,1,3)
image(Lp1h)
colormap(map)
axis([0 258 0 140])
axis off
title('1层:70×129')
F3h=interp2(B2h,'spline');
F3h(140,258)=0;
Lp0h=Bh-F3h;
subplot(4,1,4)
image(Lp0h)
colormap(map)
axis([0 258 0 140])
axis off
title('0层:140×258')
%融合
figure(6)
for m0=1:140
for n0=1:258
if abs(Lp0l(m0,n0))>abs(Lp0h(m0,n0))
Lp0(m0,n0)=Lp0l(m0,n0);
else
Lp0(m0,n0)=Lp0h(m0,n0);
end
end
end
subplot(2,2,1)
image(Lp0)
colormap(map)
axis([0 258 0 140])
axis off
title('配准后第0层图像');
for m1=1:70
for n1=1:129
if abs(Lp1l(m1,n1))>abs(Lp1h(m1,n1))
Lp1(m1,n1)=Lp1l(m1,n1);
else
Lp1(m1,n1)=Lp1h(m1,n1);
end
end
end
subplot(2,2,2)
image(Lp1)
colormap(map)
axis([0 258 0 140])
axis off
title('配准后第1层图像');
for m2=1:35
for n2=1:65
if abs(Lp2l(m2,n2))>abs(Lp2h(m2,n2))
Lp2(m2,n2)=Lp2l(m2,n2);
else
Lp2(m2,n2)=Lp2h(m2,n2);
end
end
end
subplot(2,2,3)
image(Lp2)
colormap(map)
axis([0 258 0 140])
axis off
title('配准后第2层图像');
for m3=1:18
for n3=1:33
if abs(Lp3l(m3,n3))>abs(Lp3h(m3,n3))
Lp3(m3,n3)=Lp3l(m3,n3);
else
Lp3(m3,n3)=Lp3h(m3,n3);
end
end
end
subplot(2,2,4)
image(Lp3)
colormap(map)
axis([0 258 0 140])
axis off
title('配准后第3层图像');
%还原
figure(10)
Lf3=interp2(Lp3,'spline');
G2=Lp2+Lf3;
Lf2=interp2(G2,'spline');
Lf2(70,129)=0;
G1=Lp1+Lf2;
Lf1=interp2(G1,'spline');
Lf1(140,258)=0;
Lf0=Lp0+Lf1;
Lf0=Lf0*0.8;
image(Lf0)
colormap(map);
axis([0 516 0 280])
axis off
好像有点毛病和书上的原理有点区别,请大家帮忙改下!!!