hbldh / hitherdither

Dithering algorithms for arbitrary palettes in PIL
MIT License
206 stars 21 forks source link

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

Open caas1729 opened 3 years ago

caas1729 commented 3 years ago

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.