CS1315: Introduction to Media Computation - PowerPoint PPT Presentation

About This Presentation
Title:

CS1315: Introduction to Media Computation

Description:

CS1315: Introduction to Media Computation How the transformations worked, and how to make them better Understanding and using image manipulations better Let s walk ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 19
Provided by: MarkGu7
Category:

less

Transcript and Presenter's Notes

Title: CS1315: Introduction to Media Computation


1
CS1315 Introduction to Media Computation
  • How the transformations worked, and how to make
    them better

2
Understanding and using image manipulations better
  • Lets 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
  • Lets talk about how to avoid the degradation of
    scaling

3
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,mirrorpointx,y)
  • setColor(p2,getColor(p))
  • show(source)
  • return source

4
Did it really work?
  • It clearly did the mirroring, but that doesnt
    create a 100 realistic image.
  • Check out the shadows Which direction is the sun
    coming from?

5
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?

6
Adding print statements to see whats 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",mirrorpointx,y
  • p getPixel(source,mirrorpoint-x,y)
  • p2 getPixel(source,mirrorpointx,y)
  • setColor(p2,getColor(p))
  • show(source)
  • return source

7
First pixels are either side of the mirrorpoint,
then moving down
  • gtgtgt p2mirrorTemple()
  • Copying color from 276 28
  • to 278 28
  • Copying color from 276 29
  • to 278 29
  • Copying color from 276 30
  • to 278 30

8
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,mirrorpointx,y)
  • setColor(p2,getColor(p))
  • count count 1
  • show(source)
  • print "We copied",count,"pixels"
  • return source

9
Counting pixels
  • gtgtgt p2mirrorTemple()
  • 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-14263
  • 262 columns of pixels
  • 70 262 18340

10
Rotating the copy
def copyBarbSideways() Set up the source and
target pictures barbfgetMediaPath("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
11
Rotating How it works
  • We increment the same, but we use targetX for the
    Y coordinate and targetY for the X coordinate

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

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

14
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?)

15
Rotating the copy
def rotateBarbSideways() Set up the source
and target pictures barbfgetMediaPath("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(b
arb)1) color getColor(getPixel(barb,sour
ceX,sourceY)) setColor(getPixel(canvas,targe
tY,width-targetX1), color) targetY
targetY 1 targetX targetX 1
show(barb) show(canvas) return canvas
16
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.

17
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(xlt0) or (ylt0) or (x gt getWidth(pic))
    or (y gt 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)

Well see pass and else later, but you can
probably get a sense here of whats going on.
18
Blurring out the pixelation
Write a Comment
User Comments (0)
About PowerShow.com