高光谱图像端元提取——vertex component analysis(VCA/python)

2023-11-12

在高光谱图像中,VCA是一种常用的端元提取方法,算法来源:
Vertex Component Analysis: A Fast Algorithm to Unmix Hyperspectral Data” submited to IEEE Trans. Geosci. Remote Sensing,2004
其python代码如下:

# -*- coding: utf-8 -*-
import sys
import scipy as sp
import scipy.linalg as splin


#############################################
# Internal functions
#############################################

def estimate_snr(Y,r_m,x):

  [L, N] = Y.shape           # L number of bands (channels), N number of pixels
  [p, N] = x.shape           # p number of endmembers (reduced dimension)
  
  P_y     = sp.sum(Y**2)/float(N)
  P_x     = sp.sum(x**2)/float(N) + sp.sum(r_m**2)
  snr_est = 10*sp.log10( (P_x - p/L*P_y)/(P_y - P_x) )

  return snr_est



def vca(Y,R,verbose = True,snr_input = 0):
# Vertex Component Analysis
#
# Ae, indice, Yp = vca(Y,R,verbose = True,snr_input = 0)
#
# ------- Input variables -------------
#  Y - matrix with dimensions L(channels) x N(pixels)
#      each pixel is a linear mixture of R endmembers
#      signatures Y = M x s, where s = gamma x alfa
#      gamma is a illumination perturbation factor and
#      alfa are the abundance fractions of each endmember.
#  R - positive integer number of endmembers in the scene
#
# ------- Output variables -----------
# Ae     - estimated mixing matrix (endmembers signatures)
# indice - pixels that were chosen to be the most pure
# Yp     - Data matrix Y projected.   
#
# ------- Optional parameters---------
# snr_input - (float) signal to noise ratio (dB)
# v         - [True | False]
# ------------------------------------
#
# Author: Adrien Lagrange (adrien.lagrange@enseeiht.fr)
# This code is a translation of a matlab code provided by 
# Jose Nascimento (zen@isel.pt) and Jose Bioucas Dias (bioucas@lx.it.pt)
# available at http://www.lx.it.pt/~bioucas/code.htm under a non-specified Copyright (c)
# Translation of last version at 22-February-2018 (Matlab version 2.1 (7-May-2004))
#
# more details on:
# Jose M. P. Nascimento and Jose M. B. Dias 
# "Vertex Component Analysis: A Fast Algorithm to Unmix Hyperspectral Data"
# submited to IEEE Trans. Geosci. Remote Sensing, vol. .., no. .., pp. .-., 2004
# 
# 

  #############################################
  # Initializations
  #############################################
  if len(Y.shape)!=2:
    sys.exit('Input data must be of size L (number of bands i.e. channels) by N (number of pixels)')

  [L, N]=Y.shape   # L number of bands (channels), N number of pixels
       
  R = int(R)
  if (R<0 or R>L):  
    sys.exit('ENDMEMBER parameter must be integer between 1 and L')
        
  #############################################
  # SNR Estimates
  #############################################

  if snr_input==0:
    y_m = sp.mean(Y,axis=1,keepdims=True)
    Y_o = Y - y_m           # data with zero-mean
    Ud  = splin.svd(sp.dot(Y_o,Y_o.T)/float(N))[0][:,:R]  # computes the R-projection matrix 
    x_p = sp.dot(Ud.T, Y_o)                 # project the zero-mean data onto p-subspace

    SNR = estimate_snr(Y,y_m,x_p);
    
    if verbose:
      print("SNR estimated = {}[dB]".format(SNR))
  else:
    SNR = snr_input
    if verbose:
      print("input SNR = {}[dB]\n".format(SNR))

  SNR_th = 15 + 10*sp.log10(R)
         
  #############################################
  # Choosing Projective Projection or 
  #          projection to p-1 subspace
  #############################################

  if SNR < SNR_th:
    if verbose:
      print("... Select proj. to R-1")
                
      d = R-1
      if snr_input==0: # it means that the projection is already computed
        Ud = Ud[:,:d]
      else:
        y_m = sp.mean(Y,axis=1,keepdims=True)
        Y_o = Y - y_m  # data with zero-mean 
         
        Ud  = splin.svd(sp.dot(Y_o,Y_o.T)/float(N))[0][:,:d]  # computes the p-projection matrix 
        x_p =  sp.dot(Ud.T,Y_o)                 # project thezeros mean data onto p-subspace
                
      Yp =  sp.dot(Ud,x_p[:d,:]) + y_m      # again in dimension L
                
      x = x_p[:d,:] #  x_p =  Ud.T * Y_o is on a R-dim subspace
      c = sp.amax(sp.sum(x**2,axis=0))**0.5
      y = sp.vstack(( x, c*sp.ones((1,N)) ))
  else:
    if verbose:
      print("... Select the projective proj.")
             
    d = R
    Ud  = splin.svd(sp.dot(Y,Y.T)/float(N))[0][:,:d] # computes the p-projection matrix 
                
    x_p = sp.dot(Ud.T,Y)
    Yp =  sp.dot(Ud,x_p[:d,:])      # again in dimension L (note that x_p has no null mean)
                
    x =  sp.dot(Ud.T,Y)
    u = sp.mean(x,axis=1,keepdims=True)        #equivalent to  u = Ud.T * r_m
    y =  x / sp.dot(u.T,x)

 
  #############################################
  # VCA algorithm
  #############################################

  indice = sp.zeros((R),dtype=int)
  A = sp.zeros((R,R))
  A[-1,0] = 1

  for i in range(R):
    w = sp.random.rand(R,1);   
    f = w - sp.dot(A,sp.dot(splin.pinv(A),w))
    f = f / splin.norm(f)
      
    v = sp.dot(f.T,y)

    indice[i] = sp.argmax(sp.absolute(v))
    A[:,i] = y[:,indice[i]]        # same as x(:,indice(i))

  Ae = Yp[:,indice]

  return Ae,indice,

