Reputation: 1592
I have two-d arrays with the same shape:
b8
>>>array([[42,42,42,...,43,37,47],
[41,41,40,...,44,33,34],...],dtype=uint8)
b11
>>>array([[77,77,77,...,41,41,42],
[77,77,77,...,41,41,42],...] dtype=uint8)
I want to use the normalized difference index, to create new array. The normalized index should be caluclated based on this formula:
(b8-b11)/(b8+b11)
and it should produce new array with values between -1 to 1. However, I have realized that I get unexcpected values when I try to calcualte it this way:
(b8-b11)/(b8+b11)
>>>
array([[1.85714286, 1.85714286, 1.85714286, ..., 0.02380952, 3.23076923,
0.05617978],
[1.86440678, 1.86440678, 1.87179487, ..., 0.03529412, 3.35135135,
3.26315789],...
The 1.857 and the other numbers seems to be wrong, when I calculate manually the bottom left pixels I get different result:
(42-77)/(42+77)
>>>-0.29411764705882354
I believe that there is very basic concept that I'm missing here with the matrices, I would like to understand my mistake and to be able to get the desired results.
Upvotes: 1
Views: 56
Reputation: 150805
The problem is uint8
, which is unsigned 8-bit. So your subtraction overflows:
np.uint8(42) - np.uint8(77)
# 221
Upvotes: 4