title: How to change particular type of pixel value in a grayscale image in python?
body: <p>I want to get a grayscale image in which <code>if pixel_value &gt; 250</code>, then  <code>new pixel_value = 250</code>.<br>
  I have tried it on the image </p>
  
  <p><a href="https://i.stack.imgur.com/Eeqg6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Eeqg6.jpg" alt="enter image description here"></a></p>
  
  <p>like below:</p>
  
  <pre><code>from PIL import Image
  cols = []
  img = Image.open("tiger.jpg") 
  img1=img.convert("LA")
  img1.save("newImage.png")
  img2 = Image.open("newImage.png")
  columnsize,rowsize= img2.size
  imgconv = Image.new( img2.mode, img2.size) #create new image same size with original image
  pixelsNew = imgconv.load() 
  
  
  for i in range(rowsize):
      for j in range(columnsize):
          x=pixelsNew[j,i][0]
          if x&gt;250:
              pixelsNew[j,i][0]=250
  imgconv.save("newImage2.png")
  </code></pre>
  
  <p>But it does not working. Any solution will be appreciated.</p>