Skip to content

Instantly share code, notes, and snippets.

@zachaysan
Created November 17, 2012 17:35
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 zachaysan/4097973 to your computer and use it in GitHub Desktop.
Save zachaysan/4097973 to your computer and use it in GitHub Desktop.
Code to alter the original
def artistic_black_and_white(image, order=2):
pix = pixel_array(image)
draw = ImageDraw.Draw(image)
for y in range(image_height(image)):
for x in range(image_width(image)):
r,g,b = pix[x,y]
grey_value = (r + g + b)/3
adjusted_value = int(((grey_value / 255.0) ** (1 / float(order)) * grey_value))
r = adjusted_value
g = adjusted_value
b = adjusted_value
draw.point((x,y), fill=(r,g,b))
def analyse_image(image_filename):
name = image_filename.split("/")[-1].split(".")[0]
original_image = Image.open(image_filename)
original_image = original_image.convert("RGB")
save_image(original_image, "output/" + name + "-original.jpg")
for i in range(20):
image = original_image.copy()
greyness = i / 10.0 + 0.1
artistic_black_and_white(image, greyness)
save_image(image, "output/" + name + ("%s" % greyness) + "-artistic_black_and_white.jpg")
def run():
photos_done = 0
current_image = "photos/eric.jpg"
pc = photo_colors.PhotoColors()
analyse_image(current_image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment