Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 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 images with Alice Part 5: Sound manipulations Part 6: Manipulated sounds in Alice

2 Review of code used last time print - prints out the value of whatever variable=Something – sets variable equal to the value of Something. pickAFile() – lets you pick a file, and has a value of the filename you pick. makePicture(filename) – takes a filename as input, and has a value of a Picture object. explore(picture) – shows you the picture. getPixels(picture) – gets a list of all pixels in a picture. for – lets you change one pixel at a time from a list of pixels. getRed/setRed, getBlue/setBlue, getGreen/setGreen – gets or sets the color component of a pixel

3 Functions we did last time def decreaseRed(picture): for p in getPixels(picture): value=getRed(p) setRed(p,value*0.5) def decreaseBlue(picture): for p in getPixels(picture): value=getBlue(p) setBlue(p,value*0.7) def maxBlue(picture): for p in getPixels(picture): setBlue(p,255) def decreaseGreen(picture): for p in getPixels(picture): value=getGreen(p) setGreen(p,value*0.7) def clearRed(picture): for p in getPixels(picture): setRed(p,0)

4 Making a negative image def negative(picture): for p in getPixels(picture): r = getRed(p) b = getBlue(p) g = getGreen(p) color = makeColor(255-r, 255-g, 255-b) setColor(p,color) How to use it: >>> picture = makePicture(pickAFile()) >>> negative(picture) >>> writePictureTo(picture,"c:/negativepic.jpg")

5 Some new pieces of code makeColor(redamount, greenamount, blueamount) – makes a new color. setColor(pixel,color) – sets a color of a pixel. getColor(pixel) – has a value of the color of the pixel

6 What happens if…? You do negative twice? You clear out a color (red, green, or blue) and then do the negative? (You can have many explore windows open at once, so you can compare them.)

7 How do you get grayscale? def grayscale(picture): for p in getPixels(picture): r = getRed(p) b = getBlue(p) g = getGreen(p) brightness = ??? color = makeColor(brightness,brightness,brightness) setColor(p,color)

8 Changing just some colors How do we do it? ◦ We have to figure out which pixels to change. ◦ We want pixels that are close to a given color. ◦ We want only those within a certain range

9 What color shirt? Where is it? Y=210 X=220 X=400 >>> shirt = makePicture(pickAFile()) >>> explore(shirt) >>> print shirt Picture, filename C:\mediasources\IMG_0808.JP G height 480 width 640

10 distance() function tells how close colors are >>> print white color r=255 g=255 b=255 >>> print black color r=0 g=0 b=0 >>> print distance(white,black) 441.6729559300637 >>> print red color r=255 g=0 b=0 >>> print pink color r=255 g=175 b=175 >>> print distance(red,pink) 247.48737341529164

11 Changing the whole shirt def changeAllShirt(picture): myGreen = makeColor(132,240,204) for pixel in getPixels(picture): color = getColor(pixel) if distance(color,myGreen) < 200: setColor(pixel,pink)

12 Results

13 Just doing part of the picture, and changing fewer pixels def changeShirt(picture): myGreen = makeColor(132,240,204) for x in range(220,400): for y in range(210,480): pixel = getPixel(picture,x,y) color = getColor(pixel) if distance(color,myGreen) < 50: setColor(pixel,pink)

14 Results

15 Coloring the shirt from a different picture >>> beach = makePicture(pickAFile()) >>> shirt = makePicture(pickAFile())

16 Code to grab other colors def newBackgroundShirt(picture,background): myGreen = makeColor(132,240,204) for x in range(220,400): for y in range(210,480): pixel = getPixel(picture,x,y) color = getColor(pixel) if distance(color,myGreen) < 100: backgroundPixel = getPixel(background,x,y) backgroundColor = getColor(backgroundPixel) setColor(pixel,backgroundColor)

17 Results

18 Try it! Get the shirt to turn pink really well Change something else: ◦ Make a yellow or red shirt different colors ◦ Change the white of someone’s teeth to green Change someone else’s shirt into a different background. Real Challenge: Save a picture from Alice, and then change colors in that picture!


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

Similar presentations


Ads by Google