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

时间:2019-04-26 17:09:47

标签: image-processing computer-vision rawimage

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

1 个答案:

答案 0 :(得分:2)

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

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

您将获得几乎相同的结果:

enter image description here

问题出在其他地方。

根据Fred(@ fmw42)的提示并四处玩耍,哎呀,我的意思是“仔细科学地进行实验” ,如果我将您的图像视为4096x2048像素, 16 bpp和MSB第一字节顺序:

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

enter image description here