Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image resize using PIL changes colors drastically

I am using the following code to resize an image using PIL

img = Image.open("in.png")
resized = ImageOps.fit(img, (200, 200), method=Image.ANTIALIAS)
resized.save("out.png")

But the output image colors look very different. Here they are for comparison, the big one is the original:

enter image description hereenter image description here

What's even stranger is that when I open them using the image viewer in ubuntu, they look the same. But not in Windows or MacOS.

like image 510
Juan Enrique Muñoz Zolotoochin Avatar asked May 08 '12 03:05

Juan Enrique Muñoz Zolotoochin


1 Answers

The larger image is using the Adobe RGB color profile. It is omitted from the smaller image, which means the color correction system will use some default (probably sRGB), which likely has a smaller gamut. This will cause the colors to appear duller.

Solution 1: Create the original image using sRGB instead of Adobe RGB.

Solution 2: Copy the color profile from the larger image to the smaller image.

Most Linux systems do not support color correction, at least not on the same scope that OS X or Windows do. So the fact that they appear the same in Ubuntu's image viewer is really a limitation of the image viewer program, which is unable to understand color profiles.

like image 87
Dietrich Epp Avatar answered Oct 03 '22 18:10

Dietrich Epp