Computer Graphics Si Lu Fall 27 http://www.cs.pd.edu/~lusi/cs447/cs447_547_comput er_graphics.htm //27
Last time Filtering Resampling 2
Toda Compositing NPR 3D Graphics Toolkits Transformations 3
Demo https://www.outube.com/watch?v=ckjf qnuso https://www.outube.com/watch?v=dklba U_uWpI 4
Compositing Compositing combines components from two or more images to make a new image Special effects are easier to control when done in isolation Even man all live-action sequences are more safel shot in different laers 5
Historicall The basis for film special effects Create digital imager and composite it into live action It was necessar for films (like Star Wars) where models were used It was done with film and masks, and was time consuming and epensive Important part of animation even hand animation Background change more slowl than foregrounds, so composite foreground elements onto constant background It was a major advance in animation the multiplane camera first used in Snow White (937) 6
Perfect Storm 7
Animated Eample over = 8
Mattes A matte is an image that shows which parts of another image are foreground objects Term dates from film editing and cartoon production How would I use a matte to insert an object into a background? How are mattes usuall generated for television? 9
Working with Mattes To insert an object into a background Call the image of the object the source Put the background into the destination For all the source piels, if the matte is white, cop the piel, otherwise leave it unchanged To generate mattes: Use smart selection tools in Photoshop or similar The outline the object and convert the outline to a matte Blue Screen: Photograph/film the object in front of a blue background, then consider all the blue piels in the image to be the background
Compositing Compositing is the term for combining images, one over the other Used to put special effects into live action
Alpha Basic idea: Encode opacit information in the image Add an etra channel, the alpha channel, to each image For each piel, store R, G, B and Alpha alpha = implies full opacit at a piel alpha = implies completel clear piels There are man interpretations of alpha Is there anthing in the image at that point (web graphics) Transparenc (real-time OpenGL) Images are now in RGBA format, and tpicall 32 bits per piel (8 bits for alpha) All images in the project are in this format 2
Pre-Multiplied Alpha Instead of storing (R,G,B,), store (R,G,B,) The compositing operations in the net several slides are easier with pre-multiplied alpha To displa and do color conversions, must etract RGB b dividing out = is alwas black Some loss of precision as gets small, but generall not a big problem 3
Compositing Assumptions We will combine two images, f and g, to get a third composite image Both images are the same size and use the same color representation Multiple images can be combined in stages, operating on two at a time 4
Basic Compositing Operation At each piel, combine the piel data from f and the piel data from g with the equation: c o Fc f Gc g F and G describe how much of each input image survives, and c f and c g are pre-multiplied piels, and all four channels are calculated To define a compositing operation, define F and G 5
Basic Compositing Operation F and G are simple functions of the alpha values c o F f, g c f G f, g c g F and G are chosen (independentl) Different choices give different operations To code it, ou can write one compositor and give it 6 numbers (3 for F, 3 for G) to sa which function Constant of or f is multiplied b -, or. Similar for g f g f g,,,,,,,,,,,, 6
Sample Images Images Alphas 7
Sample Images Images RGB,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, Alphas.5.5.5.5.5.5 8
Sample Images Images Pre-multiplied RGBA,,,,,.5,.5,.5,.5,,,,,,.5,,.5,,.5,,.5,,.5,,.5,,,.5,.5,,,,,,,, Alphas 9
Over Operator Computes composite with the rule that f covers g F G f c Fc Gc c ( ) c o f g f f g 2
Over Operator c Fc Gc c ( ) c o f g f f g,,,.5,.5,,,,,,,,,,.5,.5,,,,,,.5,.5,, Over.5,,.5.5,,.5.5,,.5,,.25,.5,.75.5,,.5,,,.5,.5,,,,,,,,,,,.5,.5,, f g result 2
Over Operator: Etract RGB Color,,.5,.5,,,,,,,,,.5,.5,.25,.5,.75,.5,.5,,.5,,.5,, Pre-multiplied RGBA,, /3,2/3,,,,,,,,,,,,,,, RGB.5,.5,.25,.5,.75,.5,.5,,.5,,.5,, Alpha 22
Over Operator If there s some f, get f, otherwise get g over = 23
Inside Operator Computes composite with the rule that onl parts of f that are inside g contribute F G g 24
Inside Operator c o Fc f Gc g c g f,,,.5,.5,,,,,,,,,,,.5,.5,,,,,.5,.5,, Over.5,,.5.5,,.5.5,,.5,.5,.5,.25,.25,,,,,.5,.5,,,,,,,,,,,,,, f g result 25
Inside Operator Get f to the etent that g is there, otherwise nothing inside = 26
Outside Operator Computes composite with the rule that onl parts of f that are outside g contribute F G g 27
Outside Operator Get f to the etent that g is not there, otherwise nothing outside = 28
Atop Operator Computes composite with the ove rule but restricted to places where there is some g F G g f 29
Atop Operator Get f to the etent that g is there, otherwise g atop = 3
Xor Operator Computes composite with the rule that f contributes where there is no g, and g contributes where there is no f F G g f 3
Xor Operator Get f to the etent that g is not there, and g to etent of no f or = 32
Clear Operator Computes a clear composite F G Note that (,,,>) is a partiall opaque black piel, whereas (,,,) is full transparent, and hence has no color 33
Set Operator Computes composite b setting it to equal f F G Copies f into the composite 34
Compositing Operations F and G describe how much of each input image survives, and c f and c g are pre-multiplied piels, and all four channels are calculated c o Fc f Gc g Operation F G Over Inside Outside Atop Xor Clear Set g f g g g f f 35
Unar Operators Darken: Makes an image darker (or lighter) without affecting its opacit darken( f, ) ( rf, g f, bf, f ) Dissolve: Makes an image transparent without affecting its color dissolve ( f, ) ( rf, g f, bf, f ) 36
PLUS Operator Computes composite b simpl adding f and g, with no overlap rules c o Useful for defining cross-dissolve in terms of compositing: c f c g cross( f, g, t) dissolve ( f, t) plus dissolve ( g, t) 37
Obtaining Values Hand generate (paint a grascale image) Automaticall create b segmenting an image into foreground background: Blue-screening is the analog method Remarkabl comple to get right Lasso is the Photoshop operation With snthetic imager, use a special background color that does not occur in the foreground Brightest blue or green is common 38
Compositing With Depth Can store piel depth instead of alpha Then, compositing can trul take into account foreground and background Generall onl possible with snthetic imager Image Based Rendering is an area of graphics that, in part, tries to composite photographs taking into account depth 39
Toda More Compositing Non-photorealistic Rendering (NPR) 3D Graphics Toolkits Transformations 4
Painterl Filters Man methods have been proposed to make a photo look like a painting Toda we look at one: Painterl-Rendering with Brushes of Multiple Sizes* Basic ideas: Build painting one laer at a time, from biggest to smallest brushes At each laer, add detail missing from previous laer 4 *Aaron Hertzmann. Painterl rendering with curved brush strokes of multiple sizes, SIGGRAPH 998
Algorithm function paint(sourceimage,r... R n ) // take source and several brush sizes { canvas := a new constant color image // paint the canvas with decreasing sized brushes for each brush radius R i, from largest to smallest do { // Appl Gaussian smoothing with a filter of size const * radius // Brush is intended to catch features at this scale referenceimage = sourceimage * G(fs R i ) // Paint a laer paintlaer(canvas, referenceimage, Ri) } return canvas } 42
Algorithm 2 procedure paintlaer(canvas,referenceimage, R) // Add a laer of strokes { S := a new set of strokes, initiall empt D := difference(canvas,referenceimage) // euclidean distance at ever piel for = to imagewidth stepsize grid do // step in size that depends on brush radius for = to imageheight stepsize grid do { // sum the error near (,) M := the region (-grid/2..+grid/2, -grid/2..+grid/2) areaerror := sum(d i,j for i,j in M) / grid 2 if (areaerror > T) then { // find the largest error point } (,) := ma D i,j in M s :=makestroke(r,,,referenceimage) add s to S } } paint all strokes in S on the canvas, in random order 43
Point Stle Uses round brushes We provide a routine to paint round brush strokes into an image for the project 44
Results Original Biggest brush Medium brush added Finest brush added 45
Where to now We are now done with images We will spend several weeks on the mechanics of 3D graphics Coordinate sstems and Viewing Clipping Drawing lines and polgons Lighting and shading 46
Graphics Toolkits Graphics toolkits tpicall take care of the details of producing images from geometr Input (via API functions): Where the objects are located and what the 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: Piel data in a framebuffer an image in a special part of memor Data can be put on the screen Data can be read back for processing (part of toolkit) 47
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 comple and less well supported 48
A Good Toolkit Everthing is a trade-off Functionalit Compact: a minimal set of commands Orthogonal: commands do different things and can be combined in a consistent wa Speed Ease-of-Use and Documentation Portabilit Etensibilit Standards and ownership Not an ehaustive list 49
Coordinate Sstems The use of coordinate sstems is fundamental to computer graphics Coordinate sstems are used to describe the locations of points in space, and directions in space Multiple coordinate sstems make graphics algorithms easier to understand and implement 5
Coordinate Sstems (2) Different coordinate sstems represent the same point in different was v (2,3) v (,2) u u 5
Transformations Transformations convert points between coordinate sstems v (2,3) u=- v=- v (,2) u =u+ =v+ u 52
Transformations (Alternate Interpretation) Transformations modif an object s shape and location in one coordinate sstem (2,3) =- =- (,2) = + = + The previous interpretation is better for some problems, this one is better for others 53
2D Translation Moves an object 54?????? b b?
2D Translation Moves an object 55 b b b b
2D Scaling Resizes an object in each dimension 56 s s??????
2D Scaling Resizes an object in each dimension 57 s s s s
2D Rotation Rotate counter-clockwise about the origin b an angle 58??????
2D Rotation Rotate counter-clockwise about the origin b an angle 59 cos sin sin cos
X-Ais Shear Shear along ais (What is the matri for ais shear?) 6??????
X-Ais Shear Shear along ais (What is the matri for ais shear?) 6 sh
Reflect About X Ais?????? 62
Reflect About X Ais 63
2D Affine Transformations An affine transformation is one that can be written in the form: 64 b b a a a a b a a b a a or
Composition of Affine Transforms An affine transformation can be composed as a sequence of simple transformations: Translation Scaling (possibl with negative values) Rotation 65
Rotating About An Arbitrar Point What happens when ou rotate an object about an arbitrar point that is not the origin?
Rotating About An Arbitrar Point What happens when ou rotate an object about an arbitrar point that is not the origin?
How Do We Compute It? How do we rotate an about an arbitrar point? Hint: we know how to rotate about the origin of a coordinate sstem
Rotating About An Arbitrar Point (a, b) (, ) (a, b) (, )
Rotating About An Arbitrar Point Sa ou wish to rotate about the point (a,b) You know how to rotate about (,) Translate so that (a,b) is at (,) = a, = b Rotate =(-a)cos-(-b)sin, =(-a)sin+(-b)cos Translate back again f = +a, f = +b
Rotating About An Arbitrar Point Sa R is the rotation matri to appl, and p is the point about which to rotate Translation to Origin: Rotation: Translate back: p R R( p) p R R Rp Rp The translation component of the composite transformation involves the rotation matri. What a mess! p 7
Net Time Composing transformations 3D Transformations Viewing 72