MATLAB实现遥感图像预处理——图像融合

前言

这些代码均是使用最基础的方法,通过一步一步迭代过程来理解算法的原理及实现过程,并不采用于实用工程,读者以此作为学习参考即可。

图像融合的概念

综合和提取两个或多个源的图像信息,获得对同一场景或者目标更为准确、全面、可靠的图像,使之更适合于人眼感知或计算机后续处理。

简单的图像融合算法

在这里插入图片描述

彩色图像的分解与合成

在这里插入图片描述

通过图像融合得到变化检测差异图

在这里插入图片描述

运行结果

简单图像融合算法

注:第三幅图像为均值融合图像。
在这里插入图片描述

彩色图像转换为灰度图

在这里插入图片描述
在这里插入图片描述

各分量处理重新融合

在这里插入图片描述

突出感兴趣目标

在这里插入图片描述
在这里插入图片描述
先将图像分解成红绿蓝三个分量,然后将红色分量中感兴趣目标与其背景分离开,具体如上图两部分。然后将仅含感兴趣目标的红色分量取对数变换,再与背景图相加起来,组成新的红色分量图。然后再将新的红色分量图与原来的蓝色、绿色分量图合成为新的彩色图像,图像中的感兴趣目标就被突出。

图像融合检测差异

在这里插入图片描述
在这里插入图片描述

源代码

clc;
clearvars
close all;

%简单图像融合灰度平均
san1=double(imread('san_1.bmp'));
san2=double(imread('san_2.bmp'));
[xx,yy,zz]=size(san1);
san3=zeros(xx,yy);
san4=zeros(xx,yy);
san5=zeros(xx,yy);
for i=1:xx
    for j=1:yy
        san3(i,j)=(san1(i,j)+san2(i,j))/2;
        san4(i,j)=max(san1(i,j),san2(i,j));
        san5(i,j)=min(san1(i,j),san2(i,j));
    end
end
figure(1)
subplot(3,2,1),imshow(san1,[]),title('原图像1');
subplot(3,2,2),imshow(san2,[]),title('原图像2');
subplot(3,2,3),imshow(san3,[]),title('均值融合图像');
subplot(3,2,4),imshow(san4,[]),title('最大值融合图像');
subplot(3,2,5),imshow(san5,[]),title('最小值融合图像');
%彩色图像的分解与合成
%彩色图转换为灰度图
Im1=imread('ygtx.jpg');
rre=Im1(:,:,1);
rgr=Im1(:,:,2);
rbl=Im1(:,:,3);
[x,y,z]=size(Im1);
Im2=0.2989*rre+0.5870*rgr+0.1140*rbl;
Im3=rgb2gray(Im1);
Imcha=Im3-Im2;
figure(2)
subplot(2,2,1),imshow(Im1),title('原图像');
subplot(2,2,2),imshow(rre,[]),title('红色分量');
subplot(2,2,3),imshow(rgr,[]),title('绿色分量');
subplot(2,2,4),imshow(rbl,[]),title('蓝色分量');
figure(3)
subplot(1,3,1),imshow(Im2),title('转换合成的灰度图');
subplot(1,3,2),imshow(Im3),title('自带函数转换的灰度图');
subplot(1,3,3),imshow(Imcha),title('两幅灰度图的差');
%变换后的彩色图像合成
%蓝色分量加高斯噪声
[width,height,z]=size(rbl);
av1=0;
std1=0.1;
u11=rand(width,height);
u21=rand(width,height);
x1=std1*sqrt(-2*log(u11)).*cos(2*pi*u21)+av1;
tbl=double(rbl)/255+x1;
tbl=uint8(255*tbl);
%绿色分量进行对数变换
tgr=uint8(22*log(double(rgr)+1));
%红色分量进行图像反转
tre=255-rre;
Im4=cat(3,tre,tgr,tbl);
figure(4)
subplot(2,2,1),imshow(tbl);title('加入高斯噪声的蓝色分量图像');
subplot(2,2,2),imshow(tgr);title('对数变换的绿色分量图像');
subplot(2,2,3),imshow(tre);title('反转的红色分量图像');
subplot(2,2,4),imshow(Im4);title('变换后合成的彩色图像');
%突出感兴趣目标
tq=zeros(x,y);
for i=120:190
    for j=330:520
        tq(i,j)=1;
    end
