0% found this document useful (0 votes)
42 views3 pages

CST 205

This document contains Python code for applying various filters and effects to images. It defines functions to half the red value of each pixel, remove all blue values, lessen or increase red by a percentage, apply "rose-colored glasses" by adjusting green and blue percentages, lighten the entire image, make the image negative by inverting color values, convert to black and white by averaging pixel values, and a better black and white conversion method using luminance coefficients.

Uploaded by

api-446897780
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

CST 205

This document contains Python code for applying various filters and effects to images. It defines functions to half the red value of each pixel, remove all blue values, lessen or increase red by a percentage, apply "rose-colored glasses" by adjusting green and blue percentages, lighten the entire image, make the image negative by inverting color values, convert to black and white by averaging pixel values, and a better black and white conversion method using luminance coefficients.

Uploaded by

api-446897780
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#Student: Sergio Quiroz

#CST205-40_SP19
#Cohort 9, Team 5 - Pentagration
#Adam Houser, Jason Pettit, Colin Reed, Marcus Gonzalez, Sergio Quiroz

def get_pic():
return makePicture(pickAFile())

# Warm up
def halfRed():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
r = getRed(p)
setRed(p, 0.5 * r)
repaint(pic)

def noBlue():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
b = getBlue(p)
setBlue(p, 0)
repaint(pic)

# Problem 1
def lessRed(num):
pic = get_pic()
pixels = getPixels(pic)
percent = 1 - float(num) / 100 # have to call as float to avoid integer division
for p in pixels:
r = getRed(p)
setRed(p, percent * r)
repaint(pic)

# Problem 2
def moreRed(num):
pic = get_pic()
pixels = getPixels(pic)
percent = float(num) / 100
for p in pixels:
r = getRed(p)
setRed(p, r + (percent * r))
repaint(pic)
# potential problem, only max of 255 can be set for red
# mitigate with if to make sure max of 255 is set
# not sure what JES is doing. I assume increasing R value in RGB

# Problem 3
# trial and error for correct percentages
def roseColoredGlasses():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
g = getGreen(p)
b = getBlue(p)
setGreen(p, (g * 0.5))
setBlue(p, (b * 0.75))
repaint(pic)

# Problem 4
def lightenUp():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
oldColor = getColor(p)
newColor = makeLighter(oldColor)
setColor(p, newColor)
repaint(pic)

# Problem 5
def makeNegative():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
setRed(p, (255 - r))
setGreen(p, (255 - g))
setBlue(p, (255 - b))
repaint(pic)

# Problem 6
def BnW():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
luminance = (r + g + b) / 3
setRed(p, luminance)
setGreen(p, luminance)
setBlue(p, luminance)
repaint(pic)

def betterBnW():
pic = get_pic()
pixels = getPixels(pic)
for p in pixels:
r = getRed(p)
g = getGreen(p)
b = getBlue(p)
luminance = (r * 0.299 + g * 0.587 + b * 0.114) / 3
setRed(p, luminance)
setGreen(p, luminance)
setBlue(p, luminance)
repaint(pic)

You might also like