lab 2: rose-colored glasses or jaded
DESCRIPTION
Lab 2: Rose-Colored Glasses or Jaded. Michael Stewart. Colors as points in 3D color space. Today we will continue to take advantage of the distance between two colors as representing those colors’ similarity. This is facilitated by our encoding of color. One way to view this encoding is : - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/1.jpg)
Lab 2: Rose-Colored Glasses or Jaded
Michael Stewart
![Page 2: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/2.jpg)
Colors as points in 3D color space
• Today we will continue to take advantage of the distance between two colors as representing those colors’ similarity.
• This is facilitated by our encoding of color.• One way to view this encoding is :• http://en.wikipedia.org/wiki/
File:RGB_color_solid_cube.png
![Page 3: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/3.jpg)
New JES methods
• pixel.getRed…• color.getRed…• setColor(pixel, newColor)• distance(color1, color2)
• dir
![Page 4: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/4.jpg)
Driver Function
• Sometimes when programming, you may want to test many different functions
• Or you may want to test a function that requires several arguments
• Writing one function which makes these tedious calls for you can be useful
![Page 5: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/5.jpg)
Conditionals and Branching
http://xkcd.com/210/
![Page 6: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/6.jpg)
Conditionals and Branching (cont’d.)
• So far our code has been rather declarative• However we can write recipes that perform
differently in different circumstances.• This is usually called “branching” or
“conditionals”
![Page 7: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/7.jpg)
Conditionals and Branching (cont’d.)
• The simplest kind of branch statement is the “if” statement.
• In this example, the function “doSomething” will only be called sometimes.
if somethingIsTrue:
doSomething()
![Page 8: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/8.jpg)
Boolean
• In normal numerical arithmetic, you use numerical operators (+, -, *, /) and multiple numbers, to produce a numerical result.
• In BOOLEAN arithmetic, you use boolean operators (==, <, >, not, and, or, etc.), and multiple boolean/numerical values(True, False), to produce a boolean result.
![Page 9: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/9.jpg)
Boolean (cont’d.)
• Let’s try some in the command window:• 1 > 2• 1==1• True and False• Not True
A B A and B A or B
True True True True
True False False True
False True False True
False False False False
![Page 10: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/10.jpg)
Lab Assignment
• Download the skeleton for the lab from today’s page
• Start with an image like this
![Page 11: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/11.jpg)
Lab Assignment (cont’d.)
• First, tint the image to a desired color, like this:
![Page 12: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/12.jpg)
Lab Assignment (cont’d).• Swap Roles with your partner.• Now, change the color of a certain range of
colors. So using the same starting point as tint, produce this:
![Page 13: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/13.jpg)
Lab Assignment (cont’d.)
What’s the difference?!
![Page 14: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/14.jpg)
Lab Assignment (cont’d.)
In the first picture, you’re making every
pixel closer to the target color.
In the second, you only change pixels of similar color to a color of your
choice.
![Page 15: Lab 2: Rose-Colored Glasses or Jaded](https://reader034.vdocuments.net/reader034/viewer/2022051421/5681609d550346895dcfc4b4/html5/thumbnails/15.jpg)
Lab Assignment (cont’d.)
• Submit your work to the Lab 2 Moodle assignment