-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is PIL reading RGB values correctly? #3420
Comments
On macOS 10.14, I get (243, 243, 245) from Gimp as well as Pillow. Are you able to test the point with an application like Gimp, rather than another programming library? |
On my mac (10.13.6) I get 243,243,245 with PIL. I don't have Gimp but I tried OpenCV to see what it did. Here are the results. OpenCV
Pillow
I'm confused why PIL says one thing opencv says another. |
I also get 243, 243, 243 with cv2. import os
import numpy as np
from PIL import Image
x, y = 207, 0
filename = "qtr.jpg"
def pixel_access():
# Image.LOAD_TRUNCATED_IMAGES = True
im = Image.open(filename)
px = im.load()
print("pixel_access")
r, g, b = px[x, y]
print(r, g, b)
def numpy_array():
im = Image.open(filename)
im_array = np.array(im)
print("numpy_array")
r, g, b = im_array[y][x]
print(r, g, b)
def cv2_imread():
import cv2
im_cv2 = cv2.imread(filename)
print("cv2_imread")
b, g, r = im_cv2[y][x] # Note BGR
print(r, g, b)
def imagemagick():
# https://www.imagemagick.org/discourse-server/viewtopic.php?t=13694
cmd = f"convert '{filename}[1x1+{x}+{y}]' -format '%[fx:int(255*r)] %[fx:int(255*g)] %[fx:int(255*b)]' info:"
print("imagemagick")
os.system(cmd)
print("")
print(filename)
numpy_array()
pixel_access()
imagemagick()
cv2_imread()
Different JPEG decoders? If I |
Different JPEG decoders is a good guess. Perhaps if it was saved as a lossless format like PNG then they'd all return the same value? |
Sound reasonable. |
@hugovk I think this article helps shed more light on the differences
Is it possible to provide an integer accurate decompression in the future for better compatibility? |
#6047 was opened by another user referencing the same article. They found that their problem was fixed by upgrading to Pillow 9.0.1 |
What did you do?
I loaded an image like this.
What did you expect to happen?
I expect it to load the image as it resides on the disk without manipulating RGB values. My implication is that PIL is not reading the data right.
What actually happened?
When I look at index 207 in the first row of data, the values look like this:
However, if I load the image with Leptonica in c++ and c# or with dotnet's built in imaging classes, index 207 looks like this:
So, my question is, who is right or who should I believe?
What are your OS, Python and Pillow versions?
The image in question:
The text was updated successfully, but these errors were encountered: