On Thu, Dec 31, 2020 at 10:47:02PM +0530, Mayuresh wrote: > This scenario of converting raw data to an image must be very common in > sane. Wonder if I could get some suggestions. If a python package (other > than PIL for above issue) can do it, it will be better as the driver > itself is in python. But even other alternatives will do
In the meantime I used libpng. It supports 16 bit depth. But the results aren't yet correct - it's not looking like a normal X ray. May be I am missing something about the image format. I am keeping a sample image if anyone could try and reconstruct here: http://mayuresh.sdfeu.org/img.dat.gz Note the parameters: width = 1168 height = 1562 depth = 16 It's little endian or big endian is unclear, both ways it is producing results. interlace is true or false is not clear, pypng did not show any difference when interlace in its png encoder was true vs false. It may require color inversion, which could be done either after reconstructing image or during. Here is some code using pypng: # Please set flnm suitably import struct with open(flnm,'rb') as fp: buf = [ 65535 - v[0] for v in struct.iter_unpack('>H',fp.read()) ] width = 1168 height = 1562 depth = 16 arr = [ buf[i:i+width] for r in range(height) for i in [r*width] ] import png with open('see.png','wb') as fp: png.Writer( width = width, height = height, greyscale = True, bitdepth = depth, ).write(fp,arr)
