I do have a binary file (raw image), and I read it with a specific pattern as following code, I now want to process the np array (new_array), so after processing the new_array, how do I convert it back to the array and save it to the new binary file (raw image)?
f = np.fromfile(path, dtype=np.uint16)
new_array = np.zeros(cols * rows, dtype=int)
for i in range(0, cols * rows):
tmp = '{0:08b}'.format(f[i])
part1 = tmp[4:8]
part2 = tmp[0:4]
new_array[i] = (int(part1,2)<<2) + (int(part2,2)>>6)
res_array = new_array.reshape((rows, cols))
The pattern is given above.
I am just wondering how to convert res_array to the type of the original one (the variable f) and save it to a new binary file.