{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

06PictureManipulations2009

06PictureManipulations2009 - CS1315 Introduction to Media...

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

View Full Document Right Arrow Icon
CS1315: Introduction to Media Computation Programming picture manipulations
Image of page 1

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

View Full Document Right Arrow Icon
Admin Does everyone have JES 4.2.1 installed now? New version that allows you to save your pictures
Image of page 2
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:
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 4
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…
Image of page 5

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

View Full Document Right Arrow Icon
How do you find out what RGB values you have? And where? Use the MediaTools! (especially useful when testing and debugging…)
Image of page 6
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)
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern