title: Python 3: I am trying to find find all green pixels in an image by traversing all pixels using an np.array, but can't get around index error
body: <p>My code currently consists of loading the image, which is successful and I don't believe has any connection to the problem.</p>
  
  <p>Then I go on to transform the color image into a np.array named rgb</p>
  
  <pre><code>    # convert image into array
      rgb = np.array(img)
      red = rgb[:,:,0]
      green = rgb[:,:,1]
      blue = rgb[:,:,2]
  </code></pre>
  
  <p>To double check my understanding of this array, in case that may be the root of the issue, it is an array such that rgb[x-coordinate, y-coordinate, color band] which holds the value between 0-255 of either red, green or blue.</p>
  
  <p>Then, my idea was to make a nested for loop to traverse all pixels of my image (620px,400px) and sort them based on the ratio of green to blue and red in an attempt to single out the greener pixels and set all others to black or 0.</p>
  
  <pre><code>for i in range(xsize):
  for j in range(ysize):
      color = rgb[i,j]  &lt;-- Index error occurs here
      if(color[0] &gt; 128):
          if(color[1] &lt; 128):
              if(color[2] &gt; 128):
                  rgb[i,j] = [0,0,0]
  </code></pre>
  
  <p>The error I am receiving when trying to run this is as follows: </p>
  
  <p>IndexError: index 400 is out of bounds for axis 0 with size 400</p>
  
  <p>I thought it may have something to do with the bounds I was giving i and j so I tried only sorting through a small inner portion of the image but still got the same error. At this point I am lost as to what is even the root of the error let alone even the solution.</p>