title: How to apply threshold to image
body: <p>I have an image and would like to use the thresholding to reduce its noise. I try to flatten its grid into 1D array, and then would like to use 0 to replace the pixel’s actual intensity if it is below the threshold, finally reshape it into the original grid. Here is my code:</p>
  <pre><code>Threshold_flat = np.array(Threshold_flat)
  Threshold = Threshold_flat.flatten()
  
  Threshold_1 = []
  for i in range(len(Threshold)):           
          x = [i if i&gt;20 else 0 for i in Threshold]        
          Threshold_1.append(x)
          
  Threshold_1 = np.array(Threshold_1)
  Threshold_1 = Threshold_1.reshape(326,481) 
  </code></pre>
  <p>But it doesn't work when I run the code, and the processing is also very slow.</p>
  <p>I am confused about it and have no idea how to resolve it.</p>
  <p>Thanks in advance for any help!</p>