其中,vca()参数共有四个,分别是Y、R、verbose以及snr_input,一般我们只输入Y和R:

  • Y表示L(channels) x N(pixels)的矩阵,如常见数据集Samson的Y为(156, 95*95)
  • R表示该场景中的端元数
  • verbose为True或False(可选)
  • snr_input表示信噪比(可选)

提取后的返回值有两个:Ae、indice

  • Ae表示估计后的矩阵,shape为(L, R)
  • indice表示被选择为纯度最高的索引值
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

高光谱图像端元提取——vertex component analysis(VCA/python) 的相关文章

随机推荐

  • React Hooks 学习笔记

    大家好 小编最近在梳理 React Hook 的相关内容 由于看视频 看书 自己做项目总觉得缺点什么 总觉得看过了 内容太简单 有啥好写的 但是过了一段时间 感觉有些东西又模糊了 同时又觉得怕简单 写了也不一定有人看 但是想想 还是整理成文
  • iOS开发之第三方支付支付宝支付教程,史上最新最全第三方支付宝支付方式实现、支付宝集成教程,支付宝实现流程

    本章项目demo https github com zhonggaorong alipayDemo 支付宝支付大致流程为 1 公司与支付宝进行签约 获得商户ID partner 和账号ID seller 和私钥 privateKey 开发中
  • 【自然语言处理】主题建模:Top2Vec(理论篇)

    主题建模 Top2Vec 理论篇 Top2Vec 是一种用于 主题建模 和 语义搜索 的算法 它自动检测文本中出现的主题 并生成联合嵌入的主题 文档和词向量 算法基于的假设 许多语义相似的文档都可以由一个潜在的主题表示 首先 创建文档和词向
  • 没有头的猫在笛卡尔坐标系上随机漫步(未完成)

    想用python模拟随机运动 布朗运动 BROWNIAN MOTION 英国科学家布朗在两百年前第一次观察到水分子推动花粉颗粒在水面做不规则运动 现在我们也想用电脑模拟 在无外力作用下 花粉颗粒在水面的随机运动 如何实现呢 详细解释直接写在
  • LSTM 和 Bi-LSTM

    承上启下 承接上文介绍过的 SimpleRNN 这里介绍它的改进升级版本 LSTM RNN 和 LSTM 比较 RNN 的记忆很短 容易产生梯度消失的长依赖问题 而 LSTM 可以解决这个问题 它有更长的记忆 RNN 模型比较简单 只有一个
  • c++处理数据

    处理数据 简单变量 const限定符 类型转换和auto声明 整型 char类型 字符和小整数 成员函数cout put 通用字符名 signed char和unsigned char wchar t 浮点数 bool类型 c 算术运算符
  • Python入门笔记(1)

    纯小写的就是python的BIF 内置函数 dir builtins ArithmeticError AssertionError AttributeError BaseException BlockingIOError BrokenPip
  • 避免Unity错误剥离代码

    开启ProjectSettings里的Strip Engine Code项目后 Unity会尝试剥离未使用的引擎代码 以降低包体大小和运行时内存占用 但是某些运行时需要的组件会被错误剥离
  • Hibernate之关于多对多单向关联映射

    Hibernate 之关于多对多单向关联映射 老师和学生 最典型的多对多关联 Teacher和Student 所谓单向意思就是说 老师知道自己的教的是哪些学生而学生不知道是哪些老师教 也可以这么说 在查询的时候 通过老师可以级联查询出学生
  • 有些话,只说给懂的人听

    生活中最 孤独的时候 往往不是因为孤身一人 而是即使身边有很多人 有些心事依旧无人能懂 以前的时候 我们常常会把所有的喜怒悲欢 都说与别人听 后来渐渐变得沉默了 不是因为学会了独自消化 只是明白了 有些话只能说给懂的人听 人与人之间 只有彼
  • mybatis+mysql insert时返回自增主键

    mybatis mysql insert时返回自增主键 mysqlmybatisinsert返回自增主键 使用mybatis执行insert操作时 需要返回自增主键 网上清一色的答案 useGeneratedKeys设置为true keyP
  • qt开发使用camera类获取摄像头信息并拍照保存

    首先是UI布局 在pro文件中添加两个类 QT multimedia QT multimediawidgets 然后我们需要包含几个摄像头使用的头文件并创建摄像头的对象 include
  • win10远程桌面的坑

    win10的远程桌面的确是清晰度非常好 操作非常流程的 但是还是有坑的 举两个踩坑例子 1 录屏软件在远程桌面退出后无效了 无法录制屏幕了 2 监控客户端在退出远程桌面后 再进去远程桌面 打圈圈卡死 因此一些应用不适合在win10远程桌面办
  • GNS3 配置GRE

    1 简述 GRE Generic Routing Encapsulation GRE是一种最传统的隧道协议 其根本功能就是要实现隧道功能 以实现异地网络之间可以通过内部私网相互访问 以上图为例 假设IP地址为10 1 1 1的XP1想访问I
  • 基于Zigbee的SHT10温湿度数据采集系统(已实现控制12个终端节点)——Zigbee协调器主要代码解析

    之前实现了基于Zigbee的SHT10温湿度数据采集系统 这里来重新复盘一些主要的知识和代码 写在前面 1 功能介绍 使用Zigbee终端节点采集环境的温度和湿度数据 然后将数据无线发送的Zigbee协调器 最后在电脑端显示获得到的数据 2
  • Ubuntu初学思维导图(后继续补充)

    关于虚拟机 Ubuntu的命令内容简要 1 创建用户 sudo adduser user01 创建用户时 同步创建对应组 同步创建家目录 sudo useradd user02 仅创建用户 单独设置完密码后 才能登陆 2 修改用户密码 su
  • http请求头部(header)详解

    当我们在浏览器中访问一个网站时 我们的浏览器实际上会向该网站发送一个 HTTP 请求 而 HTTP 请求头部 Header 则是一组包含请求信息的键值对 用来描述 HTTP 请求的各种属性和特征 以下是 HTTP 请求头部的一些常见属性和含
  • linux重启服务的脚本命令

    最近做网站测试 每次测试完成都要重启服务 为此写了一个简单的shell脚本 linux服务重启shell脚本示例 2014年12月18日 linux服务重启脚本 如何实现linux服务的定时重启 可以借助shell脚本来完成 ps命令捕获进
  • 方差分析在特征筛选中的应用

    方差分析在特征筛选中的应用 方差分析 Analysis of Variance 简称ANOVA 是一种常见的统计分析方法 它可以用于比较两个或多个组之间的均值差异 在机器学习中 我们可以应用方差分析来进行特征筛选 从而得到对模型有显著影响的
  • 高光谱图像端元提取——vertex component analysis(VCA/python)

    在高光谱图像中 VCA是一种常用的端元提取方法 算法来源 Vertex Component Analysis A Fast Algorithm to Unmix Hyperspectral Data submited to IEEE Tra