Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中按最小值组合重叠光栅_Python_Gdal_Blending_Photographic Mosaic - Fatal编程技术网

python中按最小值组合重叠光栅

python中按最小值组合重叠光栅,python,gdal,blending,photographic-mosaic,Python,Gdal,Blending,Photographic Mosaic,我想结合一些单波段光栅图像。我希望重叠被处理,以便选择像素中的最小值。 所有图像都具有相同的投影 我试着查看gdalwarp和gdal_merge(在命令行中),但在重叠部分,它们只使用上一张图像中的值 我也看到过使用PIL混合或粘贴的建议,但这些建议需要一个alpha层,它指示重叠应该如何混合,当然我没有 是否有人知道如何根据图像中的实际值进行重叠???,因为据我所知,使用标准命令行实用程序无法做到这一点。您可以尝试“gdal_calc.py”,它通常与gdal一起提供,这要求光栅具有相同的尺

我想结合一些单波段光栅图像。我希望重叠被处理,以便选择像素中的最小值。 所有图像都具有相同的投影

我试着查看gdalwarp和gdal_merge(在命令行中),但在重叠部分,它们只使用上一张图像中的值

我也看到过使用PIL混合或粘贴的建议,但这些建议需要一个alpha层,它指示重叠应该如何混合,当然我没有


是否有人知道如何根据图像中的实际值进行重叠???

,因为据我所知,使用标准命令行实用程序无法做到这一点。您可以尝试“gdal_calc.py”,它通常与gdal一起提供,这要求光栅具有相同的尺寸,因此可能需要一些预处理(例如gdalwarp)。至少两个光栅可以通过以下方式计算:

python gdal_calc.py -A file1.tif -B file2.tif --calc="minimum(A,B)" --outfile=res.tif
我不太确定在没有重叠的区域会发生什么,也许您需要添加nodata关键字,更多信息请访问:

您必须指定到
gdal\u calc.py
的完整路径

对于未来版本: 从GDAL 2.2开始,支持用Python编写的VRT像素函数:

然后,您将能够使VRT看起来像:

<VRTDataset rasterXSize="20" rasterYSize="20">
  <SRS>EPSG:26711</SRS>
  <GeoTransform>440720,60,0,3751320,0,-60</GeoTransform>
  <VRTRasterBand dataType="Byte" band="1" subClass="VRTDerivedRasterBand">
    <PixelFunctionType>add</PixelFunctionType>
    <PixelFunctionLanguage>Python</PixelFunctionLanguage>
    <PixelFunctionCode><![CDATA[
import numpy as np
def add(in_ar, out_ar, xoff, yoff, xsize, ysize, raster_xsize,
                   raster_ysize, buf_radius, gt, **kwargs):
    np.round_(np.clip(np.minimum(in_ar, axis = 0, dtype = 'uint16'),0,255),
              out = out_ar)
]]>
    </PixelFunctionCode>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">byte.tif</SourceFilename>
    </SimpleSource>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">byte2.tif</SourceFilename>
    </SimpleSource>
  </VRTRasterBand>
</VRTDataset>

EPSG:26711
440720,60,0,3751320,0,-60
添加
python
byte.tif
字节2.tif
同样从GDAL2.2开始,将有内置的像素函数,这是一个好主意。我还没有看到像min、max和mean这样的聚合,但一旦有了基础设施,这应该很容易添加。

对于超过两个参数的最小值,您可以执行
minimum(最小值(a,B),C)