+ 2

Read an heightmap 16 bit grayscale raw file

I need help with reading a raw heightmap file... I have a .raw heightmap 16 bit grayscale that I want to open on python but I still wasn't able to find an answer, tried several examples from the internet, several libraries, and nothing, with photoshop if I insert the file as a 131x131 16 bit pc IBM, it imports as I want and also there's a website with source code available called rawpixels.net,i was also able to use that website to open the file and generate the image how I want, but since it will be more 150 files, using the website or photoshop will take a long time, so I was looking to automate the process, but I still wasn't able to do, if anyone could help me would be great Settings used in rawpixels: https://i.gyazo.com/50975c66801b4e799d3d6db12ddf2c05.png

2nd Aug 2022, 7:08 AM
LethalArms
LethalArms - avatar
3 odpowiedzi
0
rawData = open("foo.raw" 'rb').read() imgSize = (x,y) # Use the PIL raw decoder to read the data. # the 'F;16' informs the raw decoder that we are reading # a little endian, unsigned integer 16 bit data. img = Image.fromstring('L', imgSize, rawData, 'raw', 'F;16') img.save("foo.png")
7th Aug 2022, 5:29 AM
Harsh Nama
Harsh Nama - avatar
0
import rawpy import imageio path = 'image.raw' with rawpy.imread(path) as raw: rgb = raw.postprocess() imageio.imsave('default.tiff', rgb)
7th Aug 2022, 5:30 AM
Harsh Nama
Harsh Nama - avatar
0
import cv2 import numpy as np from PIL import Image import torchvision with open('height.raw', 'rb') as infile: buf = infile.read() x = np.fromstring(buf, dtype='uint8') img = cv2.imdecode(x, cv2.IMREAD_UNCHANGED) image = torchvision.transforms.ToPILImage(img) image = Image.open(image) image.show()
7th Aug 2022, 5:30 AM
Harsh Nama
Harsh Nama - avatar