image_manipulation-1

# image_manipulation-1 - Image Manipulation Institute for...

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

CS 1 with Robots Image Manipulation Institute for Personal Robots in Education (IPRE)

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

View Full Document
Aug 29 2007 2 Taking / Saving / Loading a Picture p = takePicture() show(p) savePicture(p, “class.gif”) p2 = loadPicture(“class.gif”) print getWidth(p) print getHeight(p) 256 192
Aug 29 2007 3 Robot Pictures Robot pictures are: 256 pixels wide by 192 pixels high Each pixel is made up of 3 colors: Red, Green, and Blue Colors range in value from 0 – 255 Plus an “Alpha” value we won't use (for now). When you print a picture or a pixel, Python gives you some textual information about the item, but does not give a visual representation. The show(picture) method will display the picture on the screen.

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

View Full Document
Aug 29 2007 4 Colors (R,G,B) Different colors can be made by mixing different values of the primary (Red,Green,Blue) color lights. In computer output, colors are made by adding lights of different colors, and color combinations are additive. For example: (0, 0, 0) – Black (255, 255, 255) – White White (255, 0, 0) – Red (255, 255,0) – Yellow (255, 0, 255) – Magenta / fuchsia (bright purple) (0, 255, 255) – Cyan (bright teal)
Aug 29 2007 5 Accessing a specific pixel: getPixel(picture, x,y) print p pix = getPixel(p, 50,50) print pix setRed(pix,0) setGreen(pix,0) setBlue(pix,0) print pix show(p) <Pixel instance (r=153, g=255, b=255, a=255) at (50, 50)> <Pixel instance (r=0, g=0, b=0, a=255) at (50, 50)> <Picture instance (256 x 192)>

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

View Full Document
Aug 29 2007 6 Zoomed In View: One Black Pixel
Aug 29 2007 7 Looping through all pixels: getPixels( picture ) print p for pix in getPixels(p): setRed(pix,0) setBlue(pix,255) setGreen(pix,255) show(p)

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

View Full Document
Aug 29 2007 8 Looping through all pixels: getPixels( picture ) p = loadPicture(“class.gif”) for pix in getPixels(p): setRed(pix,255) But what if you only change the red part of the pixels?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 29

image_manipulation-1 - Image Manipulation Institute for...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online