Hello all,
I'm working on a project to apply vegetation indices formula on retrieved Drone aerial images using a simple RGB Camera. The plan is to provide the ability to see the greenness (health) of the crops using opencv. The formulas to be used are the Visible Atmospheric Resistant Index: G - R / (G+R-B) and Green-Red Vegetation Index (GRVI): G-R/(G+R).
Here is a function I have written for the VARI algorithm:
def vari_image(image): h = int(image.shape[0]) w = int(image.shape[1]) new_image = np.zeros((h,w), dtype = "float") image = cv2.divide(image, 255) r,g,b = cv2.split(image) bottom_math = cv2.subtract(cv2.add(g, r), b) new_image = (cv2.subtract(g, r) / bottom_math) return new_image
Issues: 1) I keep receiving warning for dividing by zero, and thus how can I implement an if statement to check the values while using the cv2.divide operation ?
2) The output image does satisfy what I need, disregarding the issue from above, but the image is purple and white in color. Is it possible to change it a green (health crops) and red (dead or dry area)
sorry if this seems like a lengthy question, since I'm fairly new with opencv. Any insight on how to overcome this issue will be highly appreciated. Thanks