Reputation: 89
I’m trying to extract the RGB values from an image using Python’s Pillow library on my MacBook Pro. However, the RGB values I get differ slightly from those identified using online RGB color extractors (e.g. https://www.site24x7.com/tools/color-code-picker.html). I've also tried with cv2, which gives me the same value as PIL.
For example, with the below method I get: 249, 222, 253
However, online RGB identifiers give: 255, 221, 255
Another method I tried is googling "rgb color picker" and picking a specific combination of RGB values. Then, when I screenshot the resulting colour, cv2 and PIL again give slightly different values than what I input.
See code below that I used for PIL.
from PIL import Image
image_path = "Documents/screenshots/pic.png"
try:
with Image.open(image_path) as img:
img = img.convert('RGB') # Ensure RGB mode
pixels = list(img.getdata())
print("First 10 pixel RGB values:", pixels[:10])
except Exception as e:
print(f"An error occurred: {e}")
Upvotes: 1
Views: 34