Presentation is loading. Please wait.

Presentation is loading. Please wait.

Eleven colors and rasters. Color objects [color name] Returns color with the specified name [color red green blue] Returns color with the specified amounts.

Similar presentations


Presentation on theme: "Eleven colors and rasters. Color objects [color name] Returns color with the specified name [color red green blue] Returns color with the specified amounts."— Presentation transcript:

1 eleven colors and rasters

2 Color objects [color name] Returns color with the specified name [color red green blue] Returns color with the specified amounts of red, green, and blue light Arguments should be 0-255 [red c] or c.R [green c] or c.G [blue c] or c.B Returns the amount of red/green/blue light in the color c

3 Color operations [+ color color] Adds together the light of the two colors to form a new color [× number color], [ ⁄ color number] Brightens/dims color by the factor number [intensity color] Returns the total amount of light in the color from 0-255 This was called brightness in assignment 3 [gray intensity] Returns a neutral gray color with the specified intensity (0-255)

4 Vectors (aka points) Used to represent positions in the image or displacements between positions [vector x y] or: [point x y] Returns a vector object with the specified coordinates [vector-x p] or: [point-x p], p.X [vector-y p] or: [point-y p], p.Y Returns x (or y) coordinate of p

5 Vector operations [+ vector vector], [− vector vector] Returns the sum/difference of two vectors (points) Sum shifts the first vector over by the amount of the second vector (or vice-versa) Difference shifts the first one back [× number vector], [ ⁄ vector number] Returns vector stretched/shrunk by a factor of number [rotate-vector vector angle] [rotate-vector-degrees vector angle] Rotates the vector about the origin [magnitude vector] Returns the length of the vector vector

6 What’s the difference between a vector and a point? In this class, the terms are interchangeable Both are used in the literature They technically mean slightly different things, but the distinctions don’t matter for this class We’re teaching you both terms, but you don’t need to worry about them I’ll adopt the convention of using [point x y] when I really mean a position in the image [vector x y] when I mean a shift or a direction, but not a specific position in the image I don’t care whether you follow this convention

7 The “dot” product [dot p 1 p 2 ] Definitions: The distance p 1 extends in the direction of p 2 (if p 2 has length 1) The distance p 2 extends in the direction of p 1 (if p 1 has length 1) [+ [× p 1.X p 2.X] [× p 1.Y p 2.Y]] [× [magnitude p 1 ] [magnitude p 2 ] [cos [angle-between p 1 p 2 ]]] Also known as Projection Scalar product Inner product Enigmatic But very common in graphics, signal processing (music), statistics Measures Similarity between vectors p 1 and p 2 Distance p 1 extends in the direction of p2 (or vice-versa) When p 1 is one unit long (i.e. a “unit vector”) Returns the number of units p 2 extends in the direction of p 1. Modern video cards have special hardware to compute dot products as fast as possible

8 Dot product examples X axis Y axis p 1 = [vector 1 0] p 2 = [vector 1.5 3] p 3 = [vector 0 2] [dot p 1 p 2 ] = 1×1.5+0×3 = 1.5 [dot p 1 p 3 ] = 1×0 + 0×2 = 0 [dot p3 p2] = 0×1.5+2×3 = 6 ←1.5 units →

9 Rasters (a.k.a. bitmaps) A bitmap is a specific kind of data object that represents an image E.g. JPEG files, GIF files, paint files But not like draw programs or the pictures we’ve been making so far Has a prespecified width and height (in pixels) It allows you to explicitly retrieve (or change) the color at each pixel

10 Bitmap procedures [new Bitmap string] Reads in the the jpeg or gif file with name string Converts it to internal bitmap format and returns it [height bitmap], [width bitmap] Returns the width/height of a bitmap, in pixels [pixel bitmap x y] Returns the specified pixel of the bitmap [bitmap-from-procedure procedure width height] Makes a bitmap of size width×height Repeatedly calls procedure with the location (a point) of each pixel to get the color of the pixel

11 Example The procedure [p → [color p.X p.X p.X]] Returns a color with equal amounts of red, green, and blue light So it’s grey It’s brightness varies with its horizontal position ► [bitmap-from-procedure [p → [color p.X p.X p.X]] 256 256] ►

12 Comparing to iterated-group This is sort of like iterated-group You give it a procedure And a number of times to run it (well, two numbers) And it makes a picture ► [bitmap-from-procedure [p → [color p.X p.X p.X]] 256 256] ►

13 Comparing to iterated-group Except: The procedure you pass in Returns a color, not a shape Takes a position as an input Takes two count parameters (one for width, one for height) ► [bitmap-from-procedure [p → [color p.X p.X p.X]] 256 256] ►

14 Example 2 The procedure [p → [color p.X 0 p.Y]] Changes red and blue independently So hue varies over space ► [bitmap-from-procedure [p → [color p.X 0 p.Y]] 256 256] ►

15 Example 3 ► [define sine-wave [n → [+ 128 [× 127 [sin [∕ n 20]]]]]] ► [bitmap-from-procedure [p → [color 0 [sine-wave p.X] [sine-wave p.Y]]] 256 256]

16 Bitmap procedures [map-bitmap procedure bitmap] Makes a new bitmap of the same size as bitmap Calls procedure with each pixel of bitmap Procedure returns the color of the respective pixel for the new bitmap Returns the new bitmap

17 Comparing to iterated-group Iterated-group and bitmap-from-procedure construct pictures from scratch But computing each element (shape or pixel color) as specified by a procedure Map-bitmap constructs a new image from an old image By changing the color of each pixel As specified by a procedure

18 Extracting color components of an image ► [define cones [new Bitmap “c:/documents and settings/ian/my documents/cones.jpg”]] ►

19 Extracting color components of an image ► [define gray [i → [color i i i]]] ► [map-bitmap [c → [gray [red c]]] cones] ► ► [map-bitmap [c → [gray [green c]]] cones] ► Note: the gray procedure is already built in


Download ppt "Eleven colors and rasters. Color objects [color name] Returns color with the specified name [color red green blue] Returns color with the specified amounts."

Similar presentations


Ads by Google