title: Python giving AttributeError: 'PngImageFile' object has no attribute 'read' with Pillow
body: <p>So I'm working on a small research project and a part of this involves me having to get the pixel coordinates of a image that correspond to a certain color. A sample image (named testpic.png) is shown here:</p>
  
  <p><a href="https://i.stack.imgur.com/53qCs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/53qCs.png" alt="enter image description here"></a></p>
  
  <p>What I am trying to do is determine the locations of all the dots which are the color turquoise. However, the following code (adapted from <a href="https://stackoverflow.com/questions/44923141/find-pixels-with-given-rgb-colors">Find pixels with given RGB colors</a>) gives me the error: "AttributeError: 'PngImageFile' object has no attribute 'read'" and I'm not sure what's going on.</p>
  
  <pre><code>from PIL import Image
  myImage = Image.open("testpic.png")
  
  def find_turq_pixels(image_name):
  
      # Set the value you want for these variables
      r_min = 0
      r_max = 65
      g_min = 220
      g_max = 255
      b_min = 220
      b_max = 255
  
      turq_pixels = set()
  
      img = Image.open(image_name)
      rgb = img.convert('rgb')
      for x in range(img.size[0]):
          for y in range(img.size[1]):
              r, g, b = rgb.getpixel((x, y))
              if r &gt;= r_min and r &lt;= r_max and b &gt;= b_min and b &lt;= b_max and g &gt;= g_min and g &lt;= g_max:
                  turq_pixels.add((x,y))
  
      return turq_pixels
  
  print(find_turq_pixels(myImage))
  </code></pre>
  
  <p>I'm currently using Python 3.7, and if I installed everything correctly, python says "PIL.PILLOW_VERSION" is running 5.4.1. The python file and the image file are in the same folder as well in case that was causing an error. This is my first time using Python in years so apologies in advance if I'm being very stupid about this as I've already forgotten a ton about programming, but if anyone could help me fix this, it would be much greatly appreciated! Thanks :)</p>