title: I want to apply a threshold to pixels in image using python. Where did I make a mistake?
body: <p>I want to generate the output that is a threshold. And my error:</p>
  
  <blockquote>
    <p>img_thres = n_pix[y, x]<br>
    TypeError: 'int' object is not subscriptable</p>
  </blockquote>
  
  <pre><code>import cv2
  import numpy as np
  import matplotlib as plt
  
  img = cv2.imread("cicek.png",0)
  img_rgb = cv2.imread("cicek.png")
  
  h = img.shape[0]
  w = img.shape[1]
  
  img_thres= []
  n_pix = 0
  # loop over the image, pixel by pixel
  for y in range(0, h):
      for x in range(0, w):
          # threshold the pixel
          pixel = img[y, x]
          if pixel &lt; 0.5:
              n_pix = 0
          img_thres = n_pix[y, x]
  
  cv2.imshow("cicek", img_thres)
  </code></pre>