0

I'm experiencing something strange when using Image.resize(). I have two images, one is a cropped version of the other. I've been working out the aspect ratio so that I can resize both images by the same factor and then resizing them separately.

Now for some reason, the larger of the two images is resized fine but the cropped version has some colour distortion. It almost appears like the image has been slightly saturated.

Has anyone experienced this before or know why it might be happening?

Thanks for reading.

Adam Nierzad
  • 942
  • 6
  • 19
  • Does the image change format during resizing? (e.g. from png to gif)? Could you post the relevant section of your code and possibly an MWE? – 317070 May 30 '15 at 00:20

3 Answers3

1

We really need to see code.

Without code, it's hard to know exactly, but I've commonly seen colour problems like this in PIL which are caused by type conversions. Some python image stuff assumes that numbers will floats between [0.0 - 1.0], and others assume that they will be integers in [0, 255], etc.

I suggest you play with type conversions like these to see if anything interesting happens:

image = image.astype(uint8)

image = image.astype(float32)

image = uint8(image)

image = float32(image)
Mike Ounsworth
  • 2,444
  • 21
  • 28
1

I haven't used Pillow, and I haven't seen your images or code, but let's say you have an image with a resolution of 400x200 and you want to resize it to 200x100, then each of the new pixels needs to have some color. Since the new image is smaller, the colors from the original will have to be mashed together to form the new colors. So, in this case where it gets smaller by a factor of two in each dimension, the color of each pixel will be the average of four pixels from the original. Similarly, if you resize to a larger image, depending on how that is done, the new pixels could be blocky (like when you zoom in to any pixel image) or smooth, which would mean that they are some interpolation of the pixels from the original image.

1

It could be that Pillow/PIL (and most other image libraries) are not colour space or gamma aware when they do the resizing/resampling.

Here is a related question to this issue with Pillow: SRGB-aware image resize in Pillow

This is a more general explanation of http://www.ericbrasseur.org/gamma.html

Damian Moore
  • 1,306
  • 1
  • 11
  • 13