I am interested in reading a pgm file in python as a numerical file/matrix
Right now I open the file with
f = open('/home/matthew/NCM/mdb001.pgm', 'rb')
When I read the first line, it looks as expected
r.readline()
produces
'P5\n'
and the next line is fine
'1024 1024\n'
and the next
'255\n'
but then I get a series of gibberish. It looks like some hex values mixed in with other stuff.
I don't want to view the file as an image picture, I just want to see it in this format.
P5
style pgm file as the documentation you link to describes. The "gibberish" you are seeing are the pixel data encoded as bytes between'\x00'
to maxval which you show as 255 (or'\xff
'`). There should be 1024×1024 bytes of "gibberish" representing the image data. – Chari:;;=><@>??A?@A@??@?A?BEBACADAHHFEEHHFIFFEGKJLLJLMJKKJIJJFJFHHIGIIIHIILIKLNRNNSTUY]lw
– Curagh