I am trying to read the RGB values at certain locations on my map which is a .tif-file I brought into QGIS.

Goal: match species presence points on my map to certain RGB values on the .tif-file.

from PIL import Image
img = PIL.Image.open(iface.layerTreeView().selectedLayers())
col = img.convert("RGB")
val = col.getpixel((0,0)) #tried to read value at center
print (val)

And getting the error:

AttributeError: 'list' object has no attribute 'read'
  • 1
    You have a raster layer and should use those methods to access the pixesl
    – Ian Turton
    Aug 13, 2020 at 19:23

1 Answer 1


Right now, I think you are trying to pass a raster as an input to the .open function, which is not an acceptable parameter.

According to the documentation for the Image module, parameters are:

  1. fp – A filename (string), pathlib.Path object or a file object. The file object must implement read(), seek(), and tell() methods, and be opened in binary mode.
  2. mode – The mode. If given, this argument must be "r".

Try putting the .tif filename directly into the line, like this:

img = PIL.Image.open("image.tif") 

Or providing the full path name as a parameter, like this:

img = PIL.Image.open(r"C:\temp\image.tif") 

Perhaps you might also consider using GDAL to accomplish your tasks. There is an answer here that might help get you started with that.

  • I fixed the problem using GDAL. Thanks!
    – avinator
    Aug 13, 2020 at 20:19
  • If the answer was useful, please mark it as the answer. Thanks!
    – MarcM
    Aug 14, 2020 at 6:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.