Replacing colors using if We don’t have to do one-to-one changes or replacements of color We can use if to decide if we want to make a change.  We could.

Slides:



Advertisements
Similar presentations
Conditionals-part31 Conditionals – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Advertisements

A Digital Imaging Primer Nick Dvoracek Instructional Resources Center University of Wisconsin Oshkosh.
01-IntroToMediaComp1 Barb Ericson Georgia Institute of Technology Oct 2010 Introduction to Computer Science and Media Computation.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 5: Advanced Picture Techniques.
+ Introduction to Programming My first red-eye removal.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Adobe Photoshop CS Design Professional COLORS ADJUSTING.
© 2011 Delmar, Cengage Learning Chapter 11 Adjusting Colors.
Chapter 11 Adjusting Colors. Chapter Lessons Correct and adjust color Enhance colors by altering saturation Modify color channels using levels Create.
Picture Color Manipulation. Using a Loop Our first picture recipe def decreaseRed(picture): for p in getPixels(picture): value=getRed(p) setRed(p,value*0.5)
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
EE 113D Final Project: Colorization Spring, 2006 Group Members: Johnny Cheng Brian Cheung Austin Wong Professor: R. Jain TA: Rick Lan.
CS1315: Introduction to Media Computation Referencing pixels directly by index number.
Manipulating Pixels by Range and More on Functions.
CS2984: Introduction to Media Computation Using Loops for Pictures Conditionals Copying images.
Project ideas …. Basic Photoshop: – Take your green screen photo and select your head and place it over another student's head in their green screen photo.
CSC Computing with Images
CS1315: Introduction to Media Computation Making sense of functions.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Program Design and Debugging. How do programmers start? How do you get started with a program? “Programming is all about debugging a blank piece of paper.”
Introduction to Image processing using processing.
CS1315: Introduction to Media Computation How to design and debug a program: Top-down, bottom-up, and debugging. Using background subtraction and chromakey.
CS 101: Introduction to Computing Color replacements and targeted color replacement (if statement) Developed by Mark Guzdial, Georgia Institute of Technology,
03-ConditionalsInPictures Barb Ericson Georgia Institute of Technology Feb 2010 Working with ranges in pictures.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 5: Advanced Picture Techniques.
Chapter 5: Advanced Picture Techniques (partial deck)
Chapter 5: Advanced Picture Techniques. Chapter Objectives.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
CPSC1301 Computer Science 1 Chapter 4 Manipulating Pictures, Arrays, and Loops part 5.
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
TOPIC 10 THE IF STATEMENT 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
ITEC 109 Multimedia Lecture Lecture 23. Photo manipulation Review Lists / Arrays.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Yet Another Version. More Careful Edge Detection def lineDetect(filename): orig = makePicture(filename) makeBw = makePicture(filename) for x in range(0,getWidth(orig)-1):
CS1315: Introduction to Media Computation Using Loops for Pictures.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Changing colors in an area Part 3: Chromakey.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
CS 101: Introduction to Computing Programs that change Pictures Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert.
Color Distribution A block BrownYellowOrangeRedGreenBlue GreenYellowOrangeRedPurple M&M Skittles.
Mixing Complementary Colors to create neutrals. Complementary colors are directly across from one another on the color wheel. When mixed they get various.
Python: Working with pixels. Reminder: Conditionals if age < 18: showInformation(“Sorry, not allowed to vote yet.”) else: showInformation(“Please select.
1 CS 177 Week 7 Recitation Slides Modifying Sounds using Loops + Discussion of some Exam Questions.
ManipulatingPictures-part31 Manipulating Pictures, Arrays, and Loops part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
CS1315: Introduction to Media Computation Making sense of functions.
1 CS 177 Week 4 Recitation Slides for Loop if statement and range.
Introduction to Python
Topic 10 The if statement Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Manipulating Pictures, Arrays, and Loops
Barb Ericson Georgia Institute of Technology August 2005
Manipulating Pictures, Arrays, and Loops part 5
Name: _______________________________
CS1315: Introduction to Media Computation
Agenda – 1/31/18 Questions? Group practice problems
Practice with loops! What is the output of each function below?
Removing Color Casts in GIMP
A Media Computation Cookbook
Can I color yellow?. Can I color yellow?
Georgia Institute of Technology
What Color is it?.
CS 177 Week 3 Recitation Slides
CS1315: Introduction to Media Computation
How to Select a Good Book for Your Reading Ability
Multimedia Summer Camp
CS1315: Introduction to Media Computation
CSC1401 Manipulating Pictures 2
Presentation transcript:

Replacing colors using if We don’t have to do one-to-one changes or replacements of color We can use if to decide if we want to make a change.  We could look for a range of colors, or one specific color.  We could use an operation (like multiplication) to set the new color, or we can set it to a specific value. It all depends on the effect that we want. Experiment!

Posterizing: Reducing the range of colors

Posterizing: How we do it We look for a range of colors, then map them to a single color.  If red is between 63 and 128, set it to 95  If green is less than 64, set it to 31 ... This requires many if statements, but the idea is pretty simple. The end result is that many colors, get reduced to a few colors

Posterizing function def posterize(picture): #loop through the pixels for p in getPixels(picture): #get the RGB values red = getRed(p) green = getGreen(p) blue = getBlue(p) #check and set red values if(red < 64): setRed(p, 31) if(red > 63 and red < 128): setRed(p, 95) if(red > 127 and red < 192): setRed(p, 159) if(red > 191 and red < 256): setRed(p, 223) #check and set green values if(green < 64): setGreen(p, 31) if(green > 63 and green < 128): setGreen(p, 95) if(green > 127 and green < 192): setGreen(p, 159) if(green > 191 and green < 256): setGreen(p, 223) #check and set blue values if(blue < 64): setBlue(p, 31) if(blue > 63 and blue < 128): setBlue(p, 95) if(blue > 127 and blue < 192): setBlue(p, 159) if(blue > 191 and blue < 256): setBlue(p, 223)

Comments Any line that starts with # is ignored by Python. This allows you to insert comments: Notes to yourself (or another programmer) that explain what’s going on here.  When programs get longer, and have lots of separate parts, it gets hard to figure out from the code alone what each piece does.  Comments can help explain the big picture.

Generating toned prints Toning adds a color tint to grayscale images  E.g. sepia-toning adds a brown tint that we associate with vintage photographs. We can’t just increase the amount of yellow in the picture.  Instead, colors in the shadows, midtones and highlights get tinted differently.  We can create such conversions using if

Example of sepia-toned prints

Here’s how we do it def sepiaTint(picture): #Convert image to greyscale grayScaleNew(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) Bug alert! Make sure you indent the right amount

What’s going on here? First, we’re calling grayScaleNew (the one with weights).  It’s perfectly okay to have one function calling another. We then manipulate the red (increasing) and the blue (decreasing) channels to bring out more yellows and oranges.  Why are we doing the comparisons on the red?  Why not? After grayscale conversion, all channels are the same!  Why these values?  Trial-and-error: Experiment with values until the effect is what you want

Reviewing: All the Programming We’ve Seen Assigning names to values with = Printing with print Looping with for Testing with if Defining functions with def  Making a real function with parameters uses ()  Making a real function with an output uses return Using functions to create programs (recipes) and executing them