You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's play around with image dithering, starting with this nice, low-res picture of Theresa May:
According to the docs calling convert in "P" mode defaults to the WEB palette with dithering:
orig.convert("P")
Nice, that looks good! And you can pass Image.NONE to disable the dithering.
What if we want to use less colors? Maybe we cut down the bit depth and dither to make up for it, for a retro effect.
Checking the docs again, it claims that we can use an ADAPTIVE palette and pass in some number of colors; let's use 16.
The docs say that dithering is used when converting from "RGB" to "P" and that it defaults to FLOYDSTEINBERG, but let's pass in dither just to make sure:
Doesn't look dithered - test it on a gradient image and we get severe banding:
Is there a workaround? Well, the docs for quantize claim to apply a dither.
Let's try it:
orig.quantize(16, dither=Image.FLOYDSTEINBERG)
No dice, exactly the same as the previous. Looking at the code, we see that quantize calls ImagingCore.convert with a dither - but ONLY if you pass in a palette!
Let's try that:
# Call .quantize once to get the palettepal=orig.quantize(16)
# And again using that palettedither_lesscol=orig.quantize(16, palette=pal, dither=Image.FLOYDSTEINBERG)
There we go, that's what I expected.
What did you expect to happen?
Image.convert should be able to simultanously handle an ADAPTIVE palette and apply dithering (or not) based on the dither argument.
Additionally, Image.quantize should apply dithering (or not) based on the dither argument.
What actually happened?
orig.convert("P", palette=Image.ADAPTIVE, colors=16, dither=Image.FLOYDSTEINBERG) produces a non-dithered image.
orig.quantize(16, dither=Image.FLOYDSTEINBERG) also produces a non-dithered image.
What are your OS, Python and Pillow versions?
OS: Linux Mint 20.1
Python: 3.8.10
Pillow: 7.0.0
The text was updated successfully, but these errors were encountered:
What did you do?
Let's play around with image dithering, starting with this nice, low-res picture of Theresa May:
According to the docs calling
convert
in "P" mode defaults to theWEB
palette with dithering:Nice, that looks good! And you can pass
Image.NONE
to disable the dithering.What if we want to use less colors? Maybe we cut down the bit depth and dither to make up for it, for a retro effect.
Checking the docs again, it claims that we can use an
ADAPTIVE
palette and pass in some number ofcolors
; let's use 16.The docs say that dithering is used when converting from "RGB" to "P" and that it defaults to
FLOYDSTEINBERG
, but let's pass indither
just to make sure:Doesn't look dithered - test it on a gradient image and we get severe banding:
Is there a workaround? Well, the docs for quantize claim to apply a dither.
Let's try it:
No dice, exactly the same as the previous. Looking at the code, we see that
quantize
callsImagingCore.convert
with a dither - but ONLY if you pass in a palette!Let's try that:
There we go, that's what I expected.
What did you expect to happen?
Image.convert
should be able to simultanously handle anADAPTIVE
palette and apply dithering (or not) based on thedither
argument.Additionally,
Image.quantize
should apply dithering (or not) based on thedither
argument.What actually happened?
orig.convert("P", palette=Image.ADAPTIVE, colors=16, dither=Image.FLOYDSTEINBERG)
produces a non-dithered image.orig.quantize(16, dither=Image.FLOYDSTEINBERG)
also produces a non-dithered image.What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: