CST 494/598 Computer Graphics Anshuman Razdan i3dea.asu.edu/razdan
A Razdan and Peter Wonka 1 Disclaimer These slides can only be used as study material for the class 470 at ASU The slides cannot be distributed or used for another purpose The slides may contain errors The slides do not contain all the information necessary to succeed in class; additional material from the book must to be studied The slides are based on a lecture from Prof. Purgathofer from the Vienna University of Technology
A Razdan and Peter Wonka 3 Color and Gray Scale color information: RGB color codes directly in frame buffer 1024 x 1024 x 24 bit/color 3 Mbyte storage color (lookup) tables less storage easy change of color table (e.g., for color coding) gray scale calculated from RGB e.g. intensity = 0.5 [min(r,g,b) + max(r,g,b)] red green blue Farbe black blue green cyan red magenta yellow yellow white
A Razdan and Peter Wonka 4 Color Lookup Table i j r i j g i j b i j xx xx r g b instead of: now: selected colors addressed by table index
A Razdan and Peter Wonka 5 Line Attributes (1) type solid, dashed, dotted,… pixel mask (raster line algorithms) width Bresenham + additional vertical (horizontal) spans width dependent on line slope line caps
A Razdan and Peter Wonka 6 Line Attributes (2) width thick lines as filled rectangles joining two segments: miter round bevel pen and brush options shape, size, pattern pixel mask simulation of brush strokes color
A Razdan and Peter Wonka 7 Area-Fill Attributes (1) fill styles hollow with color border filled with solid color filled with specific pattern or design (e.g., hatch,…)
A Razdan and Peter Wonka 8 Area-Fill Attributes (2) fill options edge type, width, color pattern specification through pattern tables tiling (pattern reference point) start position pixel start position
A Razdan and Peter Wonka 9 Area-Fill Attributes (3) combination of fill pattern with background colors soft fill combination of colors antialiasing at object borders simulation of semitransparent brushes example: linear soft-fill pattern back- ground and or xor replace F...foreground color B...background color BttFtFP)1(
A Razdan and Peter Wonka 10 Scan-Line Polygon-Fill Algorithm interior pixels along a scan line passing through a polygon area
A Razdan and Peter Wonka 11 Scan-L. Fill: Intersecting Vertices intersection points along scan lines that intersect poly- gon vertices. y: odd number of intersections y’: even number of intersections (bad) can be paired for correct interior pixel spans
A Razdan and Peter Wonka 12 Scan-L. Fill: Incremental Update incremental update of intersection point kk kk xx yy m kk yy m xx kk 1 1 y x xx kk 1 slope of polygon boundary line: m (for 2 successive scanlines)
A Razdan and Peter Wonka 13 Scan-L. Fill: Sorted Edge Table sort all edges on smallest y-value edge entry: [max y-value, x-intercept, inverse slope] active-edge list for each scan line contains all edges crossed by that scan line incremental update consecutive intersection pairs (spans) filled
A Razdan and Peter Wonka 14 Sorted Edge Table: Example a polygon and its sorted edge table, with edge DC shortened by 1 unit
A Razdan and Peter Wonka 15 Scan-Line Fill: Active-Edge List active-edge list for - DC’ - DE - AE - AB
A Razdan and Peter Wonka 16 Inside-Outside Tests area-filling algorithms “interior”, “exterior” for self-intersecting polygons? odd-even rule nonzero winding number rule cross or dot product to determine winding number same result for simple polygons
A Razdan and Peter Wonka 17 Flood-Fill Algorithm pixel filling of area areas with no single color boundary start from interior point “flood” internal region 4-connected, 8-connected areas reduce stack size by eliminating several recursive calls
A Razdan and Peter Wonka 18 Flood-Fill: Definition of Boundary area must be distinguishable from boundaries example: area defined within multiple color boundaries
A Razdan and Peter Wonka 19 Flood-Fill: Connectedness Definition: 4-connected means, that a connection is only valid in these 4 directions Definition: 8-connected means, that a connection is only valid in these 8 directions
A Razdan and Peter Wonka 20 Example for 4- and 8-connected a 4-connected areaan 8-connected area a 4-connected area has an 8-connected border an 8-connected area has a 4-connected border
A Razdan and Peter Wonka 21 Simple Flood-Fill Algorithm
A Razdan and Peter Wonka 22 Bad Behaviour of Simple Flood-Fill recursion sequence
A Razdan and Peter Wonka 23 Span Flood-Fill Algorithm floodFill4 produces too high stacks (recursion!) solution: incremental horizontal fill (left to right) recursive vertical fill (first up then down)
A Razdan and Peter Wonka 24 Good Behaviour of Span Flood-Fill 1 2 recursion sequence
A Razdan and Peter Wonka 25 Span Flood-Fill Example x
A Razdan and Peter Wonka 26 Span Flood-Fill Example s2 123 s1
A Razdan and Peter Wonka 27 Span Flood-Fill Example s5s s2 s1 s3
A Razdan and Peter Wonka 28 Span Flood-Fill Example s s s3 123 s2 s1
A Razdan and Peter Wonka 29 Span Flood-Fill Example s s3 123 s2 s
A Razdan and Peter Wonka 30 Span Flood-Fill Example s3 123 s2 s1
A Razdan and Peter Wonka 31 Span Flood-Fill Example s s2 s3s
A Razdan and Peter Wonka 32 Span Flood-Fill Example s2 s3s
A Razdan and Peter Wonka 33 Span Flood-Fill Example s s1 s
A Razdan and Peter Wonka 34 Span Flood-Fill Example s s1=s s4s
A Razdan and Peter Wonka 35 Span Flood-Fill Example s s4s
A Razdan and Peter Wonka 36 Span Flood-Fill Example s s
A Razdan and Peter Wonka 37 Span Flood-Fill Example s
A Razdan and Peter Wonka 38 Span Flood-Fill Example
A Razdan and Peter Wonka 39 text attributes font (e.g. Courier, Arial, Times, Roman, …) styles (regular, bold, italic, underline,…) size (32 point, 1 point = 1/72 inch) proportionally sized vs. fixed space fonts string attributes orientation alignment (left, center, right, justify) Character Attributes verticalvertical horizontal slanted Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance.
A Razdan and Peter Wonka 40 Antialiasing what is aliasing? what is the reason for aliasing? what can we do against it?
A Razdan and Peter Wonka 41 What is Aliasing? not enough resolution not enough colors not enough images / sec geometric errors numeric errors errors that are caused by the discretization of analog data to digital data
A Razdan and Peter Wonka 42 Aliasing: Staircase Effect
A Razdan and Peter Wonka 43 Various Aliasing Effects
A Razdan and Peter Wonka 44 Aliasing from too few Colors artificial color borders can appear
A Razdan and Peter Wonka 45 Aliasing in Animations jumping images "worming“ backwards rotating wheels
A Razdan and Peter Wonka 46 Backwards Rotating Wheels
A Razdan and Peter Wonka 47 Solutions against Aliasing? 1. improve the devices higher resolution more color levels faster image sequence 2. improve the images postprocessing antialiasing ! expensive or incompatible software
A Razdan and Peter Wonka 48 Shannon Sampling Theorem a signal can only be reconstructed without information loss if the sampling frequency is at least twice the highest frequency of the signal this border frequency is called "Nyquist Limit"
A Razdan and Peter Wonka 49 Shannon Sampling Theorem Nyquist sampling interval sampling rate original signal reconstructed signal
A Razdan and Peter Wonka 50 Antialiasing: Nyquist Sampling Frequency a signal can only be reconstructed without information loss if the sampling frequency is at least twice the highest frequency of the signal maxcycle /1x with 2 f x x cycle s i.e. sampling interval one-half cycle interval max 2ff s Nyquist sampling frequency:
A Razdan and Peter Wonka 51 supersampling straight-line segments subpixel weighting masks area sampling straight-line segments filtering techniques compensating for line-intensity differences antialiasing area boundaries (adjusting boundary pixel positions) adjusting boundary pixel intensity Antialiasing Strategies
A Razdan and Peter Wonka 52 Antialiasing: Supersampling Lines = max. intensity... 0 = min. intensity 9 = max. intensity... 0 = min. intensity thin line line of finite width
A Razdan and Peter Wonka 53 Antialiasing
A Razdan and Peter Wonka 54 Antialiasing: Area Sampling Lines calculate the pixel coverage exactly can be done with incremental schemes 0%0%0%0% 0%0%0%0% %3%3%3%
A Razdan and Peter Wonka 55 Antialiasing: Pixel Weighting Masks relative weights for a grid of 3x3 subpixels more weight for center subpixels must be divided by sum of weights subpixel grids can also include some neighboring pixels
A Razdan and Peter Wonka 56 Antialiasing: Filtering Techniques box filter cone filter Gaussian filter continuous overlapping weighting functions to calculate the antialiased values with integrals
A Razdan and Peter Wonka 57 Antialiasing: Compensating for Intensity Differences unequal line lengths displayed with the same number of pixels in each line/row have different intensities proper antialiasing compensates for that!
A Razdan and Peter Wonka 58 Antialiasing
A Razdan and Peter Wonka 59 Antialiasing Area Boundaries (1) adjusting pixel intensities along an area boundary alternative 1: supersampling
A Razdan and Peter Wonka 60 Antialiasing Area Boundaries (2) alternative 2: like midpoint line algorithm p´ = y y mid = [m(x k + 1) + b] (y k + 0.5) p´<0 y closer to y k p´>0 y closer to y k+1 p = p´+ (1 m) : p<1 m closer to y k p>1 m closer to y k+1 ( and p [0,1] ) y y mid Note: We add (1-m) so that the decision parameter p = area covered by polygon!
A Razdan and Peter Wonka 61 Antialiasing Area Boundaries (3) p = p´+(1-m) = [m(x k + 1) + b] (y k + 0.5) + (1 m) = mx k + b y k = xkxk x k +1 ykyk y k p for next pixel = overlap area for current pixel p´ p = p´-m+1 = p´+(1-m) m p´-m
A Razdan and Peter Wonka 62 Antialiasing Examples
A Razdan and Peter Wonka 63 Antialiasing Examples
A Razdan and Peter Wonka 64 Summary: Attributes of Primitives color and greyscale line attributes area fill attributes character attributes antialiasing aliasing effects reasons for aliasing antialiasing strategies