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

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

1 CS 177 Week 6 Recitation Slides Scaling Drawing on images Vector-based Vs. Bitmap graphical representation

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

View Full Document
2 Announcements n EXAM 1 ¨ Wednesday 09/29 ¨ 6:30p - 7:30p ¨ EE 129
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

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

View Full Document
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
Scaling up: How it works n Same basic setup as copying and rotating: 5

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

View Full Document
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
Scaling up: How it works 3 n Black pixels gets copied once… 7

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

View Full Document
Scaling up: How it works 4 n And twice… 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

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

View Full Document
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
What to do? n

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/22/2012 for the course CS 177 taught by Professor Staff during the Fall '08 term at Purdue.

### 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
Ask a homework question - tutors are online