Ask Your Question
0

python opencv: applying function on pixel

asked 2019-02-18 06:45:27 -0600

updated 2019-02-18 06:57:10 -0600

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 (dead crops) and white (healthy crops) in color. Is it possible to change it to green ( for healthy crops) and red (dead or dry crops)

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-02-18 07:55:12 -0600

supra56 gravatar image

Try this:

image = cv2.divide(image, new_image, scale=255)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-02-18 06:44:13 -0600

Seen: 916 times

Last updated: Feb 18 '19