CS 177 Week 3 Recitation Slides

Slides:



Advertisements
Similar presentations
CS2984: Introduction to Media Computation Drawing directly on images.
Advertisements

Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
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.
ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
CS1315: Introduction to Media Computation Introduction to Programming.
Created by Mark Guzdial, Georgia Institute of Technology; modified by Robert H. Sloan, University of Illinois at Chicago, For Educational Use. CS.
Python: Making colors and Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Chapter 2: Introduction to Programming. Chapter Learning Objectives.
01-IntroToMediaComp1 Barb Ericson Georgia Institute of Technology Oct 2010 Introduction to Computer Science and Media Computation.
CS 102 Computers In Context (Multimedia)‏ 02 / 18 / 2009 Instructor: Michael Eckmann.
James Tam Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions.
CS 102 Computers In Context (Multimedia)‏ 02 / 25 / 2009 Instructor: Michael Eckmann.
CSE 113 Week 5 February , Announcements  Module 2 due 2/15  Exam 3 is on 2/15  Module 3 due 2/22  Exam 4 is on 2/25  Module 4 due 2/29.
CS 177 Programming with Multimedia Objects Recitation.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
+ Introduction to Programming My first red-eye removal.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Download JES Tool JES: Jython Environment for Students
Python programming Introduction to the JES environment and basics of Python Reading: Chapters 1, 2 from “Introduction to Computing and Programming in Python”
CS1315: Introduction to Media Computation Referencing pixels directly by index number.
Jeopardy Heading1Heading2Heading3Heading4 Heading5 Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
CS1315: Introduction to Media Computation Introduction to Programming.
CS1315: Introduction to Media Computation Making sense of functions.
CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
01-IntroToMediaComp1 Barb Ericson Georgia Institute of Technology Feb 2010 Introduction to Computer Science and Media Computation.
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
Chapter 3: Modifying Pictures using Loops. Chapter Learning Objectives.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Changing colors in an area Part 3: Chromakey.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
1 CS 177 Week 2 Recitation Slides Variables, Files and Functions.
CS1315: Introduction to Media Computation Introduction to JES.
CS1315: Introduction to Media Computation Introduction to Programming.
Python: Working with pixels. Reminder: Conditionals if age < 18: showInformation(“Sorry, not allowed to vote yet.”) else: showInformation(“Please select.
1 CS 177 Week 7 Recitation Slides Modifying Sounds using Loops + Discussion of some Exam Questions.
CS1315: Introduction to Media Computation Introduction to JES.
1 CS 177 Week 4 Recitation Slides for Loop if statement and range.
CS 101: Introduction to Computing Referencing pixels directly by index number Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified.
Multimedia Summer Camp
Image Processing Objectives To understand pixel based image processing
David Meredith Aalborg University
Python/JES JES IDE (Integrated Development Environment)
Chapter 4: Modifying Pictures using Loops
Manipulating Pictures, Arrays, and Loops part 2
Image Processing CS177.
Multimedia Summer Camp
CS1315: Introduction to Media Computation
Download JES Tool JES: Jython Environment for Students
Chapter 2: Introduction to Programming
CS320n –Visual Programming
Manipulating Pictures, Arrays, and Loops part 2
Chapter 2: Introduction to Programming
Chapter 4: Modifying Pictures using Loops
Chapter 3: Modifying Pictures using Loops
CS1315: Introduction to Media Computation
Chapter 3: Modifying Pictures using Loops
Agenda – 1/31/18 Questions? Group practice problems
A Media Computation Cookbook
Chapter 3: Modifying Pictures using Loops
CSIS110 - Introduction to Computer Science
CS1315: Introduction to Media Computation
Manipulating Pictures, Arrays, and Loops
CS1315: Introduction to Media Computation
CSC1401 Manipulating Pictures 2
CSIS110 - Introduction to Computer Science
Presentation transcript:

CS 177 Week 3 Recitation Slides Pictures, Pixels, Colors and for Loop Look at 1-fridayMix slides

Announcements

ANY QUESTIONS?

Reminder: Why digitize media? Real media is analogue (continuous). To digitize it, we break it into parts and encode them into numbers. By encoding them, we can more easily manipulate them, store them, transmit them without error, etc. 4

Digitization of Pictures We digitize pictures into lots of little dots Enough dots and it looks like a continuous whole to our eye Our eye has limited resolution Each little dot (picture element) is referred to as a pixel 5

We already saw how to display a picture in JES myFile = pickAFile() myPicture = makePicture(myFile) show(myPicture)

Now, let’s see how a picture is represented in JES A Picture is a matrix of pixels Row: width Column: height Pixels are picture elements Each pixel object knows its color It also knows where it is in its picture

Encoding Colors with RGB Model Each pixel encodes the color at that position in the picture How we represent a color? We use RGB model to encode colors in computers. RGB: Red, Green, Blue.

RGB Color Model Each component color (red, green, and blue) is encoded as a single byte Colors go from (0,0,0) black to (255,255,255) white

Encoding RGB: Bits and Patterns General rule: In n bits, we can have 2n patterns In 8 bits, we can have 28 patterns, or 256 If we make the first pattern 0, then the highest value we can represent is 28-1, or 255 We’re representing color in 24 (3 * 8) bits.

Reminder: how to show pictures >>> file=pickAFile() >>> print file /Users/guzdial/mediasources/barbara.jpg >>> picture=makePicture(file) >>> show(picture) >>> print picture Picture, filename /Users/guzdial/mediasources/barbara.jpg height 294 width 222 Picture is a Python (JES) object Picture is a matrix of 294 rows x 222 colums Each element of a matrix contains a pxel

Exploring the pixels of a picture.. You can use the picture tool of JES to see the color of a picture pixel….

Manipulating Pixels or you can use a Python command to: get a single pixel at given x,y position getPixel(picture,x,y) get all the pixels into an array getPixels(picture) How to do it STEP 1: write your function in the JES edit area 13 13

What can we do with a pixel? Once you got a pixel, you can get its color components: getRed, getGreen, and getBlue Input: a pixel Output: a value between 0 and 255 Or you can change one of its color components: setRed, setGreen, and setBlue Step 2: save your function in a file

What can we do with a color? getColor: Input: a pixel Output: a Color object with the color at that pixel setColor: Input: a pixel and a Color Output: a pixel with the color set makeColor: Input: red, green, and blue values (in that order) between 0 and 255 Output: a Color object pickAColor lets you use a color chooser and returns the chosen color We also have functions that can makeLighter and makeDarker an input color Step 2: save your function in a file 15 15

Examples: Manipulating Colors Let’s see some examples… Demo You must give a name to your file

Change Pixels Directly … >>> setColor(getPixel(pict,10,100),yellow) >>> setColor(getPixel(pict,11,100),yellow) >>> setColor(getPixel(pict,12,100),yellow) >>> setColor(getPixel(pict,13,100),yellow) >>> … What if we want to change millions of pixels? Better way? … Use a loop. Step 3: load your function in main memory so as JES can execute it

Example of a for Loop def decreaseRed(picture): for p in getPixels(picture): value=getRed(p) setRed(p,value*0.5) Let’s see an example… Demo

Rules of for Loops Command name: for An index variable p is used to hold each of the different values of a sequence The word in A Python function that generates a sequence The index variable will be the name for one value in the sequence, each time through the loop A colon (“:”) And a block (the indented lines of code)

How a for Loop Works The index variable is set to an item in the sequence The block is executed The variable is often used inside the block Then execution loops to the for statement, where the index variable gets set to the next item in the sequence Repeat until every value in the sequence was used.

Using the loop in our Egg Omelette recipe … One Egg Omelette recipe: Put oil in pan Pre-heat pan Crack an egg into bowl Add Salt Wisk the contents of bowl Pour contents of bowl into pan Wait for 3 minutes

Using the loop in our Egg Omelette recipe… Four Egg Omelettes recipe: Put oil in pan Pre-heat pan Crack an egg into bowl Add Salt Wisk the contents of bowl Pour contents of bowl into pan Wait for 3 minutes Repeat the above procedure again for the second egg omelette Repeat the above procedure again for the third egg omelette Repeat the above procedure again for the fourth egg omelette

Final QUESTIONS???