1
0
mirror of synced 2024-06-07 10:05:19 +02:00
art-research/image_processing/downgrademypic.py

29 lines
927 B
Python
Executable File

from PIL import Image
import cv2
import numpy as np
import optparse
parser = optparse.OptionParser()
p = optparse.OptionParser()
p.add_option('--image', '-i', default="image.png")
options, arguments = p.parse_args()
print("Converting "+options.image)
#print("the option is " + options.image)
##################################################### Solution 1 ##############################################################
#PIL.Image.convert parametrs :
#https://pillow.readthedocs.io/en/4.2.x/reference/Image.html?highlight=image.convert#PIL.Image.Image.convert
#PIL.Image.convert Modes :
#https://pillow.readthedocs.io/en/4.2.x/handbook/concepts.html#concept-modes
#image convert to 1-bit pixels, black and white, stored with one pixel per byte and Dithering
imageConvert = Image.open(options.image).convert(mode='1',dither=Image.FLOYDSTEINBERG)
imageConvert.save('converted.png')
print("Done, saved in converted.png")