{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

06PictureManipulations2009

# 06PictureManipulations2009 - CS1315 Introduction to Media...

This preview shows pages 1–8. Sign up to view the full content.

CS1315: Introduction to Media Computation Programming picture manipulations

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Admin Does everyone have JES 4.2.1 installed now? New version that allows you to save your pictures
How "close" are two colors? Sometimes you need to find the distance between two colors, e.g., when deciding if something is a "close enough" match How do we measure distance? Pretend it’s Cartesian coordinate system Distance between two points: Distance between two colors:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Demo: Manipulating Colors >>> pixel = getPixel(pic, 1, 1) >>> print getRed(pixel) 168 >>> setRed(pixel, 255) >>> print getRed(pixel) 255 >>> color = getColor(pixel) >>> print color color r=255 g=131 b=105 >>> setColor(pixel, color) >>> newColor = makeColor(0, 100, 0) >>> print newColor color r=0 g=100 b=0 >>> setColor(pixel, newColor) >>> print getColor(pixel) color r=0 g=100 b=0 >>> print color color r=81 g=63 b=51 >>> print newcolor color r=255 g=51 b=51 >>> print distance(color, newcolor) 174.41330224498358 >>> print color color r=168 g=131 b=105 >>> print makeDarker(color) color r=117 g=91 b=73 >>> print color color r=117 g=91 b=73 >>> newcolor = pickAColor() >>> print newcolor color r=255 g=51 b=51
We can change pixels directly… >>> file = "/Users/monica/MediaSources/barbara.jpg" >>> pict = makePicture(file) >>> show(pict) >>> setColor(getPixel(pict, 10, 100), yellow) >>> setColor(getPixel(pict, 11, 100), yellow) >>> setColor(getPixel(pict, 12, 100), yellow) >>> setColor(getPixel(pict, 13, 100), yellow) >>> repaint(pict) But that’s really tedious… Manipulating pictures more cleverly is the next topic…

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
How do you find out what RGB values you have? And where? Use the MediaTools! (especially useful when testing and debugging…)
Use a loop! Our first picture recipe def decreaseRed(picture): for myPixel in getPixels (picture): value = getRed (myPixel) setRed (myPixel, value * 0.5) Used like this: >>> file = pickAFile() >>> picture = makePicture(file) >>> show(picture) >>> decreaseRed(picture) >>> repaint(picture)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern