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.

Slides:



Advertisements
Similar presentations
Chessboard problems You don’t have to know chess to solve them.
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.
Computer Science 111 Fundamentals of Programming I More Digital Image Processing.
SuperStar Basics Brian Bruderer. Sequence Editors Traditional sequence editors use a large grid to control when channels are turned on and off. This approach.
Python: Making colors and Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Right-click on the colored box and remove it.
1 CS 177 Week 6 Recitation Slides Scaling Drawing on images Vector-based Vs. Bitmap graphical representation.
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.
Course Outline Lesson1 Getting Started with Adobe Photoshop CS5 Lesson 2 Understanding Photoshop Basics Lesson 3 Saving and Printing Images Lesson 4 Changing.
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.
Javascript & HTML5 Intro. Why Javascript? Next big thing in online games Flash is slowly on its way out Can be coded via any text editor, flash costs.
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.
CSE 8A Lecture 8 Reading for next class: None Prepare for In-term exam 2 PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)
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.
First Courses Workshop Day 1 Mark Guzdial College of Computing Georgia Institute of Technology
UWCSE BRIDGE Workshop Aug. 31 – Sept. 3, 2009 Hal Perkins Computer Science & Engineering University of Washington
Web Design Unit Assignment #2: Job Skills Favorite Links Page You will create a HTML web page with links to informational websites about a variety of job.
Image Processing & Perception Sec 9-11 Web Design.
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.
Image Processing © Copyright William Rowan Objectives By the end of this you will be able to: Manipulate images to achieve special effects.
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.
Warm-up Simplify. 5x x – a + 2b – (a – 2b) Multiply.
Media Computation Workshop Day 1 Mark Guzdial College of Computing Georgia Institute of Technology
Program Design and Debugging. How do programmers start? How do you get started with a program? “Programming is all about debugging a blank piece of paper.”
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.
CS1315: Introduction to Media Computation How to design and debug a program: Top-down, bottom-up, and debugging. Using background subtraction and chromakey.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 5 Barb Ericson Georgia Institute of Technology August 2005.
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()
Yet Another Version. More Careful Edge Detection def lineDetect(filename): orig = makePicture(filename) makeBw = makePicture(filename) for x in range(0,getWidth(orig)-1):
“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
THE ELEMENTS OF ART The Elements are the “WHAT” in a work of art; the Principles are “HOW” they’re used LINESHAPEFORMSPACECOLORVALUETEXTURE.
Click left mouse button to proceed. Windows Tutorial Searching For Files CST-133 Lab AW © Delta College CST Faculty.
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.
Test 2 on Wed, 11/9 On image processing
Chapter 5: Picture Techniques with Selection
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Scratch for Interactivity
Image Processing & Perception
Picture Functions ppp =makePicture(pickAFile())
CS1315: Introduction to Media Computation
Working with ranges in pictures
Test 2 on Wed, 11/9 On image processing
Chapter 4: Modifying Pixels in a Range
Week 3.
Fundamentals of Programming I Introduction to Digital Image Processing
CS 177 Week 3 Recitation Slides
CS 101: Introduction to Computing
CS1315: Introduction to Media Computation
Chapter 4: Modifying Pixels in a Range
Op Art Directions.
Presentation transcript:

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 remembering a place where your media will be coming from (or going to)  setMediaPath() lets you pick a file in your media folder  getMediaPath(basefilename) lets you generate a complete filename out of only the last part

Example >>> setMediaPath() New media folder: C:\mediasources\ >>> getMediaPath("barbara.jpg") 'C:\\mediasources\\barbara.jpg' >>> barb=makePicture(getMediaPath("barbara.jpg"))

Blank files in mediasources file = makeEmptyPicture(100,100) will create a blank picture of size 101x101 (why not 100x100?) DO writePictureTo(file,”100x100.jpg”) to save the blank picture canvas = makePicture(getMediaPath(“100x100.jpg”)) gives you a JPEG canvas of 101x101 pixels

Edge detection Pixel is different from its neighbors => an edge Measure (criterion) of pixel differences ?  One possibility – compare B/W value of a pixel with those at the left and below  If differences are above threshold, then an edge (black), otherwise (white) For each pixel in picture1: get B/W values of the pixel, its left and below (how?) if differences of (pixel, left) and (pixel, below) > Threshold paint the pixel black otherwise, paint the pixel white

Edge detection code def edgeDetect(pic, tHold): wid = getWidht(pic) hgt = getHeight(pic) edge = makeEmptyPicture(wid, hgt) for x in range(1, wid): for y in range(1, hgt): t = getPixel(pic, x, y) l = getPixel(pic, x-1, y) b = getPixel(pic, x, y+1) thisBW = (getRed(t) +getGreen(t)+getBlue(t))/3 leftBW = (getRed(l) +getGreen(l)+getBlue(l))/3 belBW = (getRed(b) +getGreen(b)+getBlue(b))/3 if abs(thisBW-leftBW) > tHold and abs(thisBW-belBW) > tHold: setColor(getPixel(edge, x, y), black) else: setColor(getPixel(edge, x,y), white) show(edge)

Making a collage Could we do something to the pictures we copy in?  Sure! Could either apply one of those functions before copying, or do something to the pixels during the copy. Could we copy more than one picture!  Of course! Make a collage!

Making a collage Given a blank canvas  Copy flower1 at lower left corner of canvas  Copy flower2 next  Copy negated flower1  Copy flower2 with blue removed  Copy flower1, negated and red reduced How do I copy to lower left corner?  Upper left corner is easy  Need to utilize getHeight(canvas) and getHeight(flower1) How do I copy flower2 adjacent to flower1 ?

Copy to lower left corner targetX = sourceX targetY = sourceY + ?  ? : getHeight(canvas) – getHeight(flower1) sourceX sourceY flower1

Copy flower2 targetX = sourceX + getWidth(flower1) targetY = sourceY + ?  ? : getHeight(canvas) – getHeight(flower2) sourceX sourceY flower1flower2

Put them together #First picture, at left edge targetX=1 for sourceX in range(1, getWidth(flower1)): targetY=getHeight(canvas)-getHeight(flower1)-5 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= getWidth(flower1)# 100 for sourceX in range(1,getWidth(flower2)): targetY=getHeight(canvas)-getHeight(flower2)-5 for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px)) targetY=targetY + 1 targetX=targetX + 1

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=getHeight(canvas)-getHeight(flower1)-5 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)): targetY=getHeight(canvas)-getHeight(flower2)-5 for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Third picture, flower1 negated negative(flower1) targetX=200 for sourceX in range(1,getWidth(flower1)): targetY=getHeight(canvas)-getHeight(flower1)-5 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=getHeight(canvas)-getHeight(flower2)-5 for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Fifth picture, flower1, negated with decreased red decreaseRed(flower1) targetX=400 for sourceX in range(1,getWidth(flower1)): targetY=getHeight(canvas)-getHeight(flower1)-5 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 show(canvas) return(canvas)

Making a collage createCollage() too messy Any good way to simplify it ? Go back to what processes were involved => find any pattern to exploit ?  Copy flower1 at lower left corner of canvas  Copy flower2 next  Copy negated flower1  Copy flower2 with blue removed  Copy flower1, negated and red reduced  Sure! Repetition of ‘Copy’ Let us make a general picCopy() function What info do we need for picCopy() ?

LAB: Write picCopy() Write picCopy(fPic,tPic,x,y) function in Program Area, which copies fPic to tPic starting from (x,y) of tPic In Command Area, call picCopy() five times to create a collage on the right You need negate(), clearBlue(), decreaseRed()