0

I want to use Dithering from pillow, (https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Dither.FLOYDSTEINBERG)

My question is how to import dither from pillow,

Following is my code,

import os

from PIL import Image



ORIGIN_PATH = "/home/prajakta/Tasks/Evaluate detection model on scanned customer documents/scanned_docs/"
#DESTIN_PATH = "/home/prajakta/Tasks/Evaluate detection model on scanned customer documents/scanned_docs_grayscale/"


for filename in os.listdir(ORIGIN_PATH):
    img = Image.open(ORIGIN_PATH + filename).convert("L", dither=Image.Dither)
    img.show()

Thank you in advance.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
aarya
  • 83
  • 1
  • 8
  • You need to pass a mode along with it, like `dither=Image.Dither.FLOYDSTEINBERG` – Jeru Luke Jul 05 '22 at 13:54
  • @Jeru Luke Thank you it works. Is it possible to add a gray background ( half gray and half white ) to the image and then dither it? Also is there a threshold to control dithering? – aarya Jul 05 '22 at 14:17
  • @JeruLuke could you please say for the above comment? – aarya Jul 05 '22 at 14:25
  • Give this a try: `im1 = Image.open(lena.jpg').convert("P").quantize(colors=2, method=Image.Quantize.MEDIANCUT, kmeans=2, palette="ADAPTIVE", dither=Dither.FLOYDSTEINBERG)` – Jeru Luke Jul 05 '22 at 19:14

0 Answers0