Antialiasing & Compositing

Similar documents
Texture mapping from 0 to infinity

Images and Display. Computer Graphics Fabio Pellacini and Steve Marschner

CS 465 Prelim 1. Tuesday 4 October hours. Problem 1: Image formats (18 pts)

Filters. Materials from Prof. Klaus Mueller

CS 775: Advanced Computer Graphics. Lecture 12 : Antialiasing

Matting & Compositing

Sampling and Pyramids

Aliasing and Antialiasing. What is Aliasing? What is Aliasing? What is Aliasing?

To Do. Advanced Computer Graphics. Image Compositing. Digital Image Compositing. Outline. Blue Screen Matting

Computer Graphics (Fall 2011) Outline. CS 184 Guest Lecture: Sampling and Reconstruction Ravi Ramamoorthi

CS6640 Computational Photography. 15. Matting and compositing Steve Marschner

Image Sampling. Moire patterns. - Source: F. Durand

Raster (Bitmap) Graphic File Formats & Standards

Today s lecture is about alpha compositing the process of using the transparency value, alpha, to combine two images together.

Image Scaling. This image is too big to fit on the screen. How can we reduce it? How to generate a halfsized

Announcements. Image Processing. What s an image? Images as functions. Image processing. What s a digital image?

Sampling Theory. CS5625 Lecture Steve Marschner. Cornell CS5625 Spring 2016 Lecture 7

XXXX - ANTI-ALIASING AND RESAMPLING 1 N/08/08

Image Representations, Colors, & Morphing. Stephen J. Guy Comp 575

Antialiasing and Related Issues

What is an image? Images and Displays. Representative display technologies. An image is:

Last Lecture. photomatix.com

BCC Light Matte Filter

8.2 IMAGE PROCESSING VERSUS IMAGE ANALYSIS Image processing: The collection of routines and

Filtering in the spatial domain (Spatial Filtering)

Sampling and reconstruction. CS 4620 Lecture 13

Prof. Vidya Manian Dept. of Electrical and Comptuer Engineering

Midterm Examination CS 534: Computational Photography

1.Discuss the frequency domain techniques of image enhancement in detail.

Last Lecture. photomatix.com

Fireworks Bitmap Graphics Hands on practice notes. Basic Panels to note in Fireworks (Review)

Sampling and Reconstruction

קורס גרפיקה ממוחשבת 2008 סמסטר ב' Image Processing 1 חלק מהשקפים מעובדים משקפים של פרדו דוראנד, טומס פנקהאוסר ודניאל כהן-אור

Image Pyramids. Sanja Fidler CSC420: Intro to Image Understanding 1 / 35

Sampling and reconstruction

Texture Editor. Introduction

Image Processing. What is an image? קורס גרפיקה ממוחשבת 2008 סמסטר ב' Converting to digital form. Sampling and Reconstruction.

Using Curves and Histograms

Image Processing for feature extraction

Matlab (see Homework 1: Intro to Matlab) Linear Filters (Reading: 7.1, ) Correlation. Convolution. Linear Filtering (warm-up slide) R ij

BCC Displacement Map Filter

How to blend, feather, and smooth

Frequency Domain Enhancement

CSC 320 H1S CSC320 Exam Study Guide (Last updated: April 2, 2015) Winter 2015

Sampling and reconstruction

CSE 564: Visualization. Image Operations. Motivation. Provide the user (scientist, t doctor, ) with some means to: Global operations:

CoE4TN4 Image Processing. Chapter 4 Filtering in the Frequency Domain

BCC Displacement Map Filter

Images and Filters. EE/CSE 576 Linda Shapiro

Filtering. Image Enhancement Spatial and Frequency Based

Analysis of the Interpolation Error Between Multiresolution Images

Digital Image Processing. Digital Image Fundamentals II 12 th June, 2017

Image Processing. Image Processing. What is an Image? Image Resolution. Overview. Sources of Error. Filtering Blur Detect edges

CS6670: Computer Vision Noah Snavely. Administrivia. Administrivia. Reading. Last time: Convolution. Last time: Cross correlation 9/8/2009

Prof. Feng Liu. Spring /22/2017. With slides by S. Chenney, Y.Y. Chuang, F. Durand, and J. Sun.

