资源简介
N-FINDR是一种端元提取方法,本代码是利用MATLAB结合N-FINDR原理,进行编程,输入是高光谱数据,程序内包括了高光谱数据输入,N-FINDR处理,端元结果输出
代码片段和文件信息
function N_FINDR()
% read a hyperspectral image from sample data of ENVI.
nlines = 254;
npixels = 3454;
nbands = 37;
nlength = nlines*npixels;
%hs_img = multibandread(‘cup95eff.int‘ [nlines npixels nbands] ...
% ‘int16‘ 0 ‘bil‘ ‘ieee-le‘); %从二进制文件中读取BSQBILBIP数据
%hs_img= multibandread(‘F:\285-destripe_new_flaash_wv_sg_37‘[nlines npixels nbands]...
% ‘double‘0‘bsq‘‘ieee-be‘);%从二进制文件中读取BSQ文件
test_hdr=‘F:\test_img.hdr‘;%头文件的地址
maindata = ReadImg(test_hdr);%读取头文件相应的.img高光谱数据
hs_img=maindata;
% reduct the dimensionality of image to be one less the number of end-
% mumbers by using PCA.
% standardize the data by dividing each column by its standard deviation.
hs_img = reshape(hs_img [] nbands);%改变矩阵的形状,但是元素个数不变
meanh = mean(hs_img);%求均值
stdh = std(hs_img);%求标准差
sd_img = (hs_img-repmat(meanhnlength1))./repmat(stdhnlength1);%repmat:将meanh作为元素复制nlength*1块%标准化图像
[pcoef score latent] = princomp(sd_img);
%做PCA。~是对主分的打分也就是原矩阵在主成分空间的表示,pcoef是元矩阵对应的协方差矩阵对的所有特征向量,latent协方差矩阵的特征值
%latent是向量还是矩阵?
% determine the number of endmembers by calculating the contribution of
% %计算主成分的贡献来确定端元的数量
% principal components.
perc = cumsum(latent)/sum(latent)*100;%cumsum计算一个数据各行的累加值返回值与latent行列相同,sum是将latent的所有元素相加
Nend = sum(perc<99.5)+1;%确定端元的数量
% get the principal components.确定主成分的贡献量
pca_img = sd_img*pcoef(:1:Nend-1);
% repeat 50 times to find the endmembers with largest
% volume.%迭代50次找到最大体积的端元
Ntimes = 50;
locs = zeros(NtimesNend);
V_max = zeros(Ntimes1);
for i = 1:Ntimes%tic和toc计算程序的时间
[locs(i:) V_max(i1)] = finder(pca_img nlength Nend);%N-finder的函数
end
[score ind] = max(V_max);
loc = locs(ind :);
% calculate the abundance of each endmember for each
% pixel.计算对于每个像素的每个端元的丰度(最小二乘法)
M = ones(Nend);
M(2:end:) = pca_img(loc:)‘;
C = zeros(Nend nlength);
for i = 1:nlength
p = [1; pca_img(i:)‘];
C(:i) = lsqnonneg(M p);%返回C>=0约束下norm(M*C-p)的最小值向量
% C(:i) = lsqlin(E p [][][][]01);
end
save(‘F:\NFINDR_res.txt‘‘C‘‘-ASCII‘);
%stop;
% end function N_FINDR.
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [loc V_max] = finder(pca_img nlength Nend)
% randomly select pixels as initial endmembers.随机选择像素作为初始端元,求单形体的体积
ind = unidrnd(nlength 1 Nend);%产生从1到nlength所指定的最大数数之间的离散均匀随机数,生成1*nend矩阵
E = ones(Nend);%产生nend*nend全是1的数组
E(2:end:) = pca_img(ind:)‘;%随机选择nend个像素组成最初的端元矩阵
dentor = factorial(Nend-1);%求(端元-1)的阶乘
V_max = abs(det(E))/dentor;%求E的行列式在取绝对值最后除以dentor。求体积
% find the largest volume and set the corresponding pixels as
% endmembers.找到最大的体积,并设置相应的像素作为端元
for i = 1:Nend % loop over each endmember.循环每个端元
i_max = ind(i);
for j = 1:nlength % loop over each pixel.循环每个像素
E(2:endi) = pca_img(j:)‘;
V = abs(det(E))/dentor;
相关资源
- RPCA 源码 matlab yi Ma
- matlab的图像边缘的提取和函数实现
- ICA的人脸识别MATLAB源码
- 基于MATLAB的医学图像处理系统
- MIMO通信系统_MATLAB仿真代码
- 数字基带传输系统的matlab仿真实现
- 十字路口车流通量及车身颜色的统计
- Matlab实现Moravec算子程序
- 语音信号处理实验matlab程序
- Turbo码matlab仿真程序204389
- SFLA算法 matlab
- matlab构造4阶m序列,显示波形及自相关
- 基于Matlab的SVM含数据
- matlab液压系统仿真
- Lyapunov指数计算的Matlab code
- matlab HARQ仿真
- 机器人控制系统设计与matlab仿真程序
- Matlab实现二值图像的边缘检测 getedg
- 史上最全的AMESim-Matlab 联合仿真设置步
- matlab时延估计算法的互相关函数
- matlab 人脸检测
- bp神经网络算法的一个matlab实现
- 8*8矩阵zigzag反扫描 matlab代码
- matlab VAR模型应用,和PPT
- 室内可见光通信一次反射功率分布m
- 室内可见光通信信噪比计算MATLAB代码
- matlab图像叠加
- 语音信号共振峰提取Matlab
- polar3d_Matlab
- matlab串口接收程序
评论
共有 条评论