全色和多光谱融合pansharpen的尝试

一个1波段全色地理tiff图像文件的文件名(.tif扩展)。
一个3或4波段的多光谱geotiff图像文件(RGB,近红外波段,按此顺序排列)。
使用GDAL工具
将多光谱Geotiff图像文件重采样到相同的更高维度
作为全色图像的地理tiff文件采用双三次插值。
这个文件被写到磁盘上。然后,对重采样的多光谱和
全色geotiff切片成块(使用gdal_retile.py)。为
每一对,更小的泛锐多光谱geotiff创建使用
4种泛锐化方法(每片产生4个新的MS geotiff):
(1)Brovey,
(2)主成分分析(PCA),
(3) FIHS(快速强度色相饱和度),
(4)小波
稍后,对于每种泛锐化方法,所有的瓦片都合并在一起(马赛克)
用四种方法进行泛锐化,形成4个较大的马赛克(使用gdal_merge.py)。

GitHub上找到代码,clone。
打开后发现为python2程序,进行改写为python3程序
运行,发现pywt.ravel_coeffs之类的方法显示不存在,
1、打开cmd终端。
2. pip uninstall pywt 。
3. pip install PyWavelets 。
4. 重装之后正常

运行,发现生成csv失败

  procTileMS  = subprocess.Popen([tileCmdMS],shell=True,stdout=subprocess.PIPE)
  procTileMS.wait()

  procTilePan = subprocess.Popen([tileCmdPan],shell=True,stdout=subprocess.PIPE)
  procTilePan.wait()

cmd命令中运行可以成功生成csv,考虑windows和linux的差别,去掉列表符号,即中括号后可以运行
procTilePan = subprocess.Popen(tileCmdPan,shell=True,stdout=subprocess.PIPE)

融合函数createMosaic,将小图通过gdal_merge进行融合

   def createMosaic( outname, outputTileNames ):
    '''function createMosaic( outname, outputTileNames ): 
    This static (class) method calls the gdal_merge.py Python script (which should be
    installed onto your system) to stitch-together a list of Geotiff image
    files into a single Geotiff. Hence, this function takes the list of Geotiff image
    files in outputTileNames, and passes them to gdal_merge.py such that they may
    be merged into a single Geotiff by a mosaic process. 

    Args:
      outname (str): Output string name of Geotiff mosaic.
      outputTileNames (list): List of strings for Geotiffs that should be mosaic together.

    mosaicCmd = gdalMergeLocation+' -o '+outname+' -of GTiff '
    mosaicCmdList = []
    mosaicCmdList.extend([mosaicCmd])
    mosaicCmdList.extend(outputTileNames)
    mosaicCmd = ' '.join(mosaicCmdList)
    proc = subprocess.Popen([mosaicCmd],shell=True,stdout=subprocess.PIPE)
    proc.wait()

运行到最后的时候,可以看到文件夹里的4种小图片都已经成功生成,但程序运行完成后却没有想象中的4种融合图出现,
推测是融合阶段出了问题,找到融合函数,发现cmd命令中竟然没有加上python解释器…
mosaicCmd = pythonInterpreter + ' ' + mosaicCmd
加上后成功.

生成的4种图分别为
(1) a 3 or 4 band multispectral Geotiff image created using Brovey pan-sharpening
(2) a 3 or 4 band multispectral Geotiff image created using FIHS pan-sharpening
(3) a 3 or 4 band multispectral Geotiff image created using Wavlet pan-sharpening
(4) a 3 or 4 band multispectral Geotiff image created using PCA pan-sharpening

其中小波的图Wavlet 是黑的,不知道为什么…

你可能感兴趣的:(python)