1

I'm trying to get the code to give me an output of the rgb value of a certain pixel

Input:

from PIL import Image 

img=Image.open(r"C:\img1.png")

pixelMap = img.load()
pixel = pixelMap[0,0]
print(pixel)

Output:0

Desired Output: (0, 0, 0)

Dovski14
  • 11
  • 3

1 Answers1

1

Your image is probably a palette image - see here. So change your code to this:

from PIL import Image 

# Load image - ensuring RGB not palette
img=Image.open(r"C:\img1.png").convert('RGB')

pixelMap = img.load()
pixel = pixelMap[0,0]
print(pixel)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432