On Thu, Dec 31, 2020 at 01:10:25PM -0500, Aaron M. Ucko wrote: > From what I gather, python3-pythonmagick should support 16-bit channel > depths. I'm not at all familiar with its usage details, though, so I > can't give you any more specific tips.
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)

