IDL 二维数组/图像的Sen斜率实现

参考文献《基于Sen+Mann-Kendall 的北京植被变化趋势分析》

针对二维数组/图像:

function Sen_slope,x1,y1,x2,y2
  s = (y2 - y1)/(x2 - x1)
  return,s
  
pro Sen_slope_image
  COMPILE_OPT idl2
  e = ENVI(/headless)
  tic
  ;--------------------------------------------------------------------------------
  ;打开图像,将所有图像存成band,合成一个raster
  ;打开一个band,记为basraster,获取spatialref
  ;raster命名为bandarray
  ;波段数为count
  ;uri为outpath1
  ;--------------------------------------------------------------------------------
  ;计算出的斜率uri为outpath2
  ;--------------------------------------------------------------------------------
  ;输出的斜率中值uri为outpath3
  ;--------------------------------------------------------------------------------
  
  ;计算斜率
  newcount = (count * (count-1))/2 ;计算新波段数
  slope = objarr(newcount) ;存放所有计算出的斜率波段

  bandnum = size(bandarray,/n_elements);计算合成新波段数组的大小
  raster = e.openraster(outpath1)
  m = 0 
  for j = 0, bandnum -1 do begin
    for i = 0, bandnum -1 do begin
      if i lt j then begin
        band1 = raster.getdata(bands = i)
        band2 = raster.getdata(bands = j)
        s = Sen_slope(i,band1,j,band2) ;计算斜率
        newraster = enviraster(s,uri = e.GetTemporaryFilename(), SPATIALREF = basraster.spatialref)
        newraster.save ;存成raster才能用envitask
        slope[m] = newraster
        m = m + 1
      endif
    endfor
  endfor
  Task = ENVITask("BuildBandStack")
  Task.SPATIAL_REFERENCE  = basraster.spatialRef
  Task.INPUT_RASTER = slope
  Task.OUTPUT_RASTER_URI = outpath2
  Task.Execute
  ;--------------------------------------------------------------------------------
  ;计算中值
  newraster = e.openraster(outpath2)
  slopeband  = newraster.getdata();打开所有波段
  medianslope = fltarr(columns,rows)

  for t = 0, columns-1 do begin ;列
    for n = 0, rows-1 do begin ;行
      medianslope[t,n] = median(slopeband[t,n,*]);列,行,波段数
    endfor
  endfor
  newfile = enviraster(medianslope,uri = outpath3,SPATIALREF = basraster.spatialref)
  newfile.save

  toc
end

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值