title: Why doesn't decrementation work here the way it should?
body: <p>I am pretty sure I've made a silly mistake, but I cannot seem to find it for quite some time.</p>
  
  <p>I (successfully) load some images, convert them to grayscale and thresh to b&amp;w. Then I wanted to make a method that evaluates each row of pixels by measuring its avg color value (0…255) and give me the row number of the first one that is below a certain threshold. It works, but expanding the method to do the same thing from the bottom does not. Here's how it looks:</p>
  
  <pre><code>t_thresh_hor = 210.0
  
  def core_text_loc(image):
      height, width = image.shape
      height = height - 1   # to adjust for starting with 0
      width = width - 1     # to adjust for starting with 0
      top_trim = 0
      bot_trim = height
  
      i = 0
      while i &lt; height and top_trim == 0:
          row = image[i, 0:-1]
          i = i + 1
          if numpy.mean(row) &lt; t_thresh_hor:
              top_trim = i
      # here it stops working
      i = height
      while i &gt; 0 and bot_trim == height:
          row = image[height, 0:-1]
          if numpy.mean(row) &lt; t_thresh_hor:
              bot_trim = i
          i = i - 1
  
      return(top_trim, bot_trim)
  </code></pre>
  
  <p>I know the threshold is correct (works when I manually access a specific line), but bot_trim always returns the height of the picture, meaning it stopped at the first iteration (?).
  What have I done wrong?</p>
  
  <p>EDIT:
  <strong>Sample case:</strong> I am testing it on two pictures:
  first one is 4724x3177, and the output is:
      top_trim: 1216 (correct)
      bot_trim: 4723 (should be ≈ 4400)
  second one4705 3177
      top_trim: 315 (correct)
      bot_trim: 4704 (should be ≈ 4400)</p>