title: Index Error: index 512 is out of bounds for axis 0 with size 512
body: <p>So, I'm trying to replicate the "Floyd–Steinberg dithering" on an image, in python, and so far this what I have donne:</p>
  
  <pre><code>import cv2
  
  # returns an array with rgb values of all pixels
  x_img = cv2.imread("lenac.tif")
  
  # returns an image with the rgb values turned to black and white
  x_img_g = cv2.cvtColor(x_img,cv2.COLOR_BGR2GRAY)
  
  
  
  def dither(img):
  
      col = len(img[0])
      li = len(img)
  
      print(col)
      print(li)
  
      for i in range (li):
          for j in range(col):
  
              oldpixel = img[li][col]
              newpixel = quantificacao(oldpixel)
  
              print(newpixel)
  
  print(dither(x_img_g))
  </code></pre>
  
  <p>So basically the method is not finished and the only thing it is doing, is going trough every and each pixel of a black and white version on the "lena.tif" image (very famous in image manipulation), and aplying to them a method called "quantificacao", irrelevant to the question.</p>
  
  <p>The image is, 512 x 512</p>
  
  <p>Everything goes fine, until at a given point the following error pops up:</p>
  
  <pre><code>oldpixel = img[li][col]
  
  IndexError: index 512 is out of bounds for axis 0 with size 512
  </code></pre>
  
  <p>Both the variables <code>col</code> and <code>li</code>, are shown to be 512, so, the <code>for cycle</code> should go from 0 to 511 right?</p>
  
  <p>Therefore only indexing till 511</p>
  
  <p>I'm kinda lost in these one, and would be extremely garteful if someone could help me</p>