Last active
January 9, 2021 05:28
-
-
Save aryamansharda/f9ba77d41735932c6303c85abdccaff4 to your computer and use it in GitHub Desktop.
HistogramBrightness
This file contains 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
from PIL import Image | |
def boundedPixelValue(color, brightnessFactor): | |
scaledValue = float(color * (1 + brightnessFactor)) | |
if scaledValue < 0: | |
return 0 | |
elif scaledValue > 255: | |
return 255 | |
return int(scaledValue) | |
im = Image.open("source.jpg") | |
out = Image.new('RGB', im.size, 0xffffff) | |
brightnessFactor = float(input("Enter brightness amount (-1.0 to 1.0: ")) | |
width, height = im.size | |
for x in range(width): | |
for y in range(height): | |
r,g,b = im.getpixel((x,y)) | |
updatedR = boundedPixelValue(r, brightnessFactor) | |
updatedG = boundedPixelValue(g, brightnessFactor) | |
updatedB = boundedPixelValue(b, brightnessFactor) | |
out.putpixel((x,y), (updatedR, updatedG, updatedB)) | |
out.save('brightnessScaled.jpg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment