I have an text file called with the extension '.image', at the top of the file is the following:
Image Type: unsigned char
Dimension: 2
Image Size: 512 512
Image Spacing: 1 1
Image Increment: 1 1
Image Axis Labels: "" ""
Image Intensity Label: ""
193
I believe this to be an unsigned char file, but i'm having a hard time opening it in python (and saving it as a jpg, png etc)
Have tried the standard PIL.Image.open(), saving as a string and reading with Image.fromstring('RGB', (512,512), string), and reading as byte-like object Image.open(io.BytesIO(filepath))
Any ideas? Thanks in advance
If we assume there is some arbitrary, unknown length header on the file, we can read the entire file and then rather than parsing the header, just take the final 512x512 bytes from the tail of the file:
Or, if you prefer Numpy to Pathlib:
Or, if you don't really fancy writing any Python, just use
tailin Terminal to slice the last 512x512 bytes off your file and tell ImageMagick to make an 8-bit PNG from the grayscale byte values: