title: Detecting an object and get the mean pixel value (BGR)
body: <p>I have a picture of a leaf with a white paper as the background and I need to remove the noise (yellow dot) and get the pixel value (bgr) of the leaf.</p>
  
  <p>I used green threshold to detect the leaf and masked it with the original image. I used cv2.mean to get the pixel value, but it counts all the pixel include the black area/background. </p>
  
  <p>How to get the pixel value only for the leaf?
  Here is the code I used:</p>
  
  <pre><code>import cv2
  import numpy as np
  
  img=cv2.imread('crop21.jpg')
  blur=cv2.GaussianBlur(img,(5,5),0)
  hsv=cv2.cvtColor(blur,cv2.COLOR_BGR2HSV)
  #threshold green
  low_g=np.array([35,100,60],np.uint8)
  up_g=np.array([85,255,190],np.uint8)
  mask=cv2.inRange(hsv,low_g,up_g)
  mask_upstate=cv2.bitwise_and(blur, blur, mask=mask)
  #get the bgr value
  mean=cv2.mean(mask_upstate)
  print (mean)
  
  cv2.imshow('image',mask_upstate)
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>