Picture Functions ppp =makePicture(pickAFile())

Slides:



Advertisements
Similar presentations
CS1315: Introduction to Media Computation Making sense of functions.
Advertisements

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.
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.
CS 102 Computers In Context (Multimedia)‏ 02 / 06 / 2009 Instructor: Michael Eckmann.
CS 102 Computers In Context (Multimedia)‏ 02 / 18 / 2009 Instructor: Michael Eckmann.
1 CS 177 Week 6 Recitation Slides Scaling Drawing on images Vector-based Vs. Bitmap graphical representation.
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.
Some Utility Functions If you know the name of the file, searching for it with pickAFile() feels tedious You can set and get a media folder (path) for.
Tickertape def tickertape(directory,string): for each frame to generate create an new canvas write the string on canvas slightly left of the previous frame.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Copying and Transforming Pictures. First, finding the min or max… Next homework asks you to write a function to find the darkest and lightest shade of.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Computer Science 101 Introduction to Programming with Pictures.
+ Introduction to Programming My first red-eye removal.
UWCSE BRIDGE Workshop Aug. 31 – Sept. 3, 2009 Hal Perkins Computer Science & Engineering University of Washington
How to use the Java class libraries Brief documentation of how to do this all with Java.
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
02-RangesInPictures1 Barb Ericson Georgia Institute of Technology Oct 2010 Working with ranges in pictures.
CS2984: Introduction to Media Computation Using Loops for Pictures Conditionals Copying images.
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 Picture encoding and manipulation.
1 CS 177 Week 5 Recitation Slides Mirroring and copying images, Using for Loop, if statement, and range.
Copying: How it works Here's the initial setup:. Copying: How it works 2 After incrementing the sourceY and targetY once (whether in the for or via expression):
CS 101: Introduction to Computing Rotating and Blurring Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan,
Chapter 4: Modifying Pixels in a Range (partial slide deck)
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
NestedLoops-part41 Nested Loops – part 4 Barb Ericson Georgia Institute of Technology Nov 2009.
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()
Python Programming in Context Chapter 6. Objectives To understand pixel based image processing To use nested iteration To use and understand tuples To.
“But it looks right”: Bugs in non-majors media programs Mark Guzdial College of Computing/GVU Georgia Institute of Technology.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Chapter 6: Modifying Pixels by Position
CSC 112Introduction to Media Computation 1 Rotating Images.
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.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
I MAGE P ROCESSING IN CS1 Brad Miller David Ranum Luther College.
Test 2 on Wed, 11/9 On image processing
Chapter 5: Picture Techniques with Selection
Python/JES JES IDE (Integrated Development Environment)
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Download JES Tool JES: Jython Environment for Students
Week 2.
CS1315: Introduction to Media Computation
Download JES Tool JES: Jython Environment for Students
Workshop for Programming And Systems Management Teachers
Working with ranges in pictures
Test 2 on Wed, 11/9 On image processing
Two-Dimensional Arrays and Nested Loops – part 5
Chapter 4: Modifying Pixels in a Range
Agenda – 1/31/18 Questions? Group practice problems
Week 3.
Two-Dimensional Arrays and Nested Loops – part 4
Two-Dimensional Arrays and Nested Loops – part 3
Two-Dimensional Arrays and Nested Loops – part 6
Two-Dimensional Arrays and Nested Loops – part 6
CS 177 Week 3 Recitation Slides
CSC1401 Viewing a picture as a 2D image - 2
Two-Dimensional Arrays and Nested Loops – part 6
CS 177 Week 9 Recitation Slides
CS1315: Introduction to Media Computation
Chapter 4: Modifying Pixels in a Range
Presentation transcript:

Picture Functions ppp =makePicture(pickAFile()) ppp.getWidth(), ppp.getHeight() xxx=ppp.getPixel( , ) xxx.getColor(), .getRed(), .getGreen(), .getBlue() xxx.setColor(), .setRed(), .setGreen(), .setBlue() makeColor(), pickAColor() setMediaPath() – fix a path to media files getMediaPath(filename) file = makeEmptyPicture(100,100) – creates a blank picture of size 100x100 writePictureTo(file, “100x100.jpg”) – save file with name “100x100.jpg”

Copy to a blank canvas Download www.cs.uml.edu/~kim/100/flower1.jpg and www.cs.uml.edu/~kim/100/flower2.jpg targetX = sourceX targetY = sourceY sourceX sourceY flower1 canvas

Picture Copy Function picCopy() with a picture into a larger canvas Convert the copying operation below to picCopy() and main() pict = makePicture(pickAFile()) # flower1.jpg canvas = makeEmptyPicture(1000,800) hgt = pict.getHeight() wid = pict.getWidth() repaint(canvas) def picCopy(fPic, tPic, fx, fy): return canvas # main() pict = makePicture(pickAFile()) # flower1.jpg canvas = makeEmptyPicture(1000,800) picCopy(pict, canvas, 0, 0) repaint(canvas)

Copy flower2 targetX = sourceX + getWidth(flower1) targetY = sourceY

Making a collage Given a blank canvas Copy flower1 at upper left corner of canvas Copy flower2 next Copy negated flower1 Copy flower2 with blue removed Copy flower1, negated and red reduced

Put them together #First picture, at left edge targetX=1 for sourceX in range(1, getWidth(flower1)): targetY=1 for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY) canvas_x=getPixel(canvas,targetX,targetY) setColor(canvas_x,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Second picture, 100 pixels over targetX= getWidth(flower1) # 100 for sourceX in range(1,getWidth(flower2)): targetY= 1 for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) canvas_x=getPixel(canvas,targetX,targetY) setColor(canvas_x,getColor(px)) targetY=targetY + 1 targetX=targetX + 1

Collage: Code def createCollage(): flower1=makePicture(getMediaPath("flower1.jpg")) print flower1 flower2=makePicture(getMediaPath("flower2.jpg")) print flower2 canvas=makePicture(getMediaPath("640x480.jpg")) print canvas #First picture, at left edge targetX=1 for sourceX in range(1,getWidth(flower1)): targetY=1 for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Second picture, 100 pixels over targetX=100 for sourceX in range(1,getWidth(flower2)): for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) #Third picture, flower1 negated negative(flower1) targetX=200 for sourceX in range(1,getWidth(flower1)): targetY=1 for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Fourth picture, flower2 with no blue clearBlue(flower2) targetX=300 for sourceX in range(1,getWidth(flower2)): targetY= 1 for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) #Fifth picture, flower1, negated with decreased red ……. show(canvas) return(canvas)

General picCopy() If we had a general picCopy(pic, targetPic, targetX, targetY) createCollage() picCopy(flower1, canvas, 0, 0) picCopy(flower2, canvas, getWidth(flower1), 0) picCopy(negate(flower1), canvas, getWidth(flower1) + getWidth(flower2), 0) picCopy(clearBlue(flower2), canvas, getWidth(flower1)*2 + getWidth(flower2), 0) picCopy(reduceRed(negate(flower1)), canvas, getWidth(flower1)*2 + getWidth(flower2)*2, 0)

Encapsulation Once picCopy(pic, targetPic, targetX, targetY) is written View a collage A collection of high-level picture manipulation Don’t worry about the details of negate, reduceRed, etc. In cooking recipe, Do not worry about how wheat is processed into flour, … Encapsulation -> Information Hiding