I know how to read binary files in Python using NumPy's
If you want to make an image out of a binary file, you need to read it in as integer, not float. Currently, the most common format for images is unsigned 8-bit integers.
As an example, let's make an image out of the first 10,000 bytes of /bin/bash:
>>> import numpy as np >>> import cv2 >>> xbash = np.fromfile('/bin/bash', dtype='uint8') >>> xbash.shape (1086744,) >>> cv2.imwrite('bash1.png', xbash[:10000].reshape(100,100))
In the above, we used the OpenCV library to write the integers to a PNG file. Any of several other imaging libraries could have been used.
This what the first 10,000 bytes of
bash "looks" like: