Skip to content
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

Creating palette on certain images throws ValueError: zero-size array to reduction operation minimum which has no identity #11

Open
caas1729 opened this issue Oct 24, 2021 · 0 comments

Comments

@caas1729
Copy link

caas1729 commented Oct 24, 2021

  • Python version: 3.8
  • Operating System: Windows 10

Description

I attempted to create a palette with a PNG w/ a RGBA paltette converted to a JPEG w/ a RGB palette for dithering using the hitherdither.palette.Palette.create_by_median_cut(img) method.

img = Image.open('phcpd.png')

    img.load()

    background = Image.new("RGB", img.size, (255, 255, 255))

    background.paste(img, mask=img.split()[3])

    background.save('ikasdf.jpg', "JPEG", quality=80)

    img = Image.open('ikasdf.jpg')

    palette = hitherdither.palette.Palette.create_by_median_cut(img)

    img_dithered = hitherdither.ordered.bayer.bayer_dithering(img, palette, [256 / 4, 256 / 4, 256 / 4], order=8)

    img_dithered.save("test.png")

    print(type(img_dithered))

However, this error resulted:

Traceback (most recent call last):
  File "C:/Users/megag/PycharmProjects/SerenityBot/main_PIL_test.py", line 227, in <module>
    dither_test()
  File "C:/Users/megag/PycharmProjects/SerenityBot/main_PIL_test.py", line 27, in dither_test
    palette = hitherdither.palette.Palette.create_by_median_cut(img)
  File "C:\Users\megag\PycharmProjects\SerenityBot\venv\lib\site-packages\hitherdither\palette.py", line 185, in create_by_median_cut
    new_bins += median_cut(bin, dim)
  File "C:\Users\megag\PycharmProjects\SerenityBot\venv\lib\site-packages\hitherdither\palette.py", line 168, in median_cut
    mins = p.min(axis=0)
  File "C:\Users\megag\PycharmProjects\SerenityBot\venv\lib\site-packages\numpy\core\_methods.py", line 44, in _amin
    return umr_minimum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation minimum which has no identity

A link to the image is available here: phcpd.png.

@caas1729 caas1729 changed the title Creating palette throws ValueError: zero-size array to reduction operation minimum which has no identity Creating palette on certain images throws ValueError: zero-size array to reduction operation minimum which has no identity Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant