27
Image Synthesis Rabie A. Ramadan, PhD 7

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

Embed Size (px)

Citation preview

Page 1: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Image Synthesis

Rabie A. Ramadan, PhD

7

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

2

Image Rasterization

Page 3: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

3

Rasterization andFragment 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.

Page 4: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

4

The graphics pipeline

Page 5: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

5

Pipeline overview

Page 6: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

6

Primitives

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

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

Page 8: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

8

Rasterizing lines

Page 9: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

9

Point sampling

Page 10: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

10

Point sampling in action

Page 11: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Pixel addressing in raster graphics

Pixeladdress

Pixel

x x+1 x+2 x+3 x+4

y

y+1

y+2

y+3

Theoretical length

Actual length

Page 12: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Raster conversion algorithms: requirements

visual accuracy

speed

Page 13: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Line drawing algorithms

imagessymbols &

y = 2x + 5x0 = 100y0 = 50d = 100

thickness = 4

descriptions

Page 14: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Line – raster representation

Page 15: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

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

Page 16: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

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 xmaxcompute y = m*x+d

light pixel (x,y)

Page 17: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Extension by symmetry

Only works with -1 m 1:

m = 1/3

m = 3

Extend by symmetry for m > 1

Page 18: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Problems

2 floating-point operations per pixel Improvements:

compute y = m*p+d

For x=xmin to xmaxy += m

light pixel (x,y) Still 1 floating-point operation per pixel Compute in floats, pixels in integers

Page 19: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

DDA ( Digital Differential Algorithm )

m < 1

Page 20: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

DDA ( Digital Differential Algorithm )m > 1

Page 21: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

DDA ( Digital Differential Algorithm )m > 1

Page 22: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Digital Differential Algorithm input line endpoints, (x0,y0) and (xn, yn) set pixel at position (x0,y0) calculate slope m Case |m|≤1: repeat the following steps until (xn, yn) is reached: yi+1 = yi + y/ x xi+1 = xi + 1 set pixel at position (xi+1,Round(yi+1)) Case |m|>1: repeat the following steps until (xn, yn) is reached: xi+1 = xi + x/ y yi+1 = yi + 1 set pixel at position (Round(xi+1), yi+1)

Page 23: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Bresenham's line algorithm

d1

d2

x x+1

y

y = m(x+1) + b

y = mx + b

Page 24: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Bresenham's line algorithm (slope ≤ 1) input line endpoints, (x0,y0) and (xn, yn) calculate x = xn - x0 and y = yn - y0

calculate parameter p0 = 2 y - x set pixel at position (x0,y0) repeat the following steps until (xn, yn) is reached: if pi < 0 set the next pixel at position (xi +1, yi ) calculate new pi+1 = pi + 2 y if pi ≥ 0 set the next pixel at position (xi +1, yi + 1 ) calculate new pi+1 = pi + 2(y - x)

Page 25: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

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

Page 26: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Circle: naïve algorithm

Circle equation: x2+y2-r2 = 0 Simple algorithm:

for x = xmin to xmax

y = sqrt(r*r - x*x)

draw pixel(x,y) Work by octants and use symmetry

Page 27: Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization

Circle: Bresenham algorithm

Choice between two pixels:

Circle drawn so far

…or that one

Either I lit this pixel…