CS 101: Introduction to Computing Rotating and Blurring Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan,

Slides:



Advertisements
Similar presentations
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
Advertisements

Providing a Context to Motivate Non- Majors Into Computing Mark Guzdial College of Computing/GVU Georgia Institute of Technology.
Created by Mark Guzdial, Georgia Institute of Technology; modified by Robert H. Sloan, University of Illinois at Chicago, For Educational Use. CS.
Sound, Part 2 Using range to manipulate samples by index number.
1 CS 177 Week 6 Recitation Slides Scaling Drawing on images Vector-based Vs. Bitmap graphical representation.
CS 102 Computers In Context (Multimedia)‏ 04 / 01 / 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.
CS 1 with Robots Image Manipulation Institute for Personal Robots in Education (IPRE)‏
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.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 5: Advanced Picture Techniques.
Computer Science 101 Introduction to Programming with Pictures.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 7: Modifying Samples in a Range.
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.
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.
CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan.
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.”
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
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):
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.
CS 101: Introduction to Computing Color replacements and targeted color replacement (if statement) Developed by Mark Guzdial, Georgia Institute of Technology,
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.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Chapter 5: Advanced Picture Techniques. Chapter Objectives.
“But it looks right”: Bugs in non-majors media programs Mark Guzdial College of Computing/GVU Georgia Institute of Technology.
Chapter 8: Modifying Samples in a Range. Chapter Objectives.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Chapter 6: Modifying Pixels by Position
CS 101: Introduction to Computing Programs that change Pictures Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert.
CSC 112Introduction to Media Computation 1 Rotating Images.
Lecture 13: Raster Graphics and Scan Conversion
CS1315: Introduction to Media Computation Transforming pictures by index number.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 4 Barb Ericson Georgia Institute of Technology August 2005.
CS 101: Introduction to Computing Referencing pixels directly by index number Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified.
Test 2 on Wed, 11/9 On image processing
Chapter 5: Picture Techniques with Selection
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Image Processing & Perception
Picture Functions ppp =makePicture(pickAFile())
Lab 9 Intro to Robots.
Chapter 8: Making Sounds by Combining Pieces
Working with ranges in pictures
Two-Dimensional Arrays and Nested Loops – part 5
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Chapter 4: Modifying Pixels in a Range
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Two-Dimensional Arrays and Nested Loops – part 3
Two-Dimensional Arrays and Nested Loops – part 6
Two-Dimensional Arrays and Nested Loops – part 6
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
CSC1401 Viewing a picture as a 2D image - 2
Two-Dimensional Arrays and Nested Loops – part 6
CS 177 Week 9 Recitation Slides
CS 101: Introduction to Computing
CS1315: Introduction to Media Computation
Processing Sound Ranges part 3
Chapter 4: Modifying Pixels in a Range
Presentation transcript:

CS 101: Introduction to Computing Rotating and Blurring Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan, University of Illinois at Chicago, 2005, for educational use.

Rotating the copy def copyTonksSideways(): # Set up the source and target pictures tonksFile=getMediaPath("tonks.jpg") tonks = makePicture(tonksFile) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the actual copying--swap X & Y! targetX = 1 for sourceX in range(1,getWidth(tonks)): targetY = 1 for sourceY in range(1,getHeight(tonks)): color = getColor(getPixel(tonks,sourceX,sourceY)) setColor(getPixel(canvas, targetY, targetX), color) targetY = targetY + 1 targetX = targetX + 1 show(tonks) show(canvas) return canvas

Rotating: How it works We increment the same, but we use targetX for the Y coordinate and targetY for the X coordinate

Rotating: How it works 2 We increment sourceY and targetY just the same.

Rotate: How it ends Same amount of increment, even same values in the variables, but a different result.

What to do about scaling? How do we clear up the degradation of scaling up? Variety of techniques, but mostly following the same basic idea:  Use the pixels around to figure out what color a new pixel should be, then somehow (e.g., by averaging) compute the right color.  Different techniques look at different pixels and compute different averages in different ways.

A blurring program Need to go to JES and look at this and ask lots of questions about it. def blur(pic,nNeighbors): original = makeDuplicate(pic) for pixel in getPixels(pic): currentX = getX(pixel) currentY = getY(pixel) r = 0 g = 0 b = 0 count = 0 for x in range(currentX - nNeighbors, currentX + nNeighbors +1): for y in range(currentY - nNeighbors, currentY + nNeighbors + 1): if (x = getWidth(pic)) or (y >= getHeight(pic)): pass # Skip if we go off the edge else: r = r + getRed(getPixel(original, x, y)) g = g + getGreen(getPixel(original, x, y)) b = b + getBlue(getPixel(original, x, y)) count = count + 1 newColor = makeColor(r/count,g/count,b/count) setColor(pixel,newColor) def makeDuplicate(pic): #creates new picture object identical to old and returns it duplicate = makeEmptyPicture(getWidth(pic), getHeight(pic)) for x in range(1, getWidth(pic)): for y in range(1,getHeight(pic)): color = getColor(getPixel(pic, x, y)) setColor(getPixel(duplicate, x, y), color) return duplicate

Bean: Pixelated, then smooth

Questions about Blur What’s with the + 1 at the end of the range? Explain construct else: and pass Explain exact test in the if for when to pass Explain why we need makeDuplicate!