Skip to content

Instantly share code, notes, and snippets.

@BilHim
Created February 17, 2021 19:42
Show Gist options
  • Save BilHim/d0bde6a41caf370aa61005cca1a5783f to your computer and use it in GitHub Desktop.
Save BilHim/d0bde6a41caf370aa61005cca1a5783f to your computer and use it in GitHub Desktop.
# Calculate factor
if beta == 255: alpha = np.infty
else: alpha = (255+beta)/(255-beta)
for x in range(width):
for y in range(height):
r, g, b = image.getpixel((x, y))
μ = (r+g+b)/3
r_ = truncate(alpha*(r - μ) + μ)
g_ = truncate(alpha*(g - μ) + μ)
b_ = truncate(alpha*(b - μ) + μ)
new_pixel = (int(r_), int(g_), int(b_))
new_image.putpixel((x, y), new_pixel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment