[Digital image processing matlab] (PCA-based image fusion)

[Digital image processing matlab] (PCA-based image fusion)

HR is a high-resolution image, and MS is a multispectral image. (Note: The resolutions of my two images are the same, so there was no resampling code at the time. If the resolutions are different, you should first sample the multispectral image to the same resolution as the panchromatic band)

function F=PCA_melt(HR,MS)
%调用代码-------------------------------
%Image1=imread('HR.jpg');Image2=imread('MS.jpg');
%PCA_melt(Image1,Image2);
%--------------------------------------
HR=im2double(HR);
MS=im2double(MS);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PCA变换
[row,column,bands]=size(MS);
X=reshape(MS,[row*column,bands]);     %每一波段的数据保存在一列  
Cov=cov(X);        %求方差协方差矩阵,(i,j)个元素等于X的第i列向量与第j列向量的方差
[vector,value]=eig(Cov);     %a为特征向量矩阵(一列为一个特征向量),b为特征值矩阵(排序为从小到大)
vector=fliplr(vector);        %fliplr()翻转特征值与特征向量矩阵,实现由大到小排序
value=fliplr(value);   value=flipud(value); 
%Y=vector'*X',    %3*3/3*b--3*b 每一行为一个波段
Y=X*vector;     %每一列为一个波段

Major=reshape(Y(:,1),[row,column]);
[counts,X]=imhist(Major/max(max(Major)));
HR1=histeq(HR,counts);  %高分辨率影像进行直方图均衡化
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%高分辨率影像替代第一主分量
Y(:,1)=reshape(HR1*max(max(HR)),[row*column,1]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PCA逆变换%%%%%%%%
Image1=Y*inv(vector);   %pexel*3-3*3
Image1=reshape(Image1,[row,column,bands]);
imshow(Image1);title('基于PCA的影像融合');


end

test:
insert image description here

Guess you like

Origin blog.csdn.net/gsgs1234/article/details/123427714