I've tried multiple different variations, but for some reason I keep getting invalid binary digits (human readable) being output to the file:
img_array = np.asarray(imageio.imread('test.png', as_gray=True), dtype='int8')
img_array.astype('int8').tofile("test.dat")
But this doesn't produce a valid binary file. Once the file is read into a Verilog tb, it complains about invalid binary digits and when I open up the file I see a bunch of numbers and other characters. It just doesn't seem like its translating correctly.
UPDATE: After running
print(img_array)
print(img_array.tobytes())
I can see that the int value '43' is being translated to '+' whereas I would expect '2B'. It seems to only be printing certain values to ASCII. Here's a simple example:
x = np.array([[0, 9], [2, 3]], dtype='uint8')
print(x.astype('uint8'))
print(x.tobytes())
The output is:
[[0 9]
[2 3]]
b'\x00\t\x02\x03'
How Can I fix this?
Any help would be greatly appreciated.
Other Solutions that I've tried: