首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重采样图像rasterio/gdal,Python

重采样图像rasterio/gdal,Python
EN

Stack Overflow用户
提问于 2020-07-20 12:48:02
回答 1查看 3.2K关注 0票数 0

如何使用双线性插值对单频带GeoTIFF进行重采样?

代码语言:javascript
复制
import os

import rasterio
from rasterio.enums import Resampling
from rasterio.plot import show,show_hist
import numpy as np

if __name__ == "__main__":
    

    input_Dir = 'sample.tif'
    #src = rasterio.open(input_Dir) 
    #show(src,cmap="magma")

    upscale_factor = 2

    with rasterio.open(input_Dir) as dataset:
        
        # resample data to target shape
        data = dataset.read(
            out_shape=(
                dataset.count,
                int(dataset.height * upscale_factor),
                int(dataset.width * upscale_factor)
            ),
            resampling=Resampling.bilinear
        )

        # scale image transform
        transform = dataset.transform * dataset.transform.scale(
            (dataset.width / data.shape[-1]),
            (dataset.height / data.shape[-2])
        )
        show(dataset,cmap="magma",transform=transform)

我已经尝试了以下代码,我的输出如下:

我正在尝试实现以下输出:

EN

回答 1

Stack Overflow用户

发布于 2020-07-22 12:46:11

一种选择是使用GDAL python绑定。然后,您可以在内存中执行重采样(或者,如果需要,也可以保存图像)。假设旧的光栅分辨率为0.25x0.25,并且重采样为0.10x0.10:

代码语言:javascript
复制
from osgeo import gdal

input_Dir = 'sample.tif'

ds = gdal.Translate('', input_Dir, xres=0.1, yres=0.1, resampleAlg="bilinear", format='vrt')

如果您想保存图像,请将输出文件路径替换为第一个参数的空字符串,并将格式更改为'tif'!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62988817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档