A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.

Slides:



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

CS2984: Introduction to Media Computation Drawing directly on images.
Speed CS A109. Big speed differences Many of the techniques we’ve learned take no time at all in other applications Select a figure in Word. –It’s automatically.
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Computer Science 111 Fundamentals of Programming I More Digital Image Processing.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
 Caesar used to encrypt his messages using a very simple algorithm, which could be easily decrypted if you know the key.  He would take each letter.
CS 102 Computers In Context (Multimedia)‏ 02 / 06 / 2009 Instructor: Michael Eckmann.
CS 102 Computers In Context (Multimedia)‏ 02 / 18 / 2009 Instructor: Michael Eckmann.
1 CS 177 Week 6 Recitation Slides Scaling Drawing on images Vector-based Vs. Bitmap graphical representation.
James Tam Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions.
CS 102 Computers In Context (Multimedia)‏ 02 / 25 / 2009 Instructor: Michael Eckmann.
Some Utility Functions If you know the name of the file, searching for it with pickAFile() feels tedious You can set and get a media folder (path) for.
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
Persistence of Vision What makes movies work is yet another limitation of our visual system: Persistence of vision We do not see every change that happens.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
CSE 8A Lecture 8 Reading for next class: None Prepare for In-term exam 2 PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)
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.
Alice and Media Computation: Goals for this session Show interesting things you can do combining Alice and Media Computation. Provides a story-telling.
How to use the Java class libraries Brief documentation of how to do this all with Java.
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.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
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.
Jeopardy Heading1Heading2Heading3Heading4 Heading5 Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
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.
CS 101: Introduction to Computing Rotating and Blurring Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan,
Chapter 4: Modifying Pixels in a Range (partial slide deck)
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.
NestedLoops-part41 Nested Loops – part 4 Barb Ericson Georgia Institute of Technology Nov 2009.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Creating a picture in JES Use in the command window of JES (black background at bottom) to set the folder where the picture is to be saved >>> path = setMediaPath()
CS 102 Computers In Context (Multimedia)‏ 02 / 09 / 2009 Instructor: Michael Eckmann.
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
Yet Another Version. More Careful Edge Detection def lineDetect(filename): orig = makePicture(filename) makeBw = makePicture(filename) for x in range(0,getWidth(orig)-1):
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.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
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 4 Barb Ericson Georgia Institute of Technology August 2005.
Test 2 on Wed, 11/9 On image processing
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Barb Ericson Georgia Institute of Technology Dec 2009
Picture Functions ppp =makePicture(pickAFile())
CS1315: Introduction to Media Computation
Workshop for Programming And Systems Management Teachers
A Media Computation Cookbook
Test 2 on Wed, 11/9 On image processing
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Creating and Modifying Movies
Two-Dimensional Arrays and Nested Loops – part 4
FUNCTION PRACTICE !!!.
Python Practice !!!.
Two-Dimensional Arrays and Nested Loops – part 6
CSC1401 Viewing a picture as a 2D image - 2
Two-Dimensional Arrays and Nested Loops – part 6
CS 101: Introduction to Computing
CS1315: Introduction to Media Computation
Presentation transcript:

A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing colors in an area Part 3: Chromakey for digital video effects Part 4: Manipulated Alice images Part 5: Sound manipulations Part 6: Manipulated sounds in Alice

Questions being answered here today How do we make it easier to build new things? How do we make it easy to write a program to access specific pictures? How do we change the size of a picture? How do grab part of a picture? How do you combine parts of pictures? How do we use programming to replace re- typing code? How do we replace the background of a picture with something else?

How do we make it easier to build new things? Don’t start from scratch! Use the old file and add more to it. When you start JES, open up the file that you used last time. ◦ If you end your file name with “.py” you can figure out which are Python files. Type more code into that file. If you want, you can download my myfunctions.py from

How do we make it easy to write a program to access certain pictures? setMediaPath() ◦ Type this in the Command Area (black area at bottom of JES) and find the folder where you store your pictures. ◦ (Could be the Desktop, probably better to use a particular folder. I call mine “mediasources”.) makePicture(getMediaPath(“IMG_0810.JPG”)) ◦ Will make a picture from that file in the “media path” folder.

How do we change the size of a picture? To copy a picture, get the color values from pixels in one picture, and set those color values in the pixels in the other picture. def copyPicture(picture): returnPicture = makeEmptyPicture(getWidth(picture),getHeight(picture)) for pixel in getPixels(picture): color = getColor(pixel) setColor(getPixel(returnPicture,getX(pixel),getY(pixel)),returnPicture) return returnPicture

