Last active
February 17, 2021 19:27
-
-
Save BilHim/664a993684e6b6270c7d31aab646cde9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Converting image into a numpy array with a dimension (width, height, 3) | |
| data = np.array(image) | |
| # Calculate average brightness | |
| μ = np.mean(data, axis=2) | |
| μ_mean = μ.mean() | |
| # 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_ = truncate(alpha*(r - μ_mean) + μ_mean) | |
| g_ = truncate(alpha*(g - μ_mean) + μ_mean) | |
| b_ = truncate(alpha*(b - μ_mean) + μ_mean) | |
| 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