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

Slides:



Advertisements
Similar presentations
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
Advertisements

CS2984: Introduction to Media Computation Drawing directly on images.
Digital Color 24-bit Color Indexed Color Image file compression
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
The Binary Numbering Systems
ISYS 3074 Graphics File Formats File formats have developed with applications. At least 50 currently in use. Examples include: GIF, JPEG, TIFF, BMP, DIB,
Introduction to Computer Graphics
How Images are Represented Bitmap images (Dots used to draw the image) Monochrome images 8 bit grey scale images 24 bit colour Colour lookup tables Vector.
Graphical images Bit-mapped (or raster-based) image: Matrix describing the individual dots that are the smallest elements (pixels) of resolution on a computer.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
Copying and Transforming Pictures. First, finding the min or max… Next homework asks you to write a function to find the darkest and lightest shade of.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 5: Advanced Picture Techniques.
Dean Pentcheff NHMLAC MBPC/Crustacea 17 April 2006.
BFTAW BDPA Workshop Introduction to GIMP Chris
BFTAW BDPA Workshop Introduction to GIMP Chris
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Higher Computing Computer Systems S. McCrossan 1 Higher Grade Computing Studies 1. Data Representation Data Representation – Why do we use binary? simplicity,
02-RangesInPictures1 Barb Ericson Georgia Institute of Technology Oct 2010 Working with ranges in pictures.
CS2984: Introduction to Media Computation Using Loops for Pictures Conditionals Copying images.
Image Representation. Objectives  Bitmaps: resolution, colour depth and simple bitmap file calculations.  Vector graphics: drawing list – objects and.
Lecture 4 Pixels, Images and Image Files 1. In this Lecture, you will learn the following concepts: Image files (in particular, the BMP file format) How.
Computer Graphics Bitmaps & Sprites CO2409 Computer Graphics Week 3.
Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.
Image Representation. Digital Cameras Scanned Film & Photographs Digitized TV Signals Computer Graphics Radar & Sonar Medical Imaging Devices (X-Ray,
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Marr CollegeHigher ComputingSlide 1 Higher Computing: COMPUTER SYSTEMS Part 1: Data Representation – 6 hours.
Program Design and Debugging. How do programmers start? How do you get started with a program? “Programming is all about debugging a blank piece of paper.”
ADOBE PHOTOSHOP VECTOR VS RASTER. Pixel A pixel is the fundamental unit of an image in Photoshop. It is a small square block of color. An image often.
1 CS 177 Week 11 Recitation Slides Writing out programs, Reading from the Internet and Using Modules.
Digital Media Lecture 4.1: Image Encoding Practice Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
1 CS 177 Week 5 Recitation Slides Mirroring and copying images, Using for Loop, if statement, and range.
Copying: How it works Here's the initial setup:. Copying: How it works 2 After incrementing the sourceY and targetY once (whether in the for or via expression):
CS 101: Introduction to Computing Rotating and Blurring Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan,
Chapter 4: Modifying Pixels in a Range (partial slide deck)
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
Graphics An image is made up of tiny dots called pixels (“picture elements”) The resolution determines the.
NestedLoops-part41 Nested Loops – part 4 Barb Ericson Georgia Institute of Technology Nov 2009.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 5: Advanced Picture Techniques.
Chapter 5: Advanced Picture Techniques. Chapter Objectives.
 By Bob “The Bird” Fiske & Anita “The Snail” Cost.
Graphics. … Can be immersive and capture imaginations. Largest Photographs In The World.
Image File Formats. What is an Image File Format? Image file formats are standard way of organizing and storing of image files. Image files are composed.
Chapter 6: Modifying Pixels by Position
Image File Formats By Dr. Rajeev Srivastava 1. Image File Formats Header and Image data. A typical image file format contains two fields namely Dr. Rajeev.
CSC 112Introduction to Media Computation 1 Rotating Images.
CS1315: Introduction to Media Computation Transforming pictures by index number.
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
Digital Media Lecture 4.2: Image Encoding Practice Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Information Systems Design and Development Media Types Computing Science.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
ITEC2110, Digital Media Chapter 2 Fundamentals of Digital Imaging 1 GGC -- ITEC Digital Media.
Chapter 5: Picture Techniques with Selection
Web Graphics By Chris Harding.
Binary Representation in Audio and Images
Computer Science Higher
Digital Media Lecture 4.1: Image Encoding Practice
BTEC NCF Dip in Comp - Unit 02 Fundamentals of Computer Systems Lesson 10 - Text & Image Representation Mr C Johnston.
Chapter 8: Making Sounds by Combining Pieces
Working with ranges in pictures
Data Representation.
Chapter 4: Modifying Pixels in a Range
COMS 161 Introduction to Computing
CS 177 Week 3 Recitation Slides
CSC1401 Viewing a picture as a 2D image - 2
CS 177 Week 9 Recitation Slides
CS1315: Introduction to Media Computation
Chapter 4: Modifying Pixels in a Range
"Digital Media Primer" Yue-Ling Wong, Copyright (c)2013 by Pearson Education, Inc. All rights reserved.
Presentation transcript:

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

2 Announcements EXAM 1  Wednesday 09/29  6:30p - 7:30p  EE 129

Scaling 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 We sample fewer pixels  If we want a larger copy, we duplicate some pixels We over-sample some pixels 3

Scaling Up: Growing the picture To grow a picture, we simply duplicate some pixels 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 Same basic setup as copying and rotating: 5

Scaling up: How it works 2 But as we increment by only 0.5, and we use the int() function, we end up taking every pixel twice. Here, the blank pixel at (0,0) in the source gets copied twice onto the canvas. 6

Scaling up: How it works 3 Black pixels gets copied once… 7

Scaling up: How it works 4 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 sourceX = sourceX show(barb) show(canvas) return canvas

Scaling up: How it ends up We end up in the same place in the source, but twice as much in the target. Notice the degradation:  Gaps that weren’t there previously  Curves would get “choppy”: Pixelated 10

What to do? 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 11

Scaling the picture down def copyBarbsFaceSmaller(): # Set up the source and target picture 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,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), color) sourceY = sourceY + 2 sourceX = sourceX + 2 show(barb) show(canvas) return canvas

Drawing on images Sometimes you want to draw on pictures, to add something to the pictures.  Lines  Text  Circles and boxes. We can do that pixel by pixel, setting black and white pixels, but that’s tedious 13

Let’s do that with some JES functions! addText(pict,x,y,string) puts the string starting at position (x,y) in the picture addLine(picture,x1,y1,x2,y2) draws a line from position (x1,y1) to (x2,y2) addRect(pict,x1,y1,w,h) draws a black rectangle (unfilled) with the upper left hand corner of (x1,y1) and a width of w and height of h addRectFilled(pict,x1,y1,w,h,color) draws a rectangle filled with the color of your choice with the upper left hand corner of (x1,y1) and a width of w and height of h 14

Remember, in JES some colors are already defined Colors defined for you already: black, white, blue, red, green, gray, lightGray, darkGray, yellow, orange, pink, magenta, and cyan 15

Drawing lines on Carolina def lineExample(): img = makePicture(pickAFile()) verticalLines(img) horizontalLines(img) show(img) return img def horizontalLines(src): for x in range(0,getHeight(src),5): for y in range(0,getWidth(src)): setColor(getPixel(src,y,x), black ) def verticalLines(src): for x in range(0,getWidth(src),5): for y in range(0,getHeight(src)): setColor(getPixel(src,x,y), black ) We can use the color name “black” – it’s pre- defined for us. 16

Let’s see how to use these functions def addABox(): beach = makePicture(getMediaPath("beach-smaller.jpg")) addRectFilled(beach,150,150,50,50,red) show(beach) return beach 17

Let’s see how to use these functions def littlepicture(): canvas=makePicture(getMediaPath("640x480.jpg")) addText(canvas,10,50,"This is not a picture") addLine(canvas,10,20,300,50) addRectFilled(canvas,0,200,300,500,yellow) addRect(canvas,10,210,290,490) return canvas 18

Let’s think about something… Look at that previous page: Which has a fewer number of bytes?  The program that drew the picture  The pixels in the picture itself. It’s a no-brainer  The program is less than 100 characters (100 bytes)  The picture is stored on disk at about 15,000 bytes 19

Vector-based vs. Bitmap Graphical representations Vector-based graphical representations are basically executable programs that generate the picture on demand.  Postscript, Flash, and AutoCAD use vector-based representations Bitmap graphical representations (like JPEG, BMP, GIF) store individual pixels or representations of those pixels.  JPEG and GIF are actually compressed representations 20

Vector-based representations can be smaller Vector-based representations can be much smaller than bit-mapped representations Smaller means faster transmission (Flash and Postscript) 21

But vector-based has more value than that Imagine that you’re editing a picture with lines on it.  If you edit a bitmap image and extend a line, it’s just more bits. There’s no way to really realize that you’ve extended or shrunk the line.  If you edit a vector-based image, it’s possible to just change the specification Change the numbers saying where the line is Then it really is the same line That’s important when the picture drives the creation of the product, like in automatic fabric cutting machines 22

How are images compressed? Sometimes lossless using techniques like run length encoding (RLE) Instead of this: B B Y Y Y Y Y Y Y Y Y B B We could say “9 Y’s” like this: B B 9 Y B B Lossy compression (like JPEG and GIF) loses detail, some of which is invisible to the eye. 23

When changing the picture means changing a program… In a vector-based drawing package, changing the drawing is changing a program. How could we reach in and change the actual program? We can using string manipulation  The program is just a string of characters  We want to manipulate those characters, in order to manipulate the program 24

Example programmed graphic If I did this right, we perceive the left half as lighter than the right half In reality, the end quarters are actually the same colors. 25

Building a programmed graphic def greyEffect(): file = getMediaPath("640x480.jpg") pic = makePicture(file) # First, 100 columns of 100-grey grey = makeColor(100,100,100) for x in range(1,100): for y in range(1,100): setColor(getPixel(pic,x,y),grey) # Second, 100 columns of increasing greyness greyLevel = 100 for x in range(100,200): grey = makeColor(greyLevel, greyLevel, greyLevel) for y in range(1,100): setColor(getPixel(pic,x,y),grey) greyLevel = greyLevel + 1 # Third, 100 colums of increasing greyness, from 0 greyLevel = 0 for x in range(200,300): grey = makeColor(greyLevel, greyLevel, greyLevel) for y in range(1,100): setColor(getPixel(pic,x,y),grey) greyLevel = greyLevel + 1 # Finally, 100 columns of 100-grey grey = makeColor(100,100,100) for x in range(300,400): for y in range(1,100): setColor(getPixel(pic,x,y),grey) return pic 26

Another Programmed Graphic def coolpic(): canvas=makePicture(getMediaPath("640x480.jpg")) for index in range(25,1,-1): color = makeColor(index*10,index*5,index) addRectFilled(canvas,0,0,index*10,index*10,color) show(canvas) return canvas 27

And another def coolpic2(): canvas=makePicture(getMediaPath("640x480.jpg")) for index in range(25,1,-1): addRect(canvas,index,index,index*3,index*4) addRect(canvas,100+index*4,100+index*3,index*8,index*10) show(canvas) return canvas 28

29 Final QUESTIONS???