title: How do I create a threshold of an image?
body: <p>It is my understanding that thresholding is a step function meaning that pixel values are rounded off at each step. E.g. pixel value 33 would be rounded to 32(assuming there's a threshold of 32). In my code i am trying to accomplish thresholding but I don't think i am acheieving it. Can someone guide me as to what i am missing? </p>
  
  <pre><code>import pylab as plt
  import matplotlib.image as mpimg
  import numpy as np
  
   img = np.uint8(mpimg.imread("abby.jpg"))
  
  img = np.uint8((0.2126* img[:,:,0]) + \
  np.uint8(0.7152 * img[:,:,1]) +\
  np.uint8(0.0722 * img[:,:,2]))
  
  threshold = 128
  
  for row in img:  ## trying to loop through to find if each image pixel &gt; threshold
     for col in row:
        if col &gt; threshold:
          col = threshold
        else:
          col = 0
  
  plt.imshow(img,cmap=plt.cm.gray)
  plt.show()
  </code></pre>