rec6 - CS 177 Week 6 Recitation Slides Scaling Drawing on...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS 177 Week 6 Recitation Slides Scaling Drawing on images Vector-based Vs. Bitmap graphical representation
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Announcements n EXAM 1 ¨ Wednesday 09/29 ¨ 6:30p - 7:30p ¨ EE 129
Background image of page 2
Scaling n Scaling a picture (smaller or larger) has to do with sampling the source picture differently ¨ When we just copy, we sample every pixel ¨ If we want a smaller copy, we skip some pixels n We sample fewer pixels ¨ If we want a larger copy, we duplicate some pixels n We over-sample some pixels 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Scaling Up: Growing the picture n To grow a picture, we simply duplicate some pixels n We do this by incrementing by 0.5, but only use the integer part. 4 >>> print int(1) 1 >>> print int(1.5) 1 >>> print int(2) 2 >>> print int(2.5) 2
Background image of page 4
Scaling up: How it works n Same basic setup as copying and rotating: 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Scaling up: How it works 2 n But as we increment by only 0.5 , and we use the int() function, we end up taking every pixel twice. n Here, the blank pixel at (0,0) in the source gets copied twice onto the canvas. 6
Background image of page 6
Scaling up: How it works 3 n Black pixels gets copied once… 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Scaling up: How it works 4 n And twice… 8
Background image of page 8
Scaling the picture Up def copyBarbsFaceLarger(): # 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 sourceX = 45 for targetX in range(100,100+((200-45)*2)): sourceY = 25 for targetY in range(100,100+((200-25)*2)): color =getColor(getPixel(barb,int(sourceX),int(sourceY))) setColor(getPixel(canvas,targetX,targetY), color) sourceY = sourceY + 0.5 sourceX = sourceX + 0.5 show(barb) show(canvas) return canvas
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Scaling up: How it ends up n We end up in the same place in the source, but twice as much in the target. n Notice the degradation: ¨ Gaps that weren’t there previously ¨ Curves would get “choppy”: Pixelated 10
Background image of page 10
What to do? n
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

rec6 - CS 177 Week 6 Recitation Slides Scaling Drawing on...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online