Python遥感图像处理指南(5)-投影、镶嵌、裁剪和叠加

        在前几章中,我们可以提取到水体掩膜,但我们的算法有时候不是很准确,需要其他数据源来进行对比分析,本章我们将利用全球水面数据集来进行教学操作,该数据提供了过去三十六年全球范围内水面的位置和时间分布图,并提供了有关水面范围和变化的统计数据,这是一个非常实用的全球水资源研究数据库。

1、 数据下载

        进入网站(自己想办法),找到之前哨兵影像对应的区块,我之前下载的是位于巴西的70W 0N and 60W 0N两个图幅,只需点击相应的数据块,然后选择下方出现的出现链接即可。

2、加载数据

        下载数据后,我们就可以使用 rasterio 打开这两张图。此外,我们还将使用之前文章中定义的 load_landsat_image 加载图像,但只需做一个非常简单的修改。我们将返回一个包含数据集的字典,而不是仅仅以数组形式返回包含波段的图像字典,使用 matplotlib 的 subplots 函数来显示最近加载的图像

import rasterio
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np

def load_landsat_image(img_folder, bands):
    # initialize the dictionaries
    image = {}
    ds = {}
    
    path = Path(img_folder)
    
    # loop through the given bands to load
    for band in bands:
        # considering the landsat images end with *_SR_B#.TIF, we will use it to locate the correct file
        file = next(path.glob(f'*{band}.tif'))
        print(f'Opening file {file}')
        ds.update({band: rasterio.open(file)})
        image.update({band: ds[band].read(1)})

    return image, ds

# load the image
img, image_ds = load_landsat_image('D:/Images/Input/Landsat/LC08_L2SP_231062_20201026_20201106_02_T1/', ['B2', 'B3', 'B4'])

# create the RGB for the image
rgb = np.stack([img['B4'], img['B3'], img['B2']], axis=2)
rgb = rgb / rgb.max()
               
# load the water masks
water1_ds = rasterio.open('D:/Images/Input/Landsat/occurrence_70W_0Nv1_1_2019.tif')
water2_ds = rasterio.open('D:/Images/Input/Landsat/occurrence_60W_0Nv1_1_2019.tif')

water1_array = water1_ds.read(1)
water2_array = water2_ds.read(1)

# Plot the 3 images
fig, ax = plt.subplots(1, 3, figsize=(20, 6))
ax[0].imshow(rgb*3)

ax[1].i
  • 18
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gis收藏家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值