Skip to content

Instantly share code, notes, and snippets.

@robgon-art
Created January 8, 2022 20:21
Show Gist options
  • Save robgon-art/781be13086e9d4202a3fe8f3041e4747 to your computer and use it in GitHub Desktop.
Save robgon-art/781be13086e9d4202a3fe8f3041e4747 to your computer and use it in GitHub Desktop.
import math
import numpy as np
from PIL import Image
img = Image.open("input_image.png")
image_np = np.array(img, dtype = np.float32)
dark_r = np.quantile(image_np[:,:,0:1], 0.1)
dark_g = np.quantile(image_np[:,:,1:2], 0.1)
dark_b = np.quantile(image_np[:,:,2:3], 0.1)
for j in range(512):
for i in range(512):
d = math.sqrt((j-256.0) * (j-256) + (i-256.0) * (i-256))
alpha = 1.0
if d > 180:
alpha = math.sin(d*math.pi/360)
new_pix = image_np[j,i,:] * alpha + np.array([dark_r, dark_g, dark_b]) * (1.0 - alpha)
image_np[j,i,:] = image_np[j,i,:]*0.25 + new_pix*0.75
image_int = image_np.round().clip(0, 255).astype(np.uint8)
image_pil = Image.fromarray(image_int)
image_pil.save("output_image.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment