Skip to content

Instantly share code, notes, and snippets.

@arifullahjan
Created March 2, 2019 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arifullahjan/74e6078f70d713f7088bb9cea9305e27 to your computer and use it in GitHub Desktop.
Save arifullahjan/74e6078f70d713f7088bb9cea9305e27 to your computer and use it in GitHub Desktop.
'''
python task1.py path/to/input threshold-int
'''
import PIL
from PIL import Image
import itertools
import sys
from PIL import ImageDraw
image = Image.open(sys.argv[1])
image = image.convert("L") # convert to signle channeled image
width, height = image.size
pixels = image.load() # allows pixel values to be edited
for x,y in itertools.product(range(width), range(height)): # all possible values of x and y
if pixels[x,y] > int(sys.argv[2]):
pixels[x,y] = 255
else:
pixels[x,y] = 0
image.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment