title: Change contrast of image in PIL
body: <p>I have a program that's supposed to change the contrast, but I feel like it's not really changing the contrast.It changes some areas to red whereas I don't want it to. If you could tell me how to remove them, thank you.
  Here is the code:</p>
  
  <pre><code>from PIL import Image
  
  
  def change_contrast(img, level):
  
      img = Image.open("C:\\Users\\omar\\Desktop\\Site\\Images\\obama.png")
      img.load()
  
      factor = (259 * (level+255)) / (255 * (259-level))
      for x in range(img.size[0]):
          for y in range(img.size[1]):
              color = img.getpixel((x, y))
              new_color = tuple(int(factor * (c-128) + 128) for c in color)
              img.putpixel((x, y), new_color)
  
      return img
  
  result = change_contrast('C:\\Users\\omar\\Desktop\\Site\\Images\\test_image1.jpg', 100)
  result.save('C:\\Users\\omar\\Desktop\\Site\\Images\\test_image1_output.jpg')
  print('done')
  </code></pre>
  
  <p>And here is the image and its result:</p>
  
  <p><a href="https://i.stack.imgur.com/j5UID.png" rel="noreferrer"><img src="https://i.stack.imgur.com/j5UID.png" alt="obama.png"></a>
  <a href="https://i.stack.imgur.com/hONkZ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/hONkZ.jpg" alt="obama modified"></a></p>
  
  <p>If this is the actual contrast method, feel free to tell me</p>