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

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern