CSC 112Introduction to Media Computation 1 Rotating Images.

Slides:



Advertisements
Similar presentations
Transformations on the coordinate plane
Advertisements

Providing a Context to Motivate Non- Majors Into Computing Mark Guzdial College of Computing/GVU Georgia Institute of Technology.
Do Now:.
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.
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.
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.
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.
How to use the Java class libraries Brief documentation of how to do this all with Java.
TOPIC 7 MODIFYING PIXELS IN A MATRIX NESTED FOR LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by.
Chapter 6: Modifying Pixels by Position. Chapter Learning Goals.
CSC1401 Viewing a picture as a 2D image - 1. Review from the last week We used a getPixels() to get all of the pixels of a picture But this has been somewhat.
02-RangesInPictures1 Barb Ericson Georgia Institute of Technology Oct 2010 Working with ranges in pictures.
CS1315: Introduction to Media Computation Referencing pixels directly by index number.
CS2984: Introduction to Media Computation Using Loops for Pictures Conditionals Copying images.
Rotations. Graph the following coordinates, then connect the dots (2, 1) (4,1) (2, 5) X y Rotate the triangle 90° clockwise about the origin and graph.
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):
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.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Rotations.
Rotations and Dilations
“But it looks right”: Bugs in non-majors media programs Mark Guzdial College of Computing/GVU Georgia Institute of Technology.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Chapter 6: Modifying Pixels by Position
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.
Test 2 on Wed, 11/9 On image processing
12-4: Matrix Methods for Square Systems
Chapter 5: Picture Techniques with Selection
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Picture Functions ppp =makePicture(pickAFile())
Chapter 8: Making Sounds by Combining Pieces
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
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Chapter 4: Modifying Pixels in a Range
Transformations on the coordinate plane
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
Introduction to transformational GEOMETRY
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
This shows the frameset container page which holds two additional pages in rows - the first row uses 50% of the page and the last row uses the rest. Note.
Transformations on the coordinate plane
Unit 1 Transformations in the Coordinate Plane
Chapter 4: Modifying Pixels in a Range
Transformations on the coordinate plane
CSC1401 Manipulating Pictures 2
Question 35.
Unit 1 Transformations in the Coordinate Plane
Presentation transcript:

CSC 112Introduction to Media Computation 1 Rotating Images

Introduction to Media Computation2 CSC 112 Copy and Rotate def copySideways(): # This is the version from the book (Recipe 29) that # simply swithches targetX and targetY in the call to # setColor to accomplish the rotation. # # Set up the source and target pictures file=getMediaPath("flower1.jpg") picture = makePicture(file) canvasf = getMediaPath("320x240.jpg") canvas = makePicture(canvasf) # Now, do the actual copying targetX = 1 for sourceX in range(1,getWidth(picture)): targetY = 1 for sourceY in range(1,getHeight(picture)): color = getColor(getPixel(picture,sourceX,sourceY)) setColor(getPixel(canvas,targetY,targetX), color) targetY = targetY + 1 targetX = targetX + 1 # Display the results show(picture) show(canvas) return canvas

Introduction to Media Computation3 CSC 112 Rotating: How it works We increment the same, but we use targetX for the Y coordinate and targetY for the X coordinate

Introduction to Media Computation4 CSC 112 Rotating: How it works 2 We increment sourceY and targetY just the same.

Introduction to Media Computation5 CSC 112 Rotate: How it ends Same amount of increment, even same values in the variables, but a different result. First column of the original became the first for of the copy, and so on.

Introduction to Media Computation6 CSC 112 Take a closer look: The flower was reversed left-to-right as it was copied. Why? The first column of the original became the first row of the copy, when it really should be the last row to avoid reversing the image.

Introduction to Media Computation7 CSC 112 Copy with Counterclockwise Rotation def copyCounterclockwise(): # This version works like Recipe 30 from the book, but it # uses the names targetX and targetY for the values that # will be used for the X and Y values in setColor. file=getMediaPath("flower1.jpg") picture = makePicture(file) canvasf = getMediaPath("320x240.jpg") canvas = makePicture(canvasf) # The picture on the canvas will be filled in from bottom # to top with the columns from the original picture, as # targetY goes from getWidth(pictue) - 1 to 0 targetY = getWidth(picture) - 1 for sourceX in range(1,getWidth(picture)): targetX = 1 for sourceY in range(1,getHeight(picture)): color = getColor(getPixel(picture,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), color) targetX = targetX + 1 targetY = targetY - 1 # Display the results show(picture) show(canvas) return canvas

Introduction to Media Computation8 CSC 112 Other rotations We can rotate clockwise instead of counterclockwise by counting down through the values of targetX instead of targetY Inversion is accomplished by counting down through both ranges. targetX will be associated with the sourceX loop in this case, since the copied picture will be the same shape as the original.

Introduction to Media Computation9 CSC 112 Copy with Clockwise Rotation def copyClockwise(): # Like copyContercloskwise, this function uses the names targetX and # targetY for the values that will be used for the X and Y in setColor file=getMediaPath("flower1.jpg") picture = makePicture(file) canvasf = getMediaPath("320x240.jpg") canvas = makePicture(canvasf) # The picture on the canvas will be filled in from top # to bottom with the columns from the original picture targetY = 1 for sourceX in range(1,getWidth(picture)): # Each row of the new picture will be filled from right to left, # as targetX decreases from getHeight(picture) - 1 to 0 targetX = getHeight(picture) - 1 for sourceY in range(1,getHeight(picture)): color = getColor(getPixel(picture,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), color) targetX = targetX - 1 targetY = targetY + 1 show(picture) show(canvas) return canvas

Introduction to Media Computation10 CSC 112 Copy and Invert def copyInverted(): # Set up the source and target pictures file=getMediaPath("flower1.jpg") picture = makePicture(file) canvasf = getMediaPath("320x240.jpg") canvas = makePicture(canvasf) # The columns of the new picture will be added from # right to left, since targetX is counting down targetX = getWidth(picture) - 1 for sourceX in range(1,getWidth(picture)): # Each column will be filled from bottom to top, # since targetY is counting down targetY = getHeight(picture) - 1 for sourceY in range(1,getHeight(picture)): color = getColor(getPixel(picture,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), color) targetY = targetY - 1 targetX = targetX - 1 # Display the results show(picture) show(canvas) return canvas