Public Lab contributor harshitha just posted a new research note entitled 'Used the PiNoIR camera with blue filter for my experiment in order to obtain the values of NIR and Red region, now i wanted to know what out put we are getting is right or wrong?':
Read and respond to the post here: https://publiclab.org/notes/harshitha/01-16-2020/used-the-pinoir-camera-with-blue-filter-for-my-experiment-in-order-to-obtain-the-values-of-nir-and-red-region-now-i-wanted-to-know-what-out-put-we-are-getting-is-right-or-wrong
Hello... I am an engineering student working on a project based on NDVI calculation to monitor crop health. I used the PiNoIR camera with a blue filter for my experiment in order to obtain the values of the NIR and the Red region. I used the following code to extract the required values and to calculate the NDVI. But in the output image, the empty regions (the area where no leaves are present as shown in the below figure) and ground have higher NDVI values. The shadowed regions are shown in the range from 0.5 to 0.6. I wanted to know whether the output is correct and what corrections can be done in the -code in order to correct the error. The code is given below.
from PIL import Image
import numpy as np
import cv2
from cv2 import imread
from matplotlib import cm
rgb_matrix =cv2.imread('inputimg.jpg')
w=rgb_matrix.shape[1] #columns
h=rgb_matrix.shape[0] #rows
print(w)
print(h)
res=[]
for i in range(h):
row=[]
for j in range(w):
val=rgb_matrix[i][j]
n=val[2]
r=val[1]
num=((int(n)-int(r)))
den=((int(n)+int(r)))
if(den == 0):
r=0.0
else:
r=np.divide(num,den)
row.append(r)
res.append(row)
print('Done')
colors for easier identification
for i in range(h):
for j in range(w):
if(res[i][j] >=-1 and res[i][j] <0):
rgb_matrix[i][j]=[128,128,128]
elif(res[i][j]>=0 and res[i][j]<0.2):
rgb_matrix[i][j]=[64,255,0]
elif(res[i][j]>=0.2 and res[i][j]<0.3):
rgb_matrix[i][j]=[125,255,255]
elif(res[i][j]>=0.3 and res[i][j]<0.4):
rgb_matrix[i][j]=[0,128,128]
elif(res[i][j]>=0.4 and res[i][j]<0.5):
rgb_matrix[i][j]=[255,255,0]
elif(res[i][j]>=0.5 and res[i][j]<0.6):
rgb_matrix[i][j]=[255,51,153]
elif(res[i][j]>=0.6 and res[i][j]<0.7):
rgb_matrix[i][j]=[0,128,255]
elif(res[i][j]>=0.7 and res[i][j]<0.8):
rgb_matrix[i][j]=[255,43,255]
elif(res[i][j]>=0.8 and res[i][j]<0.9):
rgb_matrix[i][j]=[40,40,255]
else:
rgb_matrix[i][j]=[255,0,0]
cv2.imwrite('outputimg.jpg',rgb_matrix)
print("Completed!!")
(Ignore the indentation errors)
You received this email because you are subscribed to some or all of the following tags: ndvi,parrot,sky,crop,drone,red,pinoir,purple,opencv,dark,orange,first-time-poster,columns,rows,compute,based,grey,yellow,pink,imageprocessing,crophealth,picam,vegetativeindex.
Subscribe to all the tags for this post by visiting https://publiclab.org/subscribe/multiple/tag/ndvi,parrot,sky,crop,drone,red,pinoir,purple,opencv,dark,orange,first-time-poster,columns,rows,compute,based,grey,yellow,pink,imageprocessing,crophealth,picam,vegetativeindex.
To change your preferences, please visit https://publiclab.org/subscriptions.
Report spam and abuse to: moder...@publiclab.org
Check out the blog at https://publiclab.org/blog | Love our work? Become a Public Lab Sustaining Member today at https://publiclab.org/donate If this email title has an ID in the format #0000, you can reply with the email you use at PublicLab.org and your response will be posted as a comment on the website.