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
Converting P mode images to HSV fails with "ValueError: conversion not supported" in version 6.0.0 and later #3997
Comments
#!/usr/bin/env bash
python3 setup.py clean
rm -f "PIL/*.so"
pip3 uninstall pillow -y
python3 setup.py install
python3 3997.py
from PIL import Image
x = Image.open("3997.png").quantize(colors=10, method=1)
print(x.convert(mode="HSV").getcolors()) $ python --version
Python 3.7.4
$ git bisect start
$ git bisect good 5.4.1
$ git bisect bad 6.0.0
$ git bisect run ./bisect.sh
...
f61828acdcc846cbf29ff991425eb40d966d5b03 is the first bad commit
commit f61828acdcc846cbf29ff991425eb40d966d5b03
Date: Tue Mar 19 11:13:58 2019 +1100
Promote P images to PA in putalpha
:040000 040000 fbea0af0f1959311d72dd269fd70607cf255e84a 9aa294c996483580d0752a74c7d9d27a7ecfe487 M Tests
:040000 040000 d2b9276a992da843d799dc94a578981e5eed635f 2759727adb9e49468f91217bfc19bb266cf8d6ae M src
bisect run success |
If you're interested in an immediate workaround, I would suggest converting to RGB first. Quickly looking at the situation, that is what Pillow would have been doing internally in 5.4.1. from PIL import Image
x = Image.open('PNG-Gradient_hex.png').quantize(colors=10,method=1)
print x.convert('RGB').convert('HSV').getcolors() |
Thank you! Yes, that fixes my problem. |
I've created PR #4004 to resolve this. |
Also, while this has no bearing on the problem that you've reported, since you are using Python 2.7, you should be aware that Pillow is a project that has committed to dropping support for Python 2.7 in 2020 - https://python3statement.org/. |
I'm in the slow process of converting codebases at work over from 2.7 to 3 now. I think about the end of 2019 bearing down as a deadline all the time. Thank you for supporting 2.7 through the end of 2019 and not leaving earlier! I need every day I can get! |
What did you do?
I want to take an RGB PNG as input, quantize it, convert to HSV and call getcolors() on the result to see a listing of (pixel count, (H,S,V)) values. As a bigger-picture idea of what I'm trying to accomplish, the goal is to look for a certain hue and determine if the number of pixels that are "close" to that hue are above a certain threshold. Eg: "Do more than 10% of the pixels in the image have a hue near 250?" The information from getcolors helps quite a bit with answering that question and the quantization helps with the "near 250" part of the question. The code below is what I've been using, and it works fine up through Pillow 5.4.1.
What did you expect to happen?
Pillow 5.4.1 produces this output when calling getcolors():
What actually happened?
Pillow 6.0.0 and later throws an exception as part of the convert() call:
What are your OS, Python and Pillow versions?
Sample input image:
The text was updated successfully, but these errors were encountered: