I have a numpy array, example:
signal =array([[ 0, 0, 0, 3485, 3480, 3474],
[ 0, 0, 0, 5644, 5642, 5655],
[ 0, 0, 0, 6622, 6541, 6623],
[ 4555, 4656, 11232, 11265, 11564, 11553],
[ 3450, 3455, 3536, 3510, 3564, 3375]])
I used the scaling ((signal) / np.max(signal)*255).astype(np.uint8)
It’s became
f = array([[ 0, 0, 0, 76, 76, 76],
[ 0, 0, 0, 124, 124, 124],
[ 0, 0, 0, 146, 144, 146],
[100, 102, 247, 248, 255, 254],
[ 76, 76, 77, 77, 78, 74]], dtype=uint8)
so, now I want to generate the signal array from the f array.
I tried the reverse scale like,
(f * np.max(signal)/255).astype(np.uint32)
but It’s giving me
array([[ 0, 0, 0, 105, 105, 105],
[ 0, 0, 0, 226, 226, 226],
[ 0, 0, 0, 195, 105, 195],
[165, 256, 150, 195, 255, 210],
[105, 105, 150, 150, 196, 14]])
which is not appropriate.
so what should I do to reverse the scaling of the array to get the previous original input data?
>Solution :
You are multiplying an array with dtype uint8 with maximum value of signal. This data type can’t hold an integer that large so overflow happens and the numbers are wrapped to the range of 0->255. you have to convert it to uint32 first and then scale:
signal = f.astype(np.uint32) * np.max(signal)/255
After this, the output will still be a little different than original and that is because of converting floating point results to uint8 which will cause your numbers to lose their fraction.