37
2/17/04 © University of Wisconsin, CS559 S pring 2004 Last Time Resampling Ideal reconstruction You can only ideally reconstruct band-limited functions Otherwise high frequencies alias as lower frequencies when reconstructed Point samples images should be reconstructed with sinc filters, but we don’t do this Two ways to avoid aliasing: smooth (band-limit) the original image before sampling, or reconstruct with a filter close to a sinc Compositing Alpha describes the opacity of a pixel Compositing is always Different F and G lead to different operations Alpha comes from blue-screening, hand generation, or computer generated imagery g f o Gc Fc c

2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

Embed Size (px)

Citation preview

Page 1: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Last Time

• Resampling– Ideal reconstruction– You can only ideally reconstruct band-limited functions

• Otherwise high frequencies alias as lower frequencies when reconstructed

– Point samples images should be reconstructed with sinc filters, but we don’t do this

– Two ways to avoid aliasing: smooth (band-limit) the original image before sampling, or reconstruct with a filter close to a sinc

• Compositing– Alpha describes the opacity of a pixel– Compositing is always – Different F and G lead to different operations– Alpha comes from blue-screening, hand generation, or computer generated

imagery

gfo GcFcc

Page 2: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Today

• Painterly rendering

• The Graphics Pipeline

Page 3: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Painterly Filters

• Many methods have been proposed to make a photo look like a painting

• Today we look at one: Painterly-rendering with brushes of multiple sizes

• Basic ideas:– Build painting one layer at a time,

from biggest to smallest brushes

– At each layer, add detail missing from previous layer

Page 4: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Algorithm 1

function paint(sourceImage,R1 ... Rn) // take source and several brush sizes{

canvas := a new constant color image// paint the canvas with decreasing sized brushesfor each brush radius Ri, from largest to smallest do{

// Apply Gaussian smoothing with a filter of size const * radius// Brush is intended to catch features at this scalereferenceImage = sourceImage * G(fs Ri)// Paint a layerpaintLayer(canvas, referenceImage, Ri)

}return canvas

}

Page 5: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Algorithm 2

procedure paintLayer(canvas,referenceImage, R) // Add a layer of strokes{

S := a new set of strokes, initially emptyD := difference(canvas,referenceImage) // euclidean distance at every pixelfor x=0 to imageWidth stepsize grid do // step in size that depends on brush radius

for y=0 to imageHeight stepsize grid do { // sum the error near (x,y)

M := the region (x-grid/2..x+grid/2, y-grid/2..y+grid/2)areaError := sum(Di,j for i,j in M) / grid2

if (areaError > T) then {// find the largest error point

(x1,y1) := max Di,j in M

s :=makeStroke(R,x1,y1,referenceImage)add s to S

}}

paint all strokes in S on the canvas, in random order}

Page 6: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Results

Original Biggest brush

Medium brush added Finest brush added

Page 7: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Point Style

• Uses round brushes

• We provide a routine to “paint” round brush strokes into an image for the project

Page 8: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Where to now…

• We are now done with images

• We will spend several weeks on the mechanics of 3D graphics– Coordinate systems and Viewing

– Clipping

– Drawing lines and polygons

– Lighting and shading

• We will finish the semester with modeling and some additional topics

Page 9: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Graphics Toolkits

• Graphics toolkits typically take care of the details of producing images from geometry

• Input (via API functions):– Where the objects are located and what they look like

– Where the camera is and how it behaves

– Parameters for controlling the rendering

• Functions (via API):– Perform well defined operations based on the input environment

• Output: Pixel data in a framebuffer – an image in a special part of memory– Data can be put on the screen

– Data can be read back for processing (part of toolkit)

Page 10: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

OpenGL

• OpenGL is an open standard graphics toolkit– Derived from SGI’s GL toolkit

• Provides a range of functions for modeling, rendering and manipulating the framebuffer

• What makes a good toolkit?

• Alternatives: Direct3D, Java3D - more complex and less well supported

Page 11: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Coordinate Systems

• The use of coordinate systems is fundamental to computer graphics

• Coordinate systems are used to describe the locations of points in space

• Multiple coordinate systems make graphics algorithms easier to understand and implement

Page 12: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Coordinate Systems (2)

• Different coordinate systems represent the same point in different ways

• Some operations are easier in one coordinate system than in another– For instance, it’s easier to determine how far away something is if

one axis of your coordinate system points away from you

x

y(2,3)

u

v

x

y(1,2)

u

v

Page 13: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Transformations

• Transformations convert points between coordinate systems

x

y(2,3)v

x

y(1,2)

u

v

u

u=x-1v=y-1

x=u+1y=v+1

Page 14: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Transformations(Alternate Interpretation)

• Transformations modify an object’s shape and location in one coordinate system

• The previous interpretation is better for some problems, this one is better for others

x

y(2,3)

(1,2)

x

yx’=x-1y’=y-1

x=x’+1y=y’+1

Page 15: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

2D Affine Transformations

• An affine transformation is one that can be written in the form:

y

x

yyyx

xyxx

yyyyx

xxyxx

b

b

y

x

aa

aa

y

x

byaxay

byaxax

or

Page 16: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Why Affine Transformations?

• Affine transformations are linear– Transforming all the individual points on a line gives the same set

of points as transforming the endpoints and joining them

– Interpolation is the same in either space: Find the halfway point in one space, and transform it. Will get the same result if the endpoints are transformed and then find the halfway point

Page 17: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Composition of Affine Transforms

• Any affine transformation can be composed as a sequence of simple transformations:– Translation

– Scaling (possibly with negative values)

– Rotation

• See Shirley 1.3.6

Page 18: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

2D Translation

• Moves an object

?

?

??

??

y

x

y

x

x

y

x

y

bx

by

?

Page 19: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

2D Translation

• Moves an object

y

x

b

b

y

x

y

x

10

01

x

y

x

y

bx

by

Page 20: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

2D Scaling

• Resizes an object in each dimension

x

y

xy

x

y

sxx

syy

?

?

??

??

y

x

y

x

Page 21: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

2D Scaling

• Resizes an object in each dimension

x

y

0

0

0

0

y

x

s

s

y

x

y

x

xy

x

y

sxx

syy

Page 22: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

2D Rotation

• Rotate counter-clockwise about the origin by an angle

x

y

x

y

?

?

??

??

y

x

y

x

Page 23: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

2D Rotation

• Rotate counter-clockwise about the origin by an angle

0

0

cossin

sincos

y

x

y

x

x

y

x

y

Page 24: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

X-Axis Shear

• Shear along x axis (What is the matrix for y axis shear?)

x

y

x

y

?

?

??

??

y

x

y

x

Page 25: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

X-Axis Shear

• Shear along x axis (What is the matrix for y axis shear?)

0

0

10

1

y

xsh

y

x x

x

y

x

y

Page 26: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Reflect About X Axis

• What is the matrix for reflect about Y axis?

x x

?

?

??

??

y

x

y

x

Page 27: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Reflect About X Axis

• What is the matrix for reflect about Y axis?

0

0

10

01

y

x

y

x

x x

Page 28: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Rotating About An Arbitrary Point

• What happens when you apply a rotation transformation to an object that is not at the origin?

x

y

?

Page 29: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Rotating About An Arbitrary Point

• What happens when you apply a rotation transformation to an object that is not at the origin?– It translates as well

x

y

x

Page 30: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

How Do We Fix it?

• How do we rotate an about an arbitrary point?– Hint: we know how to rotate about the origin of a coordinate system

Page 31: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Rotating About An Arbitrary Point

x

y

x

y

x

y

x

y

Page 32: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Rotate About Arbitrary Point

• Say you wish to rotate about the point (a,b)

• You know how to rotate about (0,0)

• Translate so that (a,b) is at (0,0)– x’=x–a, y’=y–b

• Rotate– x”=(x-a)cos-(y-b)sin, y”=(x-a)sin+(y-b)cos

• Translate back again– xf=x”+a, yf=y”+b

Page 33: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Scaling an Object not at the Origin

• What also happens if you apply the scaling transformation to an object not at the origin?

• Based on the rotating about a point composition, what should you do to resize an object about its own center?

Page 34: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Back to Rotation About a Pt

• Say R is the rotation matrix to apply, and p is the point about which to rotate

• Translation to Origin:

• Rotation:

• Translate back:

• The translation component of the composite transformation involves the rotation matrix. What a mess!

pxx RpRxpxRxRx )(pRpRxpxx

Page 35: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Homogeneous Coordinates

• Use three numbers to represent a point

• (x,y)=(wx,wy,w) for any constant w0

• Typically, (x,y) becomes (x,y,1)

• Translation can now be done with matrix multiplication!

11001

y

x

baa

baa

y

x

yyyyx

xxyxx

Page 36: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Basic Transformations

• Translation: Rotation:

• Scaling:

100

10

01

y

x

b

b

100

00

00

y

x

s

s

100

0cossin

0sincos

Page 37: 2/17/04© University of Wisconsin, CS559 Spring 2004 Last Time Resampling –Ideal reconstruction –You can only ideally reconstruct band-limited functions

2/17/04 © University of Wisconsin, CS559 Spring 2004

Homogeneous Transform Advantages

• Unified view of transformation as matrix multiplication– Easier in hardware and software

• To compose transformations, simply multiply matrices– Order matters: AB is generally not the same as BA

• Allows for non-affine transformations:– Perspective projections!

– Bends, tapers, many others