Lab 5: Software Mirrors (part 1)
Bard College – Computer Science – Object-Oriented Programming

This lab asks you to create a series of image effects: a software photo-booth. You can work by yourself or in pairs for this lab.

Warm-Up

  1. Download an image and use loadImage() to bring it into Processing.
  1. Tint the image red using Processing’s tint() and display it.
  1. Understand the skeleton code below, particularly how the functions process the images passed to them and returns new images.

Software Mirror

Your “software mirror” sketch should load an image from a file or the webcam (next week), and then based on user input, transform the image with different effects. Starting with the code provided you should trigger specific effects when the user presses a key. Each effect (including those provided) should be fully explained in comments. All the effects should operate at the pixel level and not use filter, tint, blend, translate, rotate or scale.

  1. brighten ’b’ – adds a constant amount to each color channel, or scales each by some factor.
  • BONUS: Make it so that every time you press ‘b’ it gets progressively brighter.
  1. dim ’d’ – subtract a constant amount to each color channel, or scales each by some factor.
  • BONUS: Make it so that every time you press ‘d’ it gets progressively dimmer.
  1. swap ’w’ – swaps the red, green, and blue channels.
  1. gray ’g’ – turn the image into a gray scale by using your lum function from lab 3; remember what makes a color gray scale is equal values for the red, green & blue channels.  (alternatively, you can average the red, green, and blue channels and use that as the gray scale color).
  1. threshold ’t’ – turn the image into a binary, black-and-white image using a conditional statement.
  1. sepia ’s’ – applies a sepia effect, which raises the red and green channels, and lowers the blue. In particular it adds twice the sepiaAmount to the red, adds sepiaAmount to green, and subtracts sepiaAmount from blue. 20 is a good value for sepiaAmount.
  1. fairey ’f’ – applies an effect similar to Shepard Fairey’s iconic Obama “HOPE” poster. Each pixel is colored one of four colors depending upon the sum of RGB values. It assigns roughly equal intervals for each of the four colors.
rgb sum
Color
0 – 181
darkBlue: (0, 51, 76)
182 – 363
red: (217, 26, 33)
364 – 545
lightBlue: (112, 150, 158)
546 – 765
yellow: (252, 227, 166)
  1. your effect ’y’ – an image effect of your choice (e.g. mirror, green-screen,  glitch art, pixelation).

Filtering Images 


def setup():
    global video
    size(640, 480)  #use a size to something that makes sense for your image
    video = loadImage("doge.jpg")
    video.resize(width, height)
    image(video, 0, 0)

def draw():
    pass

def keyPressed():
    global video
    if key == 'i':         ## invert image
        image(invert(video), 0, 0)
    elif key == 'l':       ## turn the image upside down
        image(flip(video), 0, 0)
    elif key == 'z':
        image(flip(invert(video)), 0, 0)
    else: