I am trying to identify only green color in an image. That means, other than Green color (sample image attached) in the image the rest should be blacked out.
Here is the original image:
original image of a Rose with green leaves
Here is the expected output: Highlighted green in the image
I extracted the green color using HSV threshold values using the following code:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread("rose.jpg")
mask = cv2.inRange(hsv, (40, 0, 0), (80, 255,255))
imask = mask>0
green = np.zeros_like(img, np.uint8)
green[imask] = img[imask]
plt.imshow(green)
plt.show()
But I would like to know, how to do this exactly the same without using these threshold values. Is there any other way than threshold?
It is helpful if someone can help me through this.
Looking forward for your inputs. Thank you all very much.