CS1315: Introduction to Media Computation Using Loops for Pictures.

Slides:



Advertisements
Similar presentations
CS2984: Introduction to Media Computation Drawing directly on images.
Advertisements

Book Scanning & Digital Image Production The VRC Guide to Imaging By Kate Stepp.
Grey Level Enhancement Contrast stretching Linear mapping Non-linear mapping Efficient implementation of mapping algorithms Design of classes to support.
Color Vision. Wavelength properties: ● Hue: psychological reaction to different wavelengths of light. (Basically the same thing as color). ● Different.
Digital Imaging and Image Analysis
01-IntroToMediaComp1 Barb Ericson Georgia Institute of Technology Oct 2010 Introduction to Computer Science and Media Computation.
Twelve painting with procedures. Overview Making shaded images with procedures Making a more elegant language Making textures with noise functions.
CSC Computing with Images1 Image encodings CSC 1040.
Copying and Transforming Pictures. First, finding the min or max… Next homework asks you to write a function to find the darkest and lightest shade of.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
+ Introduction to Programming My first red-eye removal.
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)
© 1999 Rochester Institute of Technology Color. Imaging Science Workshop for Teachers ©Chester F. Carlson Center for Imaging Science at RIT Color Images.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
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.
Towards Collaborative Dynabooks In Alan Kay’s vision, the computer’s greatest purpose is to facilitate learning through creation and exploration of multimedia.
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.
CSC Computing with Images
CS1315: Introduction to Media Computation Making sense of functions.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
CS 101: Introduction to Computing Color replacements and targeted color replacement (if statement) Developed by Mark Guzdial, Georgia Institute of Technology,
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
Chapter 5: Advanced Picture Techniques (partial deck)
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
01-IntroToMediaComp1 Barb Ericson Georgia Institute of Technology Feb 2010 Introduction to Computer Science and Media Computation.
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
Digital Images are represented by manipulating this…
ITEC 109 Multimedia Lecture Lecture 23. Photo manipulation Review Lists / Arrays.
Yet Another Version. More Careful Edge Detection def lineDetect(filename): orig = makePicture(filename) makeBw = makePicture(filename) for x in range(0,getWidth(orig)-1):
Chapter 3: Modifying Pictures using Loops. Chapter Learning Objectives.
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.
Examples from Georgia Tech’s CS 1315: Introduction to Media Computation Class examples and student work.
Python: Working with pixels. Reminder: Conditionals if age < 18: showInformation(“Sorry, not allowed to vote yet.”) else: showInformation(“Please select.
ManipulatingPictures-part31 Manipulating Pictures, Arrays, and Loops part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Intro CS and Media Computation1 Barb Ericson Georgia Institute of Technology Feb 2010 Introduction to Computer Science and Media Computation.
To Students in Psychology Some of you have used part of at least one Trinity Day learning about color perception on your own. The internet is.
CS1315: Introduction to Media Computation Making sense of functions.
1 CS 177 Week 4 Recitation Slides for Loop if statement and range.
Image Processing Objectives To understand pixel based image processing
Chapter 4: Modifying Pictures using Loops
CASTLEFORD CAMERA CLUB
Multimedia Summer Camp
Week 2.
Media as a Context for Learning Computation
Media as a Context for Learning Computation
Chapter 4: Modifying Pictures using Loops
Chapter 3: Modifying Pictures using Loops
CS1315: Introduction to Media Computation
CS1315 Introduction to Media Computation
Chapter 3: Modifying Pictures using Loops
Media as a Context for Learning Computation
Agenda – 1/31/18 Questions? Group practice problems
A Media Computation Cookbook
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops part 6
Digital Image Processing
CS 177 Week 3 Recitation Slides
Chapter 3: Modifying Pictures using Loops
CS1315: Introduction to Media Computation
Multimedia Summer Camp
CS1315: Introduction to Media Computation
Manipulating Pictures, Arrays, and Loops part 6
Presentation transcript:

CS1315: Introduction to Media Computation Using Loops for Pictures

Use a loop! Our first picture recipe def decreaseRed(picture): for p in getPixels(picture): value=getRed(p) setRed(p,value*0.5) Used like this: >>> file="/Users/guzdial/mediasources/katie.jpg" >>> picture=makePicture(file) >>> show(picture) >>> decreaseRed(picture) >>> repaint(picture)

Once we make it work for one picture, it will work for any picture

Think about what we just did Did we change the program at all? Did it work for all the different examples? What was the input variable picture each time, then?  It was the value of whatever picture we provided as input! def decreaseRed(picture): for p in getPixels(picture): value=getRed(p) setRed(p,value*0.5)

Read it as a Recipe Recipe: To decrease the red Ingredients: One picture, name it pict Step 1: Get all the pixels of pict. For each pixel p in the pixels… Step 2: Get the value of the red of pixel p, and set it to 50% of its original value def decreaseRed(picture): for p in getPixels(picture): value=getRed(p) setRed(p,value*0.5)

Let’s use something with known red to manipulate: Santa Claus

What if you decrease Santa’s red again and again and again…? >>> file=pickAFile() >>> pic=makePicture(file) >>> decreaseRed(pic) >>> show(pic) (That’s the first one) >>> decreaseRed(pic) >>> repaint(pic) (That’s the second)

Increasing Red def increaseRed(picture): for p in getPixels(picture): value=getRed(p) setRed(p,value*1.2) What happened here?!? Remember that the limit for redness is 255. If you go beyond 255, all kinds of weird things can happen

How does increaseRed differ from decreaseRed? Well, it does increase rather than decrease red, but other than that…  It takes the same input  It can also work for any picture It’s a specification of a process that’ll work for any picture There’s nothing specific to any picture here. Practical programs = parameterized processes

Clearing Blue def clearBlue(picture): for p in getPixels(picture): setBlue(p,0) Again, this will work for any picture. Try stepping through this one yourself!

Can we combine these? Why not! How do we turn this beach scene into a sunset? What happens at sunset?  At first, I tried increasing the red, but that made things like red specks in the sand REALLY prominent. That can’t be how it really works  New Theory: As the sun sets, less blue and green is visible, which makes things look more red.

A Sunset-generation Function def makeSunset(picture): for p in getPixels(picture): value=getBlue(p) setBlue(p,value*0.7) value=getGreen(p) setGreen(p,value*0.7)

Creating a negative Let’s think it through  R,G,B go from 0 to 255  Let’s say Red is 10. That’s very light red. What’s the opposite? LOTS of Red!  The negative of that would be 245: So, for each pixel, if we negate each color component in creating a new color, we negate the whole picture.

Recipe for creating a negative def negative(picture): for px in getPixels(picture): red=getRed(px) green=getGreen(px) blue=getBlue(px) negColor=makeColor( 255-red, 255-green, 255-blue) setColor(px,negColor)

Original, negative, double negative (This gives us a quick way to test our function: Call it twice and see if the result is equivalent to the original)

Converting to greyscale We know that if red=green=blue, we get grey  But what value do we set all three to? What we need is a value representing the darkness of the color, the luminance There are lots of ways of getting it, but one way that works reasonably well is dirt simple—simply take the average:

Converting to grayscale def grayScale(picture): for p in getPixels(picture): intensity = (getRed(p)+getGreen(p)+getBlue(p))/3 setColor(p,makeColor(intensity,intensity,intensity)) Shouldn’t that be “greyscale”?

Why can’t we get back again? Converting to greyscale is different from computing a negative.  A negative transformation retains information. With grayscale, we’ve lost information  We no longer know what the ratios are between the reds, the greens, and the blues  We no longer know any particular value. Media compressions are one kind of transformation. Some are lossless (like negative); Others are lossy (like grayscale)

But that’s not really the best grayscale In reality, we don’t perceive red, green, and blue as equal in their amount of luminance: How bright (or non-bright) something is.  We tend to see blue as “darker” and red as “brighter”  Even if, physically, the same amount of light is coming off of each Photoshop’s grayscale is very nice: Very similar to the way that our eye sees it  B&W TV’s are also pretty good

Building a better greyscale We’ll weight red, green, and blue based on how light we perceive them to be, based on laboratory experiments. def grayScaleNew(picture): for px in getPixels(picture): newRed = getRed(px) * newGreen = getGreen(px) * newBlue = getBlue(px) * luminance = newRed+newGreen+newBlue setColor(px,makeColor(luminance,luminance,luminance))

Comparing the two grayscales: Average on left, weighted on right

Let’s use a black cat to compare

Average on left, weighted on right