【问题标题】:How can display a Digital Elevation Model (DEM) (.raw) using Python?如何使用 Python 显示数字高程模型 (DEM) (.raw)?
【发布时间】:2019-04-26 17:09:46
【问题描述】:

我想使用 Python 显示一个 DEM 文件 (.raw),但结果可能有问题。

下面是我的代码:

img1 = open('DEM.raw', 'rb')
rows = 4096
cols = 4096

f1 = np.fromfile(img1, dtype = np.uint8, count = rows * cols)
image1 = f1.reshape((rows, cols)) #notice row, column format
img1.close()

image1 = cv2.resize(image1, (image1.shape[1]//4, image1.shape[0]//4))
cv2.imshow('', image1)
cv2.waitKey(0)
cv2.destroyAllWindows()

我得到了这个结果: display result

原始DEM文件放在这里:DEM.raw

【问题讨论】:

  • DEM 通常不是 16 位整数吗?
  • 来自en.wikipedia.org/wiki/USGS_DEM,上面写着The elevations are contiguous; breaks or other discontinuities are expressed using "void" elevations of value -32767. Each elevation is described as a six-character readable integer occupying a fixed location in a block. 所以我认为你不应该将它指定为uint8
  • @fmw42 我同意你的两个想法,Fred,但文件大小确实对应于 4096x4096 的 8 位数据,而不是你明智建议的 16 位或 ASCII 格式。嗯……我认为 OP 需要检查他的消息来源。
  • 我发现了一些东西,谢谢@Mark Setchell

标签: image-processing computer-vision rawimage


【解决方案1】:

您的代码没有问题,这就是您文件中的内容。您可以在命令行中使用 ImageMagick 将其转换为 JPEG 或 PNG,如下所示:

magick -size 4096x4096 -depth 8 GRAY:DEM.raw result.jpg

你会得到几乎相同的结果:

问题出在其他地方。

从 Fred (@fmw42) 那里得到提示并玩弄,哎呀,我的意思是 “仔细而科学地实验”,如果我将您的图像视为 4096x2048 像素16 bpp 和 MSB 第一端:

magick -size 4096x2048 -depth 16 -endian MSB gray:DEM.raw  -normalize result.jpg 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-16
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2017-11-22
    • 1970-01-01
    相关资源
    最近更新 更多