如何使用Python显示数字高程模型(DEM)(.raw)?

问题描述 投票:2回答:1

我想使用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

image-processing computer-vision rawimage
1个回答
2
投票

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

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

你会得到几乎相同的:

enter image description here

问题出在其他地方。

从弗雷德(@ fmw42)的提示和玩耍,oops我的意思是“仔细和科学地进行实验”,如果我将你的图像视为4096x2048像素,16 bpp和MSB first endianness,我可以获得更可能的结果:

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.