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

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
2 Announcements n EXAM 1 ¨ Wednesday 09/29 ¨ 6:30p - 7:30p ¨ EE 129
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
Image of page 3

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

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

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

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

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

View Full Document Right Arrow Icon
Scaling up: How it works 4 n And twice… 8
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
Image of page 9

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

View Full Document Right 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
Image of page 10
What to do?
Image of page 11

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern