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

Slides:



Advertisements
Similar presentations
RAPTOR Syntax and Semantics By Lt Col Schorsch
Advertisements

CS2984: Introduction to Media Computation Drawing directly on images.
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.
Objectives Define photo editing software
James Tam Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Colors – part 3 K1066BI – Graphical Design Teppo Räisänen
1 Internet Graphics. 2 Representing Images  Raster Image: Images consist of “dots” of color, not lines  Pixel: Picture element-tiny rectangle  Resolution:
CompSci Today’s topics Robots Myro Loops Notes from the Institute for Personal Robots in Education Upcoming ä More Python Reading Learning Computing.
Digital Images The digital representation of visual information.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Technology and digital images. Objectives Describe how the characteristics and behaviors of white light allow us to see colored objects. Describe the.
CMYK vs. RGB Design. Primary colors The colors that make up the base for every other color created. Depending on whether you are looking at it from science,
Co mputer Graphics Researched via: Student Name: Nathalie Gresseau Date:12/O7/1O.
Image Processing & Perception Sec 9-11 Web Design.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
Color Correct and Remove Keystoning A minimalist approach to photographing your art By Paul Marley.
CS 101 – Sept. 16 Finish color representation –RGB √ –CMY –HSB –Indexed color Chapter 4 – how computers think –Begin with basic building blocks.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Chapter 6: Modifying Pixels by Position. Chapter Learning Goals.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
CS1315: Introduction to Media Computation Referencing pixels directly by index number.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Color and Resolution Introduction to Digital Imaging.
Pictures Looping through pixels.. Lab Review (1) Objects  Instantiated from Class  Turtle myTut = new Turtle(myWorld);  new operator creates an instance.
CSC Computing with Images
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
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.
# Red Green Blue Digital Color RGB to HEX.
Chapter 5: Advanced Picture Techniques (partial deck)
Ch 6 Color Image processing CS446 Instructor: Nada ALZaben.
Adobe Photoshop CS5 – Illustrated Unit A: Getting Started with Photoshop CS5.
ITEC 109 Multimedia Lecture Lecture 23. Photo manipulation Review Lists / Arrays.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
CS305j Introduction to Computing Simple Graphics 1 Topic 11 Simple Graphics "What makes the situation worse is that the highest level CS course I've ever.
PART TWO Electronic Color & RGB values 1. Electronic Color Computer Monitors: Use light in 3 colors to create images on the screen Monitors use RED, GREEN,
Color.
Python: Working with pixels. Reminder: Conditionals if age < 18: showInformation(“Sorry, not allowed to vote yet.”) else: showInformation(“Please select.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Adobe Photoshop CS4 – Illustrated Unit A: Getting Started with Photoshop CS4.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CS 101: Introduction to Computing Referencing pixels directly by index number Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified.
Getting Started with Adobe Photoshop CS6
Data Representation Images.
Pixels, Colors and Shapes
Adapted from slides by Marty Stepp and Stuart Reges
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Multimedia Summer Camp
Week 2.
Image Processing & Perception
Lab 9 Intro to Robots.
Building Java Programs
CSc 110, Spring 2017 Lecture 6: Parameters (cont.) and Graphics
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Basic Graphics Drawing Shapes 1.
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Looping through pixels.
Two ways to discuss color 1) Addition 2) Subtraction
A Media Computation Cookbook
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
CS 177 Week 3 Recitation Slides
Multimedia Summer Camp
Presentation transcript:

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

Aug Taking / Saving / Loading a Picture p = takePicture()‏ show(p)‏ savePicture(p, “class.gif”)‏ p2 = loadPicture(“class.gif”)‏ print getWidth(p)‏ print getHeight(p)‏

Aug 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.

Aug 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 White (255, 255, 255) – White (255, 0, 0) – Red (255, 255,0) – Yellow (255, 0, 255) – Magenta / fuchsia (bright purple)‏ (0, 255, 255) – Cyan (bright teal)

Aug 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)‏

Aug Zoomed In View: One Black Pixel

Aug Looping through all pixels: getPixels( picture )‏ print p for pix in getPixels(p): setRed(pix,0) setBlue(pix,255)‏ setGreen(pix,255)‏ show(p)‏

Aug 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?

Aug Looping through all pixels: getPixels( picture )‏ p = loadPicture(“class.gif”)‏ for pix in getPixels(p): setRed(pix,255) show(p)‏ The Green and Blue parts of the pixels retain their original information!

Aug Pixel Functions Getting a specific pixel: getPixel(picture,x,y)‏ Getting all pixels: getPixels(picture)‏ Getting information about pixel color: getRed(pixel)‏ getGreen(pixel)‏ getBlue(pixel)‏...and about pixel location: getX(pixel)‏ getY(pixel)‏ Changing color information: setRed(pixel, value)‏ setGreen(pixel,value)‏ setBlue(pixel,value)‏

Aug How to change more than 1 pixel, but less than all? p = loadPicture(“class.gif”)‏ for pix in getPixels(p): x = getX(pix)‏ if(x == 50): setRed(pix,255)‏ setGreen(pix,0)‏ setBlue(pix,0) show(p)‏ You can check each pixel to see if you want to change it!

Aug Drawing a line, quickly! A (robot) picture has 256 x 192 pixels = 49,152 pixels A horizontal line has 256 pixels, and a vertical line has 192 pixels. Code on the previous slide looked at all 49,152 pixels and decided if it should color them red based upon the value of the X coordinate. That's 49,152 calls to getX and 49,152 IF statement checks! No wonder it takes a second to finish!

Aug Drawing a line, quickly! p = loadPicture(“class.gif”)‏ pHeight = getHeight(p)‏ for y in range(pHeight): pix = getPixel(p,50,y)‏ setRed(pix,255)‏ setGreen(pix,0)‏ setBlue(pix,0) show(p)‏ Only work on the pixels you want to change!

Aug Only work with the pixels we want to change! The quick line drawing code only works with 192 pixels! That's only 192 calls to getPixel, and 192 cycles through the loop! It's no surprise that this code runs faster! How would we change it to draw a horizontal line?

Aug Drawing a horizontal line! p = loadPicture(“class.gif”)‏ pHeight = getHeight(p)‏ for y in range(pHeight): pix = getPixel(p,50,y)‏ setRed(pix,255)‏ setGreen(pix,0)‏ setBlue(pix,0) show(p)‏ Change all the code that deals with height, and make it work with width instead!

Aug Drawing a horizontal line p = loadPicture(“class.gif”)‏ pWidth = getWidth(p)‏ for x in range(pWidth): pix = getPixel(p,x,50)‏ setRed(pix,255)‏ setGreen(pix,0)‏ setBlue(pix,0) show(p)‏

Aug Making it more general... p = loadPicture(“class.gif”)‏ pWidth = getWidth(p)‏ for x in range(pWidth): pix = getPixel(p,x,50)‏ setRed(pix,255)‏ setGreen(pix,0)‏ setBlue(pix,0) show(p)‏ Let's turn this code into a function! What do we want to control when drawing a horizontal line? What parameters do we want to send into the function?

Aug H-line function def drawHLine(pic, y, r,g,b): pWidth = getWidth(pic)‏ for x in range(pWidth): pix = getPixel(pic,x,y)‏ setRed(pix,r)‏ setGreen(pix,g)‏ setBlue(pix,b) p = loadPicture(“class.gif”)‏ drawHLine(p, 20, 0, 255,0)‏ show(p)‏

Aug Moving the H-Line We have a function that draws a line. Lets animate the line by drawing it multiple times! Our procedure: Draw the line at the top of the picture Show the picture Draw the line one pixel lower Show the picture again Repeat until the line is at the bottom of the picture!

Aug Moving Horizontal Line p = loadPicture(“class.gif”)‏ y = 0 #Start at the top! while(y < getHeight(p) ): drawHLine(p, y, 255,0,0)‏ show(p)‏ wait(0.05)‏ y = y + 1

Aug Moving Horizontal Line Why didn't that work? How can we fix it?

Aug Saving overwritten data Our drawHLine() function overwrites pixel data. But, it doesn't restore pixel data! To fix it, we could save the pixel data from each line, and then restore it before we draw the next line. Or, we could be lazy, and just save a copy of the entire picture! By drawing our line on a new copy of the picture each time, we ensure that only the line we are drawing now will be red!

Aug Moving Horizontal Line (working on a picture copy)‏ p = loadPicture(“class.gif”)‏ p2 = copyPicture(p)‏ y = 0 #Start at the top! while(y < getHeight(p) ): drawHLine(p2, y, 255,0,0)‏ show(p2)‏ wait(0.05)‏ y = y + 1 p2 = copyPicture(p)‏

Aug Speeding things up? Ok, that works, but it was kinda slow... Did we wait too long? What happens if we change the wait time to zero? How could we speed things up? Buy a faster computer! We could cheat.... By only drawing the line every five lines, it would appear to go down the image faster.

Aug Moving Horizontal Line (every 5 th line)‏ p = loadPicture(“class.gif”)‏ p2 = copyPicture(p)‏ y = 0 #Start at the top! while(y < getHeight(p) ): if (y % 5 == 0): drawHLine(p2, y, 255,0,0)‏ show(p2) wait(0.05)‏ p2 = copyPicture(p)‏ y = y + 1

Aug What else can we do? Draw a rectangle! Copy a rectangle from one picture to another!

Aug Draw a rectangle! p = loadPicture(“class.gif”)‏ for x in range(50,90): for y in range(100,150): pix = getPixel(p,x,y)‏ setRed(pix,255)‏ setGreen(pix,255)‏ setBlue(pix,0)‏ show(p)‏

Aug Double (Nested) for loops! You just saw something that is very useful when working with two dimensional data. By using two for loops, one nested inside of the other, you can iterate two variables (e.g. x & y) over all values within a rectangle! for x in range(startX,endX): for y in range(startY,endY): doSomethingAt( x, y)

Aug Copy a rectangle! p = loadPicture(“class.gif”)‏ p2 = loadPicture(“p3.jpg”)‏ show(p); show(p2)‏ for x in range(30,100): for y in range(60,170): pix = getPixel(p,x,y)‏ pix2 = getPixel(p2,x,y)‏ setRed(pix, getRed(pix2) )‏ setGreen(pix,getGreen(pix2) )‏ setBlue(pix,getBlue(pix2) )‏ show(p)‏