Presentation is loading. Please wait.

Presentation is loading. Please wait.

Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.

Similar presentations


Presentation on theme: "Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization."— Presentation transcript:

1 Image Synthesis Rabie A. Ramadan, PhD 7

2 2 Image Rasterization

3 3 Rasterization and Fragment Processing A precise sequence of steps for converting primitives into patterns of pixel values in the framebuffer. Digital images created or captured (for example, by scanning in a photo) as a set of samples of a given space.

4 4 The graphics pipeline

5 5 Pipeline overview

6 6 Primitives

7 7 Rasterization First job: enumerate the pixels covered by a primitive Simple, aliased definition: pixels whose centers fall inside Second job: interpolate values across the primitive e.g., colors computed at vertices Will see applications later on

8 8 Rasterizing lines

9 9 Point sampling

10 10 Point sampling in action

11 Pixel addressing in raster graphics

12 Raster conversion algorithms: requirements visual accuracy speed

13 Line drawing algorithms

14 Line – raster representation

15 How does computer draw line? Screen made of pixels High-level language specifies line System must color pixels

16 Naïve algorithm for lines Line definition: ax+by+c = 0 Also expressed as: y = mx + d m = slope d = distance For x=xmin to xmax compute y = m*x+d light pixel (x,y)

17 Extension by symmetry Only works with -1  m  1: m = 1/3 m = 3 Extend by symmetry for m > 1

18 Problems 2 floating-point operations per pixel Improvements: compute y = m*p+d For x=xmin to xmax y += m light pixel (x,y) Still 1 floating-point operation per pixel Compute in floats, pixels in integers

19 DDA ( Digital Differential Algorithm ) m < 1

20 DDA ( Digital Differential Algorithm ) m > 1

21 DDA ( Digital Differential Algorithm ) m > 1

22 Digital Differential Algorithm input line endpoints, (x 0,y 0 ) and (x n, y n ) set pixel at position (x 0,y 0 ) calculate slope m Case |m|≤1: repeat the following steps until (x n, y n ) is reached: y i+1 = y i +  y/  x x i+1 = x i + 1 set pixel at position (x i+1,Round(y i+1 )) Case |m|>1: repeat the following steps until (x n, y n ) is reached: x i+1 = x i +  x/  y y i+1 = y i + 1 set pixel at position (Round(x i+1 ), y i+1 )

23 Bresenham's line algorithm d1 d2 xx+1 y y = m(x+1) + b y = mx + b

24 Bresenham's line algorithm (slope ≤ 1) input line endpoints, (x 0,y 0 ) and (x n, y n ) calculate  x = x n - x 0 and  y = y n - y 0 calculate parameter p 0 = 2  y -  x set pixel at position (x 0,y 0 ) repeat the following steps until (x n, y n ) is reached: if p i < 0 set the next pixel at position (x i +1, y i ) calculate new p i+1 = p i + 2  y if p i ≥ 0 set the next pixel at position (x i +1, y i + 1 ) calculate new p i+1 = p i + 2(  y -  x)

25 DDA versus Bresenham’s Algorithm DDA works with floating point arithmetic Rounding to integers necessary Bresenham’s algorithm uses integer arithmetic Constants need to be computed only once Bresenham’s algorithm generally faster than DDA

26 Circle: naïve algorithm Circle equation: x 2 +y 2 -r 2 = 0 Simple algorithm: for x = xmin to xmax y = sqrt(r*r - x*x) draw pixel(x,y) Work by octants and use symmetry

27 Circle: Bresenham algorithm Choice between two pixels: Circle drawn so far …or that one Either I lit this pixel…


Download ppt "Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization."

Similar presentations


Ads by Google