Plan for Today
- Last time, we learned about if statements, a way to conditionally apply operations.
- Now, we're going to experiment with if statements by creating a green screen filter.
Green Screen Example
- Works by replacing all the pixels of a certain color in one image with another image
- Color depends on the original image
- Idea: if a pixel is "close" in color to our target color, replace it with the corresponding pixel in the other image
Green Screen Continued
- How do we replace a pixel with another?
if(pixel1.isSimilarTo(RED, GREEN, BLUE, NUMBER))
BLUE values represent the target color
NUMBER is the "tolerance": bigger number be true more often. Should be between 0 and 255
- No need to use an inequality operator; that line of code just gives us a true or false directly
"Faded" Green Screen
Idea: instead of using the original pixel values, can blend them with background
Talk with a partner on how to modify the green screen code to achieve this effect
Writing Faded Green Screen
Green Screen: Multiple Passes
Write code to replace the red stop sign with leaves, and the blue sky with yosemite
- Midterm is in STLC 115 in two weeks!
- Email Shreya and me your OAE accommodations please
- Moving back to Canvas
Today, we learned more complicated methods for editing images, seeing the power of if statements and for loops. Next time, we'll move away from images and manipulate other kinds of data.