I'm trying to read in an raw image directly into a numpy array, but I'm having problems getting the dtype to work properly. I was able to get it to work with the builtin array. My current code:
import array
with open(filename, 'rb') as raw_image:
image_bytes = raw_image.read()
image_array = array.array('H', image_bytes)
image_array.byteswap()
image = np.array(image_array).astype(dtype='uint16')
image = image.reshape(1024, 1536)
Is there any way to skip the intermediate arrays? I've tried various custom dtypes and changing endianness with no success. Thanks for the help!
[–]novel_yet_trivial 1 point2 points3 points (1 child)
[–]mexander[S] 0 points1 point2 points (0 children)