Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.

Slides:



Advertisements
Similar presentations
Introduction to Computing CS A109. Course Objectives Goal is to teach computation in terms relevant to non-CS majors Students will be able to read, understand,
Advertisements

+ Introduction to Programming My first red-eye removal.
CS1315: Introduction to Media Computation Making sense of functions.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
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.
Computer Science 111 Fundamentals of Programming I More Digital Image Processing.
ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1.
Digital Image Manipulation UCA
Python: Making colors and Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
01-IntroToMediaComp1 Barb Ericson Georgia Institute of Technology Oct 2010 Introduction to Computer Science and Media Computation.
CS 102 Computers In Context (Multimedia)‏ 02 / 06 / 2009 Instructor: Michael Eckmann.
CS 102 Computers In Context (Multimedia)‏ 02 / 18 / 2009 Instructor: Michael Eckmann.
Programming: Part II In this section of notes you will learn more advanced programming concepts such as branching and repetition as well as how to work.
James Tam Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions.
CSC 160 Computer Programming for Non-Majors Section 1.2: Drawing a UFO Prof. Adam M. Wittenstein
CS 102 Computers In Context (Multimedia)‏ 02 / 25 / 2009 Instructor: Michael Eckmann.
Persistence of Vision What makes movies work is yet another limitation of our visual system: Persistence of vision We do not see every change that happens.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 3: Modifying Pictures using Loops.
Graphics in Python using the JES environment
Computer Science 101 Introduction to Programming with Pictures.
+ Introduction to Programming My first red-eye removal.
Python.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
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”
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
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.
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.
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.
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.
Creating a picture in JES Use in the command window of JES (black background at bottom) to set the folder where the picture is to be saved >>> path = setMediaPath()
CS 102 Computers In Context (Multimedia)‏ 02 / 09 / 2009 Instructor: Michael Eckmann.
Python Programming in Context Chapter 6. Objectives To understand pixel based image processing To use nested iteration To use and understand tuples To.
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.
CS1315: Introduction to Media Computation Introduction to Programming.
CS1315: Introduction to Media Computation Transforming pictures by index number.
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.
Python programming Using the JES picture functions and defining new functions.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Test 2 on Wed, 11/9 On image processing
Multimedia Summer Camp
Python/JES JES IDE (Integrated Development Environment)
Download JES Tool JES: Jython Environment for Students
Week 2.
Picture Functions ppp =makePicture(pickAFile())
Download JES Tool JES: Jython Environment for Students
Test 2 on Wed, 11/9 On image processing
Chapter 3: Modifying Pictures using Loops
Chapter 3: Modifying Pictures using Loops
Agenda – 1/31/18 Questions? Group practice problems
Practice with loops! What is the output of each function below?
A Media Computation Cookbook
Python Practice !!!.
Manipulating Pictures, Arrays, and Loops
CS 177 Week 3 Recitation Slides
Chapter 3: Modifying Pictures using Loops
CS1315: Introduction to Media Computation
Presentation transcript:

Python: Modifying Pictures Using Loops

Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function should do. JES Functions for file manipulation JES->Files JES Functions for interacting with user JES-->Input/Output JES Functions for picture manipulation JES-->Pictures

Reminder: Manipulating Pictures >>> pic1 = makeEmptyPicture(200,100) >>> show(pic1) >>> setAllPixelsToAColor(pic1, red) >>> show(pic1) >>> addText(pic1,30,50,“hello") similarly can add rectangles, lines, etc.

Reminder: Common errors >>> file = pickAFile() >>> pic = makePicture(file) >>> show(file) The error was:sample Name not found globally. A local or global name could not be found. You need to define the function or variable before you try to use it in any way. >>> show(pic) >>> print pic Picture, filename C:\Documents and Settings\mpapalas\Desktop\sample.jpg height 1200 width 1600 Oops!

Making new Colors Some names for common colors are predefined – try using the names: yellow, black, white, etc. makeColor() takes red, green, and blue values (in that order) between 0 and 255, and returns a Color object pickAColor() lets you use a color chooser and returns the chosen color

Color:(108,86,142) Position: (12,9) x = 12 y = 9 red=108green=86blue=142

Encoding RGB Colors go from (0,0,0) to (255,255,255) >>> pic2 = makeEmptyPicture(200,100) >>> show(pic2) >>> seafoam = makeColor(153, 255, 204) >>> setAllPixelsToAColor(pic2, seafoam ) >>> show(pic2)

Manipulating pixels getPixel(picture,x,y) gets a single pixel. getPixels(picture) gets all of them in an array

Color:(108,86,142) Position: (12,9) x = 12 y = 9 red=108green=86blue=142 >>> pixel=getPixel(picture,12,9) >>> print pixel Pixel, red=108 green=86 blue=142 >>> allThePixels=getPixels(picture) >>> print allThePixels[0] Pixel red=191 green=149 blue=120

What can we do with a pixel? getRed(), getGreen(), and getBlue() are functions that take a pixel as input and return a value between 0 and 255 setRed(), setGreen(), and setBlue() are functions that take a pixel as input and a value between 0 and 255

We can also get, set, and modify Colors getColor() takes a pixel as input and returns a Color object with the color at that pixel setColor() takes a pixel as input and a Color, then sets the pixel to that color We also have functions that can makeLighter() and makeDarker() an input color Last time we saw that we can also create colors: –makeColor() takes red, green, and blue values (in that order) between 0 and 255, and returns a Color object –pickAColor() lets you use a color chooser and returns the chosen color

Demonstrating: Manipulating Colors >>> 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 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= pickAFile() >>> 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)

Media Tools JES Picture function OR Media Tools menu How do you find out what RGB values you have? And where?

Repeating an action for all the pixels in a picture Example: for p in getPixels(picture): value = getRed(p) setRed(p, value*0.5)

Repeating an action for all the pixels in a picture decreaseRed() Example: def decreaseRed(picture): for p in getPixels(picture): value = getRed(p) setRed(p, value*0.5)

More examples: decreaseGreen() decreaseBlue() clearBlue() lighten() darken() negative() grayScale()

Saving to a file setMediaPath(): Prompts the user to pick a folder on the computer. JES then will look for files in that directory unless given a full path, i.e. one that starts with "c:\" writePictureTo(picture, path): picture: the picture you want to be written out to a file path: the path to the file you want the picture written to Takes a picture and a file name (string) as input, then writes the picture to the file as a JPEG. Example: writePictureTo(pic, “mypic.jpg”)

Assignment Create picture manipulation functions that do the following: 1.Decrease red by 10% 2.Decrease green by 10% 3.Decrease blue by 10% 4.Make the picture darker by decreasing red, green, and blue by 10% 5.Make a grayscale version of the image and then negate it (B/W negative)

Next time: Repetition Conditionals Lists Menu-driven program

Repetition for number in range(0,N): pic =.... filename = “pic” + str(number) writePictureTo(pic, filename)

Conditionals if age < 18: showInformation(“Sorry, not allowed to vote yet.”) else: showInformation(“Please select candidate.”)

Lists [“hi”, “hello”, “howdy”, “hiya”, “yo”] [10, 23, 15] [] range(0,6) range(1,4) range(3,8)

Preview of next assignment Create a menu-driven picture manipulation program that allows the user to make various changes to images. Here is the algorithm: welcome the user to your program get the user to select a picture to work on show(picture) ask the user to select an option from a list of numbers: –reduce red –reduce green –reduce blue –posterize –grayscale – repaint(picture) ask user whether to save the picture work, and if the response is “yes”, save it show goodbye/thank you message