CS1315: Introduction to Media Computation

Slides:



Advertisements
Similar presentations
+ Introduction to Programming My first red-eye removal.
Advertisements

A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
CS2984: Introduction to Media Computation Drawing directly on images.
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
CS 1 with Robots Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
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.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
+ Introduction to Programming My first red-eye removal.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Image Processing & Perception Sec 9-11 Web Design.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
TOPIC 7 MODIFYING PIXELS IN A MATRIX NESTED FOR LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Chapter 6: Modifying Pixels by Position. Chapter Learning Goals.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
CSC1401 Viewing a picture as a 2D image - 1. Review from the last week We used a getPixels() to get all of the pixels of a picture But this has been somewhat.
02-RangesInPictures1 Barb Ericson Georgia Institute of Technology Oct 2010 Working with ranges in pictures.
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.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 11 Fall 2010.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
1 CS 177 Week 5 Recitation Slides Mirroring and copying images, Using for Loop, if statement, and range.
Chapter 4: Modifying Pixels in a Range (partial slide deck)
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
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.
Chapter 5: Advanced Picture Techniques (partial deck)
Photo Story Creating your own!. What is Photo Story? Photo Story is a way to create slideshows with added narration, effects, transitions and background.
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
CSC1401 Using Decisions in Java - 1. Recall from Alice We only wanted to shoot a lightning bolt at a philosopher So, we used the If statement.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
CS1315: Introduction to Media Computation Transforming pictures by index number.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 2 Barb Ericson Georgia Institute of Technology August 2005.
ITEC2110, Digital Media Chapter 2 Fundamentals of Digital Imaging 1 GGC -- ITEC Digital Media.
CS 101: Introduction to Computing Referencing pixels directly by index number Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified.
translations, rotations, and reflections
Chapter 5: Picture Techniques with Selection
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Week 2.
Lab 9 Intro to Robots.
Workshop for Programming And Systems Management Teachers
Georgia Institute of Technology
Working with ranges in pictures
Chapter 7: Modifying Samples in a Range
Barb Ericson Georgia Institute of Technology August 2005
Workshop for Programming And Systems Management Teachers
CS1315: Introduction to Media Computation
CSE 8A Lecture 6 Reading for next class:
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Chapter 4: Modifying Pixels in a Range
Introduction to Media Computation
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Two-Dimensional Arrays and Nested Loops – part 2
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
CS 177 Week 3 Recitation Slides
CS 101: Introduction to Computing
CS1315: Introduction to Media Computation
Barb Ericson Georgia Institute of Technology May 2006
CS1315: Introduction to Media Computation
Chapter 4: Modifying Pixels in a Range
Multimedia Summer Camp
CS1315: Introduction to Media Computation
CSC1401 Manipulating Pictures 2
you get to solve puzzles!
Presentation transcript:

CS1315: Introduction to Media Computation More referencing pixels directly by index number: Red eye and mirroring If there’s time, a fun thing to do here is to take any picture the students’ want and do the image manipulation that they suggest to it: Turning blue eyes brown; turning a smile purple, turning hair gray, whatever. It’s fun and relevant.

Removing “Red Eye” When the flash of the camera catches the eye just right (especially with light colored eyes), we get bounce back from the back of the retina. This results in “red eye” We can replace the “red” with a color of our choosing. First, we figure out where the eyes are (x,y) using MediaTools

Removing Red Eye def removeRedEye(pic, startX, startY, endX, endY, replacementColor): red = makeColor(255,0,0) for x in range(startX, endX): for y in range(startY, endY): currentPixel = getPixel(pic, x, y) if (distance(red, getColor(currentPixel)) < 165): setColor(currentPixel, replacementColor) Why use a range? Because we don’t want to replace her red dress! What we’re doing here: Within the rectangle of pixels (startX, startY) to (endX, endY) Find pixels close to red, then replace them with a new color replacementColor

“Fixing” it: Changing red to black removeRedEye(jenny, 109, 91, 202, 107, makeColor(0,0,0)) Jenny’s eyes are actually not black could fix that Eye are also not mono-color A better function would handle gradations of red and replace with gradations of the correct eye color Let’s try it! Who’s got red eyes?

If you know where the pixels are: Mirroring Imagine a mirror horizontally across the picture, or vertically What would we see? How do generate that digitally? We simply copy the colors of pixels from one place to another

Mirroring a picture Slicing a picture down the middle and sticking a mirror on the slice Do it by using a loop to measure a difference The index variable is actually measuring distance from the mirrorpoint Then reference to either side of the mirrorpoint using the difference

Recipe for mirroring def mirrorVertical(source): mirrorpoint = int(getWidth(source) / 2) for y in range(1, getHeight(source)): for xOffset in range(1, mirrorpoint): pright = getPixel(source, xOffset + mirrorpoint, y) pleft = getPixel(source, mirrorpoint - xOffset, y) c = getColor(pleft) setColor(pright, c)

How does it work? Compute the half-way horizontal index The y value travels the height of the picture The xOffset value is an offset It’s not actually an index It’s the amount to add or subtract We copy the color at mirrorpoint-offset to mirrorpoint+offset def mirrorVertical(source): mirrorpoint = int(getWidth(source) / 2) for y in range(1, getHeight(source)): for xOffset in range(1, mirrorpoint): pright = getPixel(source, xOffset + mirrorpoint, y) pleft = getPixel(source, mirrorpoint - xOffset, y) c = getColor(pleft) setColor(pright, c)

Can we do this with a horizontal mirror? def mirrorHorizontal(source): mirrorpoint = int(getHeight(source) / 2) for yOffset in range(1, mirrorpoint): for x in range(1, getWidth(source)): pbottom = getPixel(source, x, yOffset + mirrorpoint) ptop = getPixel(source, x , mirrorpoint - yOffset) setColor(pbottom, getColor(ptop))

Of course!

What if we wanted to copy bottom to top? Very simple: Swap the order of pixels in the bottom line def mirrorHorizontal(source): mirrorpoint = int(getHeight(source) / 2) for yOffset in range(1, mirrorpoint): for x in range(1, getWidth(source)): pbottom = getPixel(source, x, yOffset + mirrorpoint) ptop = getPixel(source, x , mirrorpoint - yOffset) setColor(ptop, getColor(pbottom)) Set color this way, instead of this setColor(pbottom, getColor(ptop))

Messing with Santa some more

Doing something useful with mirroring Mirroring can be used to create interesting effects, but it can also be used to create realistic effects. Consider this image that M.G. took on a trip to Athens, Greece. Can we “repair” the temple by mirroring the complete part onto the broken part?

Figuring out where to mirror Use MediaTools to find the mirror point and the range that we want to copy

Writing functions for specific files…generally The function to mirror the temple needs to work for one and only one file. But we still don’t want to write out the whole path. setMediaPath() allows us to pick a directory where our media will be stored. getMediaPath(filename) will generate the entire path for us to the filename in the media directory THIS ONLY WORKS WHEN WE’RE ACCESSING FILES IN THE MEDIA DIRECTORY AND WHERE WE HAVE SET THE PATH FIRST!

Program to mirror the temple def mirrorTemple(): source = makePicture(getMediaPath("temple.jpg")) mirrorpoint = 277 lengthToCopy = mirrorpoint - 14 for x in range(1, lengthToCopy): for y in range(28, 98): p1 = getPixel(source, mirrorpoint - x, y) p2 = getPixel(source, mirrorpoint + x, y) setColor(p2, getColor(p1)) show(source) return source

Did it really work? It clearly did the mirroring, but that doesn’t create a 100% realistic image. Check out the shadows: Which direction is the sun coming from?