end
tqh=zeros(x,y);
for i=1:x
    for j=1:y
        tqh(i,j)=double(rre(i,j))*tq(i,j);
    end
end
tq=not(tq);
tqhb=zeros(x,y);
for i=1:x
    for j=1:y
        tqhb(i,j)=double(Im1(i,j))*tq(i,j);
    end
end
tqh=20*log(double(tqh)+1);
trre=tqhb+tqh;
Im5=cat(3,trre,rgr,rbl);
figure(5)
subplot(2,2,1),imshow(Im1),title('原图像');
subplot(2,2,2),imshow(tqh,[]),title('红色分量提取子图');
subplot(2,2,3),imshow(tqhb,[]),title('红色分量提取背景图');
subplot(2,2,4),imshow(trre,[]),title('合成红色分量图');
figure(6)
subplot(1,1,1),imshow(Im5),title('突出目标的图像');
%通过图像融合检测差异
%1差异
I1=zeros(xx,yy);
for i= 2:xx-1
    for j= 2:yy-1
        u11=san1(i-1:i+1,j-1:j+1);
        u1=mean(u11(:));
        u12=san2(i-1:i+1,j-1:j+1);
        u2=mean(u12(:));
        I1(i,j)=1-min(u1/u2,u2/u1);
    end
end
I2=abs(log(double(san2))-log(double(san1)));
figure(7)
subplot(2,2,1),imshow(san1,[]),title('原图像1');
subplot(2,2,2),imshow(san2,[]),title('原图像2');
subplot(2,2,3),imshow(I1,[]),title('1-min差异图I1');
subplot(2,2,4),imshow(I2,[]),title('log差异图I2');
%2组合差异图像
zhcy1=zeros(xx,yy);
for i=1:xx
    for j=1:yy
        if isinf(I1(i,j))|isinf(I2(i,j))
            tmp=Inf;
        elseif isnan(I1(i,j))|isnan(I2(i,j))
            tmp=NaN;
        else
            tmp=0.5*I1(i,j)+0.5*I2(i,j);
        end
        zhcy1(i,j)=tmp;
    end
end
zhcy2=zeros(xx,yy);
for i=1:xx
    for j=1:yy
        if isinf(I1(i,j))|isinf(I2(i,j))
            tmp=Inf;
        elseif isnan(I1(i,j))|isnan(I2(i,j))
            tmp=NaN;
        else
            tmp=0.9*I1(i,j)+0.1*I2(i,j);
        end
        zhcy2(i,j)=tmp;
    end
end
I1_fft=fftshift(fft2(double(uint8(I1))));
I2_fft=fftshift(fft2(double(uint8(I2))));
zhcy3_fft=zeros(xx,yy);
m_mid=fix(xx/2);
n_mid=fix(yy/2);
d0=80;
for i=1:xx
    for j=1:yy
        d=sqrt((i-m_mid)^2+(j-n_mid)^2);
        if d<=d0
            zhcy3_fft(i,j)=(I1_fft(i,j)+I2_fft(i,j))/2;
        else
            zhcy3_fft(i,j)=min(I1_fft(i,j)+I2_fft(i,j));
        end
    end
end
zhcy3=real(ifft2(ifftshift(zhcy3_fft)));
figure(8)
subplot(2,2,1),imshow(zhcy1,[]),title('I1和I2均值差异图');
subplot(2,2,2),imshow(zhcy2,[]),title('I1权值0.9和I2权值0.1均值差异图');
subplot(2,2,3),imshow(zhcy3,[]),title('低频均值、高频取小的图像');


最开始写的代码比较随意,图片也是随意找的,没有注释,给大家磕了。。
  • 12
    点赞
  • 70
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值