#Function to test image tinting def test(): file = pickAFile() picture = makePicture(file) sepiaTint(picture) # writePictureTo(picture, "C:\Documents and Settings\deckenc\My Documents\sepia.jpg") cyanTint(picture) # writePictureTo(picture, "C:\Documents and Settings\deckenc\My Documents\cyan.jpg") magentaTint(picture) # writePictureTo(picture, "C:\Documents and Settings\deckenc\My Documents\magenta.jpg") greenTint(picture) # writePictureTo(picture, "C:\Documents and Settings\deckenc\My Documents\green.jpg") quadColorsTint(picture) # writePictureTo(picture, "C:\Documents and Settings\deckenc\My Documents\quad.jpg") ###################################################################### # Function: sepiaTint(picture) # Description: Takes in a picture, converts the picture to greyscale, then tints each pixel # by increasing the red and increasing the yellow (actually decreases blue). The RGB # values are divided into intensity ranges and different tinting percentages are applied # accordingly to provide a better result than uniform tinting. ###################################################################### def sepiaTint(picture): #Convert image to greyscale greyScaleNew(picture) #loop through picture to tint pixels for p in getPixels(picture): red = getRed(p) blue = getBlue(p) #tint shadows if (red < 63): red = red*1.1 blue = blue*0.9 #tint midtones if (red > 62 and red < 192): red = red*1.15 blue = blue*0.85 #tint highlights if (red > 191): red = red*1.08 if (red > 255): red = 255 blue = blue*0.93 #set the new color values setBlue(p, blue) setRed(p, red) #refresh the picture to see the results repaint(picture) ###################################################################### # Function: cyanTint(picture) # Description: Takes in a picture, converts the picture to greyscale, then tints each pixel # by increasing the blue and increasing the green. The RGB values are divided into # intensity ranges and different tinting percentages are applied accordingly to provide # a better result than uniform tinting. ###################################################################### def cyanTint(picture): #Convert image to greyscale greyScaleNew(picture) #loop through picture to tint pixels for p in getPixels(picture): green = getGreen(p) blue = getBlue(p) #tint shadows if (green < 63): green = green*1.1 blue = blue*1.1 #tint midtones if (green > 62 and green < 192): green = green*1.15 blue = blue*1.15 #tint highlights if (green > 191): green = green*1.1 if(green > 255): green = 255 blue = blue*1.1 if (blue > 255): blue = 255 #set the new color values setBlue(p, blue) setGreen(p, green) #refresh the picture to see the results repaint(picture) ###################################################################### # Function: magentaTint(picture) # Description: Takes in a picture, converts the picture to greyscale, then tints each pixel # by increasing the blue and increasing the red. The RGB values are divided into # intensity ranges and different tinting percentages are applied accordingly to provide # a better result than uniform tinting. ###################################################################### def magentaTint(picture): #Convert image to greyscale greyScaleNew(picture) #loop through picture to tint pixels for p in getPixels(picture): red = getRed(p) blue = getBlue(p) #tint shadows if (red < 63): red = red*1.15 blue = blue*1.15 #tint midtones if (red > 62 and red < 192): red = red*1.2 blue = blue*1.2 #tint highlights if (red > 191): red = red*1.1 if (red > 255): red = 255 blue = blue*1.1 if (blue > 255): blue = 255 #set the new color values setBlue(p, blue) setRed(p, red) #refresh the picture to see the results repaint(picture) ###################################################################### # Function: greenTint(picture) # Description: Takes in a picture, converts the picture to greyscale, then tints each pixel # by increasing the green. The RGB values are divided into intensity ranges and # different tinting percentages are applied accordingly to provide a better result than # uniform tinting. ###################################################################### def greenTint(picture): #Convert image to greyscale greyScaleNew(picture) #loop through picture to tint pixels for p in getPixels(picture): green = getGreen(p) #tint shadows if (green < 63): green = green*1.12 #tint midtones if (green > 62 and green < 192): green = green*1.18 #tint highlights if (green > 191): green = green*1.1 if(green > 255): green = 255 #set the new color value setGreen(p, green) #refresh the picture to see the results repaint(picture) ###################################################################### # Function: quadColorsTint(picture) # Description: Takes in a picture, converts the picture to greyscale, then divides the # picture into 4 quadrants. Each quadrant is tinted a different color. The first quadrant # is tinted red, the second green, the third blue, and the fourth yellow. The RGB values # are divided into intensity ranges and different tinting percentages are applied # accordingly to provide a better result than uniform tinting. ###################################################################### def quadColorsTint(picture): #Convert image to greyscale greyScaleNew(picture) #get the height and width height = getHeight(picture) width = getWidth(picture) #divide in half to compute quadrants xDelta = width/2 yDelta = height/2 #first quad red tint for x in range(0, xDelta): for y in range(0, yDelta): p = getPixel(picture, x, y) red = getRed(p) #tint shadows if (red < 63): red = red*1.15 #tint midtones if (red > 62 and red < 192): red = red*1.2 #tint highlights if (red > 191): red = red*1.1 if (red > 255): red = 255 #set the new color value setRed(p, red) #second quad green tint for x in range(xDelta, width): for y in range(0, yDelta): p = getPixel(picture, x, y) green = getGreen(p) #tint shadows if (green < 63): green = green*1.15 #tint midtones if (green > 62 and green < 192): green = green*1.2 #tint highlights if (green > 191): green = green*1.1 if(green > 255): green = 255 #set the new color value setGreen(p, green) #third quad blue tint for x in range(0, xDelta): for y in range(yDelta, height): p = getPixel(picture, x, y) blue = getBlue(p) #tint shadows if (blue < 63): blue = blue*1.15 #tint midtones if (blue > 62 and blue < 192): blue = blue*1.2 #tint highlights if (blue > 191): blue = blue*1.1 if (blue > 255): blue = 255 #set the new color value setBlue(p, blue) #fourth quad yellow tint for x in range(xDelta, width): for y in range(yDelta, height): p = getPixel(picture, x, y) blue = getBlue(p) #tint shadows if (blue < 63): blue = blue*0.85 #tint midtones if (blue > 62 and blue < 192): blue = blue*0.8 #tint highlights if (blue > 191): blue = blue*0.9 #set the new color value setBlue(p, blue) #refresh the picture to see the results repaint(picture) ###################################################################### # Function: greyScale(picture) ###################################################################### def greyScale(picture): for p in getPixels(picture): intensity = (getRed(p)+getGreen(p)+getBlue(p))/3 setColor(p, makeColor(intensity, intensity, intensity)) ###################################################################### # Function: greyScaleNew(picture) ###################################################################### def greyScaleNew(picture): for p in getPixels(picture): newRed = getRed(p) * 0.299 newGreen = getGreen(p) * 0.587 newBlue = getBlue(p) * 0.114 luminance = newRed + newGreen + newBlue setColor(p, makeColor(luminance, luminance, luminance)) ###################################################################### # Function: fadeToBlack(picture) ###################################################################### def fadeToBlack(picture): for p in getPixels(picture): setColor(p, makeColor((getRed(p)*0.5), (getGreen(p)*0.5), (getBlue(p)*0.5)))