I am in the process of computing an NDVI index for an image. The NDVI should give values between 0 and 1, however I get much larger values. My data is in a [5000,5000,3] array, and the important bands for the NDVI calculation are the second and the fourth. All entries in my arrays are positive. My code is:
nu=imarray[:,:,3]-imarray[:,:,1]
de=imarray[:,:,3]+imarray[:,:,1]
NDVI=div0(nu,de)
Where imarray is my array, nu is the numerator and de is the denominator. I use denis's excellent div0 function from this question, which divides the numerator by the denominator but sets the potential 0/0 to equal 0. Inserting the following print statements for debugging however:
print np.amax(NDVI)
print np.amin(NDVI)
Gives
38.1372781065
0.0
I.e. instead of being between -1 and 1, the index is between 0 and 38.1. Mathematically this appears to make little sense, so does anyone know what I am programming incorrectly here?
Thanks in advance :)