python - matplotlib.imshow() 复制图像
问题描述
我正在使用 Python3、earthpy、rasterio、numpy 和 matplotlib 处理 Sentinel-2 卫星图像和分析。你可以参考这里的完整代码。我正在尝试分别使用红色、绿色和蓝色波段来创建 RGB 复合图像。
如果您参考代码,您可以看到以下代码行生成了黑白图像,而不是彩色图像-
rgb = ep.plot_rgb( arr = stacked_s2_sentinel_img, rgb = (1, 2, 3), figsize =(20, 10) #, title = titles )
plt.show()
为了缓解这个问题,我采用了使用 numpy 的 'nanpercentile()' 函数来计算对比度拉伸边界的方法,然后使用这些边界和 numpy 的 'interp()' 函数在 0 和 1 之间使用这些函数动态拉伸图像界限。支持代码为:
blue_stretch.shape, green_stretch.shape, red_stretch.shape
# ((1830, 1830), (1830, 1830), (1830, 1830))
rgb_img = np.stack([red_stretch, green_stretch, blue_stretch])
rgb_img.shape
# (3, 1830, 1830)
rgb_img = rgb_img.reshape(1830, 1830, 3)
rgb_img.shape
# (1830, 1830, 3)
plt.figure(figsize = (10, 8))
plt.imshow(rgb_img, interpolation='nearest')
plt.show()
但这显示了相同的图像在 3 x 3 网格中重复了 9 次。怎么了?此外,图像看起来完全错误。
怎么了?
解决方案
推荐阅读
- python - 暂停主进程直到生成的进程开始执行?
- javascript - 使用 Web3 为 Solidity 合约提供资金问题
- c++ - 无法以编程方式在 QTablewidget 中选择一行
- java - 没有找到查询类的持久类:
- spring-boot - 如何使用 Spring Boot 获取节点链(Neo4j)
- opengl - 为什么没有实现 OpenGL 灰度纹理性能增益?
- javascript - 从 div 获取链接并在新链接中发布
- android - 从 FusedLocationProvider(Google Play 服务)获取位置不会给出低于 10 米的准确度
- linux - 添加文件夹中所有视频文件的持续时间
- intellij-idea - 如何检测 SonarQube 中未使用的集合?