【问题标题】:Reading TIFF in Python and Matplotlib using GDAL使用 GDAL 在 Python 和 Matplotlib 中读取 TIFF
【发布时间】:2012-04-29 22:31:14
【问题描述】:

我正在尝试使用 Python 和 MatPlotLib 显示灰度 TIFF 文件,

到目前为止,我已经阅读了以下文件:

import scipy as N
import gdal
import sys
import matplotlib.pyplot as pyplot

try:
    tif = gdal.Open('filename.tif')
    tifArray = tif.ReadAsArray()
except:
    print 'The file does not exist.'
    sys.exit(0)

band1 = tif.GetRasterBand(1)
band2 = tif.GetRasterBand(2)
band3 = tif.GetRasterBand(3)

band1Array = band1.ReadAsArray()
band2Array = band2.ReadAsArray()
band3Array = band3.ReadAsArray()

但是我不知道我还能做什么......我一无所知。 有人会在这方面帮助我吗?

【问题讨论】:

  • GDAL 怎么没有导入错误?

标签: python matplotlib gdal


【解决方案1】:

将文件处理成 2 数组后,您可以使用 matplotlib 中的任何函数来绘制 2D 数组,例如cmap、imshow 等

这是marbles example的输出

img=mpimg.imread('MARBLES.TIF ')
imgplot = plt.imshow(img)

如果您只查看图像的 band3,您会得到以下结果:

imgplot2 = plt.imshow(band3Array)
plt.show()

进一步了解 MPL 和 2D 数组函数中的图像查看...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-10
    • 2014-09-17
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 2020-10-07
    相关资源
    最近更新 更多