To scale the picture smaller = scale(picture,0.5) How does it work? ◦ To get it to be only ½ the size (in both horizontal and vertical) directions, we need to lose some pixels. ◦ Easiest way: Skip a few. Every other pixel gets copied. ◦ Can generalize this for any size scaling.

Code to scale def scale(picture,factor): newHeight = int(factor*getHeight(picture))+1 newWidth = int(factor*getWidth(picture))+1 returnPic = makeEmptyPicture(int(newWidth),int(newHeight)) sx = 0 for tx in range(0,newWidth): sy = 0 for ty in range(0,newHeight): if (int(sx) < getWidth(picture)) and (int(sy) < getHeight(picture)): sp = getPixel(picture,int(sx),int(sy)) tp = getPixel(returnPic,tx,ty) setColor(tp,getColor(sp)) sy = sy + (1/factor) sx = sx + (1/factor) return returnPic

How do we grab part of a picture? guys = makePicture(getMediaPath("IMG_0805.JPG")) james = copyPartPicture(guys,352,217,618,475) copyPartPicture(picture,startX,startY,endX,endY) ◦ Gives you a new picture inside the box defined by upper-left corner and lower-right corner.

Code to grab part of a picture def copyPartPicture(picture,x1,y1,x2,y2): returnPicture = makeEmptyPicture(x2-x1,y2-y1) targetx = 0 for srcx in range(x1,x2): targety = 0 for srcy in range(y1,y2): srcpixel = getPixel(picture,srcx,srcy) targetPixel = getPixel(returnPicture,targetx,targety) setColor(targetPixel,getColor(srcpixel)) targety = targety + 1 targetx = targetx + 1 return returnPicture

How do we combine parts of a picture? grayscale(betsy) clearRed(james) pastePicture(betsy,scale(james,0.35),0,0) pastePicture(canvas,partial,startX,startY) ◦ Pasting “partial” picture onto the “canvas” starting from (startX,startY)

Code to paste a picture def pastePicture(canvas,source,startx,starty): targetx = startx for x in range(0,getWidth(source)): targety = starty for y in range(0,getHeight(source)): srcpixel = getPixel(source,x,y) if (targetx < getWidth(canvas)) and (targety < getHeight(canvas)): targetPixel = getPixel(canvas,targetx,targety) setColor(targetPixel,getColor(srcpixel)) targety = targety + 1 targetx = targetx + 1

How do use programming to replace re-typing code? Building a collage of pictures: def makeACollage(): betsy = makePicture(getMediaPath("IMG_0802.JPG")) hunter = makePicture(getMediaPath("IMG_0808.JPG")) guys = makePicture(getMediaPath("IMG_0805.JPG")) james = copyPartPicture(guys,352,217,618,475) grayscale(betsy) clearRed(james) pastePicture(betsy,scale(james,0.35),0,0) maxBlue(guys) pastePicture(betsy,scale(guys,0.35),450,340) negative(hunter) pastePicture(betsy,scale(hunter,0.35),0,340) writePictureTo(betsy,"C:/collage.jpg")

Result:

How do we replace the background of a picture with something else? Take a picture with a background that is easy to test and isn’t in the foreground. Two examples. Which one do you think will work?

Code to chromakey for any background color def chromakey(picture,background,color,threshold=100.0): for pixel in getPixels(picture): pixelColor = getColor(pixel) if distance(color,pixelColor) < threshold: newColor = getColor(getPixel(background,getX(pixel),getY(pixel))) setColor(pixel,newColor)

Trying to make the yellow background work >>> chromakey(yellowBarb, moon, makeColor(167,159,110)) >>> writePictureTo(yellowBarb, "C:/yellowBarb-th100.jpg") >>> chromakey( yellowBarb, moon, makeColor(167,159,110),50) >>> writePictureTo( yellowBarb, "C:/yellowBarb-th50.jpg") Yellow is too close to Barb’s skin tone to work.

Using the general chromakey form for a blue background >>> chromakey(blueJenny,moon,makeColor(36,62,95))

Doing a specific version of Chromakey Coming up with a test for being “truly blue” def chromakeyBlue(picture,background): for pixel in getPixels(picture): pixelColor = getColor(pixel) if getRed(pixel)<getBlue(pixel) and getGreen(pixel)<getBlue(pixel): newColor = getColor(getPixel(background,getX(pixel),getY(pixel))) setColor(pixel,newColor)

Nicely chromakeyed

Try it! Take your own picture and put it on a new background. Create a collage with various pieces of the pictures we have.