资源简介
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;
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论