CS1315: Introduction to Media Computation

Slides:



Advertisements
Similar presentations
Sound, Part 2 Using range to manipulate samples by index number.
Advertisements

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.
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.
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.
UWCSE BRIDGE Workshop Aug. 31 – Sept. 3, 2009 Hal Perkins Computer Science & Engineering University of Washington
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
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.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Chapter 6: Modifying Pixels by Position. Chapter Learning Goals.
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.
Manipulating Pixels by Range and More on Functions.
CS2984: Introduction to Media Computation Using Loops for Pictures Conditionals Copying images.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
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.
CS 101: Introduction to Computing Color replacements and targeted color replacement (if statement) Developed by Mark Guzdial, Georgia Institute of Technology,
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.
Transformations To move a figure in the coordinate system to another location or image, by a rule.
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
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.
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.
Test 2 on Wed, 11/9 On image processing
translations, rotations, and reflections
Chapter 5: Picture Techniques with Selection
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Image Manipulation Institute for Personal Robots in Education (IPRE)‏
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Constructions of Basic Transformations
Picture Functions ppp =makePicture(pickAFile())
Chapter 8: Making Sounds by Combining Pieces
CS1315: Introduction to Media Computation
Workshop for Programming And Systems Management Teachers
Manipulating Pictures, Arrays, and Loops part 2
Working with ranges in pictures
ROTATIONS UNIT 1 – sept. 8.
Two-Dimensional Arrays and Nested Loops – part 5
Transformations and Symmetry
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 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
Manipulating Pictures, Arrays, and Loops
Chapter 4: Modifying Pixels in a Range
CS1315: Introduction to Media Computation
Presentation transcript:

CS1315: Introduction to Media Computation How the transformations worked, and how to make them better This is an exploration lecture – things to explore: How to walk through mirroring more carefully and how to debug for understanding. An additional copying transformation – rotations How we can use blurring to get scaling to look better If time permits: Talk about other kinds of blurring (weighting so that you don’t mess up edges) Talk about how to do rotations OTHER THAN right angles

Understanding and using image manipulations better Let’s walk through mirroring in more detail Use the temple fixing example What was really going on there? More on what we can do with copying: Rotating Let’s talk about how to avoid the degradation of scaling

Program to mirror the temple def mirrorTemple(): source = makePicture(getMediaPath("temple.jpg")) mirrorpoint = 277 lengthToCopy = mirrorpoint - 14 for x in range(1,lengthToCopy): for y in range(28,98): p = getPixel(source,mirrorpoint-x,y) p2 = getPixel(source,mirrorpoint+x,y) setColor(p2,getColor(p)) show(source) return source

Did it really work? It clearly did the mirroring, but that doesn’t create a 100% realistic image. Check out the shadows: Which direction is the sun coming from? Consider other reasons why this worked as well as it did. Clouds in the sky?

Understanding the Temple Fix What is the very first transfer of pixels from and to? Which (x,y) pixel from? Which (x,y) pixel to? What is the second set of pixels? How many pixels get copied? Try to get people to make guesses here, first, before going on.

Adding print statements to see what’s happening def mirrorTemple(): source = makePicture(getMediaPath("temple.jpg")) mirrorpoint = 277 lengthToCopy = mirrorpoint - 14 for x in range(1,lengthToCopy): for y in range(28,98): print "Copying color from",mirrorpoint-x,y print "to",mirrorpoint+x,y p = getPixel(source,mirrorpoint-x,y) p2 = getPixel(source,mirrorpoint+x,y) setColor(p2,getColor(p)) show(source) return source

First pixels are either side of the mirrorpoint, then moving down >>> p2=mirrorTemple() Copying color from 276 28 to 278 28 Copying color from 276 29 to 278 29 Copying color from 276 30 to 278 30

Counting pixels def mirrorTemple(): source = makePicture(getMediaPath("temple.jpg")) mirrorpoint = 277 lengthToCopy = mirrorpoint - 14 count = 0 for x in range(1,lengthToCopy): for y in range(28,98): p = getPixel(source,mirrorpoint-x,y) p2 = getPixel(source,mirrorpoint+x,y) setColor(p2,getColor(p)) count = count + 1 show(source) print "We copied",count,"pixels" return source

Counting pixels >>> p2=mirrorTemple() We copied 18340 pixels Where did that come from? How many rows? Y goes from 28 to 98 = 70 rows of pixels How many columns? X goes from 1 to 277-14=263 = 262 columns of pixels 70 * 262 = 18340

Rotating the copy def copyBarbSideways(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") barb = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the actual copying targetX = 1 for sourceX in range(1,getWidth(barb)+1): targetY = 1 for sourceY in range(1,getHeight(barb)+1): color = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetY,targetX), color) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas Here’s another example of a transformation.

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.

Did this really “Rotate”? No, it flipped along the main diagonal. What do we need to do to really rotate (either clockwise or counter-clockwise?)

Rotating the copy def rotateBarbSideways(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") barb = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the actual copying targetX = 1 width = getWidth(barb) for sourceX in range(1,getWidth(barb)+1): targetY = 1 for sourceY in range(1,getHeight(barb)+1): color = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetY,width-targetX+1), color) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas Here’s another example of a transformation.

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 recipe def blur(pic,size): for pixel in getPixels(pic): currentX = getX(pixel) currentY = getY(pixel) r = 0 g = 0 b = 0 count = 0 for x in range(currentX - size,currentX + size): for y in range(currentY - size, currentY + size): if(x<=0) or (y<=0) or (x > getWidth(pic)) or (y > getHeight(pic)): pass # Skip if we go off the edge else: r = r + getRed(getPixel(pic,x,y)) g = g + getGreen(getPixel(pic,x,y)) b = b + getBlue(getPixel(pic,x,y)) count = count + 1 newColor = makeColor(r/count,g/count,b/count) setColor(pixel,newColor) We’ll see pass and else later, but you can probably get a sense here of what’s going on.

Blurring out the pixelation