Images and Displays. Lecture Steve Marschner 1

Printing on the Epson You should save a second.psd or tiff version of your image for printing

Digital Image Processing 3/e

Prof. Feng Liu. Fall /04/2018

IMAGE PROCESSING Vedat Tavşanoğlu

Fast Perception-Based Depth of Field Rendering

CS 200 Assignment 3 Pixel Graphics Due Tuesday September 27th 2016, 9:00 am. Readings and Resources

CS448f: Image Processing For Photography and Vision. Fast Filtering Continued

Multimedia Systems Giorgio Leonardi A.A Lectures 14-16: Raster images processing and filters

What will be on the midterm?

BCC Make Alpha Key Filter

Image Interpolation. Image Processing

6. Graphics MULTIMEDIA & GRAPHICS 10/12/2016 CHAPTER. Graphics covers wide range of pictorial representations. Uses for computer graphics include:

Image Filtering. Median Filtering

Matting & Compositing

Using Adobe Photoshop

Development of Image Processing Tools for Analysis of Laser Deposition Experiments

Interactive Computer Graphics

INTRODUCTION TO COMPUTER MUSIC SAMPLING SYNTHESIS AND FILTERS. Professor of Computer Science, Art, and Music

Digital Imaging and Image Editing

Fast Bilateral Filtering for the Display of High-Dynamic-Range Images

Image Matting Based On Weighted Color and Texture Sample Selection

CEE598 - Visual Sensing for Civil Infrastructure Eng. & Mgmt.

Filip Malmberg 1TD396 fall 2018 Today s lecture

Computer Vision, Lecture 3

12 Final Projects. Steve Marschner CS5625 Spring 2016

PHOTO 11: INTRODUCTION TO DIGITAL IMAGING

CSI Application Note AN-525 Speckle Pattern Fundamentals

Image Filtering and Gaussian Pyramids

Vision Review: Image Processing. Course web page:

Digital Image Processing. Lecture 5 (Enhancement) Bu-Ali Sina University Computer Engineering Dep. Fall 2009

PHOTO 11: INTRODUCTION TO DIGITAL IMAGING

Topaz Labs DeNoise 3 Review By Dennis Goulet. The Problem

6.A44 Computational Photography

background confusion map alpha mask. image

Ian Barber Photography

Hand-drawn art. making it digital, making it colourful

Compositing Recipe for Psunami Water

DodgeCmd Image Dodging Algorithm A Technical White Paper

Computational Photography

Registering and Distorting Images

Working with the BCC Displacement Map Filter

Sensing Increased Image Resolution Using Aperture Masks

Raster Images and Displays

Image Enhancement. DD2423 Image Analysis and Computer Vision. Computational Vision and Active Perception School of Computer Science and Communication

Transcription:

Antialiasing & Compositing CS4620 Lecture 14 Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 1

Pixel coverage Antialiasing and compositing both deal with questions of pixels that contain unresolved detail Antialiasing: how to carefully throw away the detail Compositing: how to account for the detail when combining images

Aliasing point sampling a continuous image: continuous image defined by ray tracing procedure continuous image defined by a bunch of black rectangles

Signal processing view Recall this picture:

Signal processing view Recall this picture: we need to do this step

Signal processing view Recall this picture: we need to do this step

Antialiasing A name for techniques to prevent aliasing In image generation, we need to lowpass filter Sampling the convolution of filter & image Boils down to averaging the image over an area Weight by a filter Methods depend on source of image Rasterization (lines and polygons) Point sampling (e.g. raytracing) Texture mapping

Rasterizing lines Define line as a rectangle Specify by two endpoints Ideal image: black inside, white outside

Rasterizing lines Define line as a rectangle Specify by two endpoints Ideal image: black inside, white outside

Point sampling Approximate rectangle by drawing all pixels whose centers fall within the line Problem: all-ornothing leads to jaggies this is sampling with no filter (aka. point sampling)

Point sampling Approximate rectangle by drawing all pixels whose centers fall within the line Problem: all-ornothing leads to jaggies this is sampling with no filter (aka. point sampling)

Point sampling in action

Aliasing Point sampling is fast and simple But the lines have stair steps and variations in width This is an aliasing phenomenon Sharp edges of line contain high frequencies Introduces features to image that are not supposed to be there!

Antialiasing Point sampling makes an all-or-nothing choice in each pixel therefore steps are inevitable when the choice changes yet another example where discontinuities are bad On bitmap devices this is necessary hence high resolutions required 600+ dpi in laser printers to make aliasing invisible On continuous-tone devices we can do better

Antialiasing Basic idea: replace is the image black at the pixel center? with how much is pixel covered by black? Replace yes/no question with quantitative question.

Box filtering Pixel intensity is proportional to area of overlap with square pixel area Also called unweighted area averaging

Box filtering by supersampling Compute coverage fraction by counting subpixels Simple, accurate But slow

Box filtering in action

Weighted filtering Box filtering problem: treats area near edge same as area near center results in pixel turning on too abruptly Alternative: weight area by a smoother filter unweighted averaging corresponds to using a box function sharp edges mean high frequencies so want a filter with good extinction for higher freqs. a gaussian is a popular choice of smooth filter important property: normalization (unit integral)

Weighted filtering by supersampling Compute filtering integral by summing filter values for covered subpixels Simple, accurate But really slow

Weighted filtering by supersampling Compute filtering integral by summing filter values for covered subpixels Simple, accurate But really slow

Gaussian filtering in action

Filter comparison Point sampling Box filtering Gaussian filtering

Antialiasing and resampling Antialiasing by regular supersampling is the same as rendering a larger image and then resampling it to a smaller size Convolution of filter with high-res image produces an estimate of the area of the primitive in the pixel. So we can re-think this one way: we re computing area of pixel covered by primitive another way: we re computing average color of pixel this way generalizes easily to arbitrary filters, arbitrary images

More efficient antialiased lines Filter integral is the same for pixels the same distance from the center line Just look up in precomputed table based on distance Gupta-Sproull Does not handle ends

Antialiasing in ray tracing aliased image

Antialiasing in ray tracing aliased image one sample per pixel

Antialiasing in ray tracing antialiased image four samples per pixel

Antialiasing in ray tracing one sample/pixel 9 samples/pixel

Details of supersampling For image coordinates with integer pixel centers: // one sample per pixel for iy = 0 to (ny-1) by 1 for ix = 0 to (nx-1) by 1 { ray = camera.getray(ix, iy); image.set(ix, iy, trace(ray)); } // ns^2 samples per pixel for iy = 0 to (ny-1) by 1 for ix = 0 to (nx-1) by 1 { Color sum = 0; for dx = -(ns-1)/2 to (ns-1)/2 by 1 for dy = -(ns-1)/2 to (ns-1)/2 by 1 { x = ix + dx / ns; y = iy + dy / ns; ray = camera.getray(x, y); sum += trace(ray); } image.set(ix, iy, sum / (ns*ns)); }

Details of supersampling For image coordinates in unit square // one sample per pixel for iy = 0 to (ny-1) by 1 for ix = 0 to (nx-1) by 1 { double x = (ix + 0.5) / nx; double y = (iy + 0.5) / ny; ray = camera.getray(x, y); image.set(ix, iy, trace(ray)); } // ns^2 samples per pixel for iy = 0 to (ny-1) by 1 for ix = 0 to (nx-1) by 1 { Color sum = 0; for dx = 0 to (ns-1) by 1 for dy = 0 to (ns-1) by 1 { x = (ix + (dx + 0.5) / ns) / nx; y = (iy + (dy + 0.5) / ns) / ny; ray = camera.getray(x, y); sum += trace(ray); } image.set(ix, iy, sum / (ns*ns)); }

Antialiasing in textures Would like to render textures with one (or few) s/p Need to filter first! perspective produces very high image frequencies

When viewed from a distance Aliasing! Also, minification Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 28

How does area map over distance? At optimal viewing distance: One-to-one mapping between pixel area and texel area When closer Each pixel is a small part of the texel When farther Each pixel could include many texels Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 29

How does area map over distance? At optimal viewing distance: One-to-one mapping between pixel area and texel area When closer Each pixel is a small part of the texel When farther Each pixel could include many texels Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 29

