I'm using opencv and numpy to process some satellite images.
I need to differentiate what is "land" from what is "green" (crops and vegetation).
My question is: How can I decide which values are close to green in the RGB format?
What I'm doing so far is:
img = cv2.imread('image1.jpg',1)
mat = np.asarray(img)
for elemento in mat:
for pixel in elemento:
if pixel[1] > 200: # If the level of green is higher than 200, I change it to black
pixel[0] = 0
pixel[1] = 0
pixel[2] = 0
else: # If the level of G is lower than 200 I change it to white.
pixel[0] = 255
pixel[1] = 255
pixel[2] = 255
This code works, but isn't really useful. I need a more precise manner to decide which RGB values correspond to green and which ones does not.
How can I achieve this?