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

Preview:

Citation preview

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.

4

The graphics pipeline

5

Pipeline overview

6

Primitives

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

Rasterizing lines

9

Point sampling

10

Point sampling in action

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

Raster conversion algorithms: requirements

visual accuracy

speed

Line drawing algorithms

imagessymbols &

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

thickness = 4

descriptions

Line – raster representation

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

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)

Extension by symmetry

Only works with -1 m 1:

m = 1/3

m = 3

Extend by symmetry for m > 1

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

DDA ( Digital Differential Algorithm )

m < 1

DDA ( Digital Differential Algorithm )m > 1

DDA ( Digital Differential Algorithm )m > 1

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)

Bresenham's line algorithm

d1

d2

x x+1

y

y = m(x+1) + b

y = mx + b

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)

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

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

Circle: Bresenham algorithm

Choice between two pixels:

Circle drawn so far

…or that one

Either I lit this pixel…

Recommended