0

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.

parupalu
  • 51
  • 2
  • 9
  • why do you want to do this in a different way? what is wrong with the standard definition of green? – Piglet Apr 05 '19 at 08:33
  • I am looking to integrate this for a real-time application and which has to be very accurate. Since this threshold can be adjusted, I want something which is stable that can detect any shade of green. – parupalu Apr 05 '19 at 08:36
  • 1
    and what is inaccurate about thresholding Hue in your opinion? – Piglet Apr 05 '19 at 08:42
  • the range of Hue I gave is from 80, but it could also be from 77 which is more like a transition from yellow to green. It is not inaccurate, but I want something robust and independent of these threshold values – parupalu Apr 05 '19 at 08:53
  • then use 77 if you still consider this green. colour a subjective perception. ask someone else and he will pick another threshold. Hue is calculated from RGB touples using a mathematical formula. You can use other color metrics leaving you with the same problem. Where ends one color and where starts another? they are all accurate up to the point where somone has to decide what is green and what is not. – Piglet Apr 05 '19 at 09:01
  • So do you think other than thesholding there is know other way to answer my question? – parupalu Apr 05 '19 at 09:05
  • given your request to find all green pixels that's the only approach that makes sense. green is a range of tristimuli and all you have to do is to check if a pixel is within that range or not. if you want to do more stuff other method can come in handy. google colour segmentation. but these methods don't find green pixels, they group pixels of similar values. – Piglet Apr 05 '19 at 09:19
  • Alright. Thank you very much for your answers and time. – parupalu Apr 05 '19 at 09:28

0 Answers0