当前位置:   article > 正文

Python干货 | 制作遥感影像图_图像跟卫星地图的融合 python

图像跟卫星地图的融合 python

0.前言

近50年来,Landsat系列卫星为我们提供了非常长时间序列的地球表面观测信息,现阶段Landsat卫星仍然在服役,为全球治理和科学研究提供了非常宝贵的数据。

图片

图源:USGS

现在是大数据时代,作为地球科学领域来说,遥感资料是不折不扣的宝贵的一手实测资料,且数据量非常的庞大。现阶段来说,可能大部分遥感资料生产的速度远远大于我们去利用它的速度,所以大部分遥感资料还是处于沉睡状态,在等待着技术的继续革新,唤醒这沉睡的数据,使其发光发热。

今天我们来探索一下使用Landsat数据来制作一张遥感影像图。先上图!图示为杭州湾 

图片

东南形胜,三吴都会,钱塘自古繁华

1.准备工作

先准备下载好的Landsat8数据集,Landsat8中包括11个波段,在数据文件夹中,每个波段一个tif文件,这个tif文件中包括了坐标信息、波段值等信息,可以通过Pythonrasterio模块来读取(如果有需要的话,可以详细写一下使用这个库来读取tif文件信息)。

导入接下来要用到的Python库。

  1. import numpy as np
  2. import os
  3. import matplotlib.pyplot as plt
  4. import tifffile as tiff
  5. from skimage import exposure

使用遥感影像制作底图时,通常是选取三个波段的数据分别作为图像RGB的三个通道,其中RGB表示红绿蓝三个通道,不同波段组合将得到不同的效果。

我们使用比较多的Google earth 中就用到了Landsat数据,他的波段组合是432。即使用Landsat的B4、B3和B2三个波段作为影像的三个通道。

上图的杭州湾图使用的是753。 

如果波段组合是432情况下的效果如下图所示,432波段合成的真彩色图片,比较接近地物真实色彩,图像平淡,色调偏暗。

图片

2.动起手来

首先把Landsat各个波段的数据读取出来。用到了一丢丢Python小技能,参见:

8个你应该掌握的Python列表技能

7个你应该掌握的Python字典操作

  1. l8path = r'pathOfLandsat8\LC08_L1TP_118039_20160126_20170330_01_T1'
  2. fileName = l8path.split("\")[-1]
  3. prefix = os.path.join(l8path,fileName)
  4. bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'B11']
  5. n_bands = len(bands)
  6. temp = tiff.imread(prefix + "_B1.TIF")
  7. arr = np.zeros((n_bands, np.shape(temp)[0], np.shape(temp)[1]), dtype=np.float)
  8. for i in range(n_bands):
  9. file2read = prefix + "_" + bands[i] + ".TIF"
  10. arr[i, :, :] = tiff.imread(file2read)
选取三个波段
rgb=(642) #Python下界为0,其实是753
  1. rgb_bands = arr[rgb, :, :]
  2. rgb_bands = _stretch_im(rgb_bands, 2)
  3. rgb_bands = bytescale(rgb_bands).transpose([120])
  4. plt.close('all')
  5. fig, ax = plt.subplots(figsize=figSize)
  6. ax.imshow(rgb_bands, extent=extent)
  7. ax.set_title(title)
  8. ax.set(xticks=[], yticks=[])
其中用到了两个函数,其中一个是提高图像的对比度,另外一个将波段数据归一化到像素点常用的[0,255]区间内。
  1. def _stretch_im(arr, str_clip):
  2. s_min = str_clip
  3. s_max = 100 - str_clip
  4.   arr_rescaled = np.zeros_like(arr)
  5. pLow, pHigh = np.percentile(arr[arr > 0], (s_min, s_max))
  6. arr_rescaled = exposure.rescale_intensity(arr, in_range=(pLow, pHigh))
  7. return arr_rescaled.copy()
  1. def bytescale(data, high=255, low=0, cmin=None, cmax=None):
  2. if data.dtype == "uint8":
  3. return data
  4. if high > 255:
  5. raise ValueError("high should be less than or equal to 255.")
  6. if low < 0:
  7. raise ValueError("low should be greater than or equal to 0.")
  8. if high < low:
  9. raise ValueError("high should be greater than or equal to low.")
  10. if cmin is None or (cmin < data.min()):
  11. cmin = float(data.min())
  12. if (cmax is None) or (cmax > data.max()):
  13. cmax = float(data.max())
  14. # Calculate range of values
  15. crange = cmax - cmin
  16. if crange < 0:
  17. raise ValueError("cmax should be larger than cmin.")
  18. elif crange == 0:
  19. raise ValueError(
  20. "cmax and cmin should not be the same value. Please specify "
  21. "cmax > cmin"
  22. )
  23. scale = float(high - low) / crange
  24. # If cmax is less than the data max, then this scale parameter will create
  25. # data > 1.0. clip the data to cmax first.
  26. data[data > cmax] = cmax
  27. bytedata = (data - cmin) * scale + low
  28. return (bytedata.clip(low, high) + 0.5).astype("uint8")

3.小结

大功告成!

这个遥感影像图,可以作为我们出图的底图,还可以实现两张遥感影像图的融合,在影像图上叠加自己想要叠加的数据,欲知详情,且听下回分解....

因遥感数据较大,关注公众号 海洋纪 ,后台回复 Landsat   获取数据及源码。

Tips:不同波段组合情况可以实现不同的效果,大家可以自己试试看。如543,652,765等。

最后,感谢阅读。

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/329859
推荐阅读
相关标签
  

闽ICP备14008679号