How does area map over distance? At optimal viewing distance: One-to-one mapping between pixel area and texel area When closer Each pixel is a small part of the texel When farther Each pixel could include many texels Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 29

How does area map over distance? At optimal viewing distance: One-to-one mapping between pixel area and texel area When closer Each pixel is a small part of the texel When farther Each pixel could include many texels Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 29

Theoretical Solution Find the area of pixel in texture space Filter the area to compute average texture color Filtering eliminates high frequency artifacts How to filter? Analytically compute area But too expensive Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 30

MIP Maps MIP Maps Multum in Parvo: Much in little, many in small places Proposed by Lance Williams Stores pre-filtered versions of texture Supports very fast lookup Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 31

Mipmap image pyramid [Akenine-Möller & Haines 2002] Cornell CS4620/5620 Fall 2013 Lecture 14 32 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan)

Filtering by Averaging Each pixel in a level corresponds to 4 pixels in lower level Average smarter filtering (as in previous lecture) Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 33

Using the MIP Map Find the MIP Map level where the pixel has a 1-to-1 mapping How? Find largest side of pixel footprint in texture space Pick level where that side corresponds to a texel Compute derivatives to find pixel footprint Intuition for derivatives Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 34

Using the MIP Map Find the MIP Map level where the pixel has a 1-to-1 mapping How? Find largest side of pixel footprint in texture space Pick level where that side corresponds to a texel Compute derivatives to find pixel footprint x derivative: y derivative: Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 35

Given derivatives: what is level? Gradients Available in pixel shader (except where there is dynamic branching) Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 36

Using the MIP Map In level, find texel and Return the texture value: point sampling (but still better)! Bilinear interpolation Trilinear interpolation Level i Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 37

Using the MIP Map In level, find texel and Return the texture value: point sampling (but still better)! Bilinear interpolation Trilinear interpolation Level i Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 37

Using the MIP Map In level, find texel and Return the texture value: point sampling (but still better)! Bilinear interpolation Trilinear interpolation Level i Level i+1 Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 37

Interpolation Bilinear interpolation for (u, v) (u0, v0), (u1, v1), (u2, v2), (u3, v3) T0, T1, T2, T3 B(u,v) = (u1-u)[(v-v0) T3 + (v1-v) T0] + (u-u0)[(v-v0) T2 + (v1-v) T1] Trilinear interpolation (d1-d) B(u, v, d0) + (d-d0) B (u, v, d1) Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 38

Memory Usage What happens to size of texture? Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 39

MIPMAP Multi-resolution image pyramid Pre-sampled computation of MIPMAP 1/3 more memory Bilinear or Trilinear interpolation Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 40

Texture minification point sampled minification mipmap minification [Akenine-Möller & Haines 2002] Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan)

Some basic assumptions Can t really precompute every possible required area Assume that pixel only maps to squares in texture space In fact, assume it maps to squares at particular locations Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 42

Anisotropic Filtering Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 43

Anisotropic Filtering GPU supports multiple reads: 16x Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 44

Anisotropic Filtering GPU supports multiple reads: 16x Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 44

Cornell CS4620/5620 Fall 2013 Lecture 14 45 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan)

Antialiasing summary Techniques depend on source of detail Sharp-edged lines and polygons: fractional coverage calculations, supersampling variant: multisample antialiasing samples coverage and depth at a higher rate but still only shades once Ray traced scenes: supersampling variant: adaptive sampling to use more samples only when needed Texture maps: MIP mapping variant: anisotropic lookups for less blurring Cornell CS4620/5620 Fall 2013 Lecture 14 (with previous instructors James/Bala, and some slides courtesy Leonard McMillan) 46

Compositing [Titanic ; DigitalDomain; vfxhq.com]

Combining images Often useful combine elements of several images Trivial example: video crossfade smooth transition from one scene to another A B t = 0 note: weights sum to 1.0 no unexpected brightening or darkening no out-of-range results this is linear interpolation

Combining images Often useful combine elements of several images Trivial example: video crossfade smooth transition from one scene to another A B t =.3 0 note: weights sum to 1.0 no unexpected brightening or darkening no out-of-range results this is linear interpolation

Combining images Often useful combine elements of several images Trivial example: video crossfade smooth transition from one scene to another A B t =.3.6 0 note: weights sum to 1.0 no unexpected brightening or darkening no out-of-range results this is linear interpolation

Combining images Often useful combine elements of several images Trivial example: video crossfade smooth transition from one scene to another A B t =.3.6.8 0 note: weights sum to 1.0 no unexpected brightening or darkening no out-of-range results this is linear interpolation

Combining images Often useful combine elements of several images Trivial example: video crossfade smooth transition from one scene to another A B t =.3.6.8 01 note: weights sum to 1.0 no unexpected brightening or darkening no out-of-range results this is linear interpolation

Foreground and background In many cases just adding is not enough Example: compositing in film production shoot foreground and background separately also include CG elements this kind of thing has been done in analog for decades how should we do it digitally?

Foreground and background How we compute new image varies with position [Chuang et al. / Corel] use foreground use background Therefore, need to store some kind of tag to say what parts of the image are of interest

Binary image mask First idea: store one bit per pixel answers question is this pixel part of the foreground? [Chuang et al. / Corel] causes jaggies similar to point-sampled rasterization same problem, same solution: intermediate values

Binary image mask First idea: store one bit per pixel answers question is this pixel part of the foreground? [Chuang et al. / Corel] causes jaggies similar to point-sampled rasterization same problem, same solution: intermediate values

Binary image mask First idea: store one bit per pixel answers question is this pixel part of the foreground? [Chuang et al. / Corel] causes jaggies similar to point-sampled rasterization same problem, same solution: intermediate values

Partial pixel coverage The problem: pixels near boundary are not strictly foreground or background how to represent this simply? interpolate boundary pixels between the fg. and bg. colors

Alpha compositing Formalized in 1984 by Porter & Duff Store fraction of pixel covered, called α A covers area α B shows through area (1 α) E = A over B r E = A r A +(1 g E = A g A +(1 g E = A g A +(1 this exactly like a spatially varying crossfade Convenient implementation 8 more bits makes 32 2 multiplies + 1 add per pixel for compositing A )r B A )g B A )g B

Alpha compositing example [Chuang et al. / Corel]

Alpha compositing example [Chuang et al. / Corel]

Alpha compositing example [Chuang et al. / Corel]

Compositing composites so far have only considered single fg. over single bg. in real applications we have n layers Titanic example compositing foregrounds to create new foregrounds what to do with α? desirable property: associativity to make this work we need to be careful about how α is computed

Compositing composites Some pixels are partly covered in more than one layer in D = A over (B over C) what will be the result?

Compositing composites Some pixels are partly covered in more than one layer in D = A over (B over C) what will be the result?

Compositing composites Some pixels are partly covered in more than one layer in D = A over (B over C) what will be the result?

Compositing composites Some pixels are partly covered in more than one layer in D = A over (B over C) what will be the result? Fraction covered by neither A nor B

Associativity? What does this imply about (A over B)? Coverage has to be but the color values then don t come out nicely in D = (A over B) over C:

An optimization Compositing equation again c E = A c A +(1 A )c B Note c A appears only in the product α A c A so why not do the multiplication ahead of time? Leads to premultiplied alpha: store pixel value (r, g, b, α) where c = αc E = A over B becomes c 0 E = c 0 A +(1 A )c 0 B this turns out to be more than an optimization hint: so far the background has been opaque!

Compositing composites What about just E = A over B (with B transparent)? in premultiplied alpha, the result E = A +(1 A ) B looks just like blending colors, and it leads to associativity.

Associativity! This is another good reason to premultiply

Independent coverage assumption Why is it reasonable to blend α like a color? Simplifying assumption: covered areas are independent that is, uncorrelated in the statistical sense [Po

Independent coverage assumption Holds in most but not all cases this not this or this This will cause artifacts but we ll carry on anyway because it is simple and usually works

Alpha compositing failures [Chuang et al. / Corel] [Cornell PCG] positive correlation: too much foreground negative correlation: too little foreground

Other compositing operations Generalized form of compositing equation: E = A op B c E = F A c A + F B c B A or 0 A A or B or 0 0 B B or 0 1 x 2 x 3 x 2 = 12 reasonable choices [Po