title: How to find the center point of numpy arrays?
body: <p>I am detecting green color using PIL and numpy. Since the code finds lots of green pixels even in non-green area. Thus, I am finding the nearest value of them to a value that I specified, I get a 3 matching points that provides a (1512L, 3L) matrix. Code is below. As a result, I want to plot this matrix on the original image to see the location. How can I do that ? Sample image is also below.</p>
  
  <pre><code>import numpy as np
  from PIL import Image
  
  # Open image and make RGB and HSV versions
  RGBim = Image.open("AdjustedNewMaze3.jpg").convert('RGB')
  HSVim = RGBim.convert('HSV')
  
  # Make numpy versions
  RGBna = np.array(RGBim)
  HSVna = np.array(HSVim)
  
  # Extract Hue
  H = HSVna[:,:,0]
  
  # Find all green pixels, i.e. where 100 &lt; Hue &lt; 140
  lo,hi = 100,140
  # Rescale to 0-255, rather than 0-360 because we are using uint8
  lo = int((lo * 255) / 360)
  hi = int((hi * 255) / 360)
  green = np.where((H&gt;lo) &amp; (H&lt;hi))
  
  # Make all green pixels black in original image
  RGBna[green] = [0,0,0]
  
  def find_nearest(array, value):
      array = np.asarray(array)
      idx = (np.abs(array - value)).argmin()
      return array[idx]
  
  value = 120
  
  green = find_nearest(RGBna, value)
  average = np.average(green)
  print(green)
  
  count = green[0].size
  print("Pixels matched: {}".format(count))
  Image.fromarray(green).save('resultgreen.png')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pwED0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pwED0.jpg" alt="Sample Image"></a></p>