Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a...

47
Sampling, Aliasing

Transcript of Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a...

Page 1: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Sampling, Aliasing

Page 2: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Examples of Aliasing

Page 3: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

What is a Pixel?• A pixel is not:

– a box– a disk– a tiny little light

• A pixel “looks different” ondifferent display devices

• A pixel is a sample– it has no dimension– it occupies no area– it cannot be seen– it has a coordinate– it has a value

Page 4: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Philosophical perspective

• The physical world is continuous, inside the computer things need to be discrete

• Lots of computer graphics is about translating continuous problems into discrete solutions – e.g. ODEs for physically-based animation, global

illumination, meshes to represent smooth surfaces, antialiasing

• Careful mathematical understanding helps do the right thing

Page 5: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

More on Samples• The process of mapping a continuous function to a discrete one

is called sampling

• The process of mapping a continuous variable to a discrete one is called quantization

• To represent or render an image using a computer, we must both sample and quantize – Focus on the effects of sampling and how to overcome them

discrete position

discretevalue

Page 6: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Sampling & reconstructionThe visual array of light is a continuous function1/ we sample it

– with a digital camera, or with a ray tracer– This gives us a finite set of numbers,

not really something we can see– We are now inside the discrete computer world

2/ we need to get this back to the physical world: we reconstruct a continuous function– for example, the point spread of a pixel on a CRT or LCD

• Both steps can create problems– But we’ll focus on the first one (you are not display

manufacturers)

Page 7: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Examples of Aliasing

Page 8: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Examples of Aliasing

Page 9: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Examples of Aliasing

Texture Errors

point sampling

Page 10: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Sampling Density

• If we’re lucky, sampling density is enough

Input Reconstructed

Page 11: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Sampling Density

• If we insufficiently sample the signal, it may be mistaken for something simpler during reconstruction (that's aliasing!)

Page 12: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

12

Aliasing insufficient sampling (sampling rate is too small)

• Aliasing: a high-frequency signal masquerading as a low frequency

SamplingInterval

Actual (high-frequency) signal

Sampled (aliased) signal

Page 13: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Discussion

• Two types of aliasing– Edges– Repetitive textures

• More tricky• Harder to solve

Page 14: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Solution?

• How do we avoid the high-frequency patterns distort our image?

• We blur!– For ray tracing: compute at higher resolution, blur,

resample at lower resolution– For textures, we can also blur the texture image

before doing the lookup

Page 15: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

15

Aliasing and Line Drawing

• We draw lines by sampling at intervals of one pixel and drawing the closest pixels

SamplingInterval

SamplingInterval

• Results in stair-stepping

Page 16: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

16

Anti-aliasing Lines

• Idea:– Make line thicker– Fade line out (removes high frequencies)– Now sample the line

Page 17: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

17

Anti-aliasing Lines

Solution – Unweighted Area Sampling:– Treat line as a single-pixel wide rectangle

– Colour pixels according to the percentage of each pixel covered by the rectangle.

Page 18: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

18

Solution : Unweighted Area Sampling

• Pixel area is unit square• Constant weighting function • Pixel colour is determined by computing the amount of

the pixel covered by the line, then shading accordingly• Easy to compute, gives reasonable results

Line

One Pixel

Page 19: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

19

Solution : Weighted Area Sampling

Treat pixel area as a circle with a radius of one pixel Use a radially symmetric weighting function (e.g., cone):

– Areas closer to the pixel centre are weighted more heavily

Better results than unweighted, slightly higher cost

Line

One Pixel

Page 20: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Re-hashing

• Your intuitive solution is to compute multiple colour values per pixel and average them

• A better interpretation of the same idea is that– You first create a higher resolution image– You blur it (average)– You resample it at a lower resolution

Page 21: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Sampling Theorem

• When sampling a signal at discrete intervals, the sampling frequency must be greater than twice the highest frequency of the input signal in order to be able to reconstruct the original perfectly from the sampled version (Shannon, Nyquist, Whittaker, Kotelnikov)

Page 22: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Filters (convolution kernel)• Weighting function

• Area of influence often bigger than "pixel"

• Sum of weights = 1– Each sample contributes

the same total to image

– Constant brightness as object moves across the screen.

• No negative weights

Page 23: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Filters

• Filters are used to – reconstruct a continuous signal from a sampled signal

(reconstruction filters)– band-limit continuous signals to avoid aliasing during

sampling (low-pass filters)

• Desired frequency domain properties are the same for both types of filters

• Often, the same filters are used as reconstruction and low-pass filters

Page 24: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Pre-Filtering• Filter continuous primitives

• Treat a pixel as an area

• Compute weighted amount of object overlap

• What weighting function should we use?

Page 25: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Post-Filtering

• Filter samples• Compute the weighted average of many samples• Regular or jittered sampling (better)

Page 26: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

The Ideal Filter• Unfortunately it has

infinite spatial extent– Every sample contributes

to every interpolated point

• Expensive/impossible to compute spatial

frequency

Page 27: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Problems with Practical Filters

• Many visible artifacts in re-sampled images are caused by poor reconstruction filters

• Excessive pass-band attenuation results in blurry images

• Excessive high-frequency leakage causes "ringing" and can accentuate the sampling grid (anisotropy)

frequency

Page 28: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Gaussian Filter

• This is what a CRTdoes for free!

spatial

frequency

Page 29: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Box Filter / Nearest Neighbour

• Pretending pixelsare little squares.

spatial

frequency

Page 30: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Tent Filter / Bi-Linear Interpolation

• Simple to implement• Reasonably smooth

spatial

frequency

Page 31: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Bi-Cubic Interpolation• Begins to approximate

the ideal spatial filter, the sinc function

spatial

frequency

Page 32: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Ideal sampling/reconstruction

• Pre-filter with a perfect low-pass filter– Box in frequency– Sinc in time

• Sample at Nyquist limit– Twice the frequency cutoff

• Reconstruct with perfect filter– Box in frequency, sinc in time

• And everything is great!

Page 33: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Difficulties with perfect sampling

• Hard to prefilter• Perfect filter has infinite support

– Fourier analysis assumes infinite signal and complete knowledge

– Not enough focus on local effects

• And negative lobes– Emphasizes the two problems above– Negative light is bad– Ringing artifacts if prefiltering or supports are not

perfect

Page 34: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Supersampling in graphics

• Pre-filtering is hard– Requires analytical visibility– Then difficult to integrate

analytically with filter

• Possible for lines, or if visibility is ignored

• usually, fall back to supersampling

Page 35: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

35

Solution: Super-sampling

• Divide pixel up into “sub-pixels”: 22, 33, 44, etc.

• Sub-pixel is coloured if inside line• Pixel colour is the average of its sub-pixel colours• Easy to implement (in software and hardware)

No anti-aliasing Anti-aliasing (22 super-sampling)

Page 36: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

36

Many Types of Supersampling

GridRandom

Poisson Disc Jittered

Page 37: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

37

Polygon Anti-aliasing• To anti-alias a line, we treat it as a rectangle• Anti-aliasing a polygon is similar.• Some concerns:

– Micro-polygons: smaller than a

pixel

– Super-sampling: There may still be polygons that “slip between the cracks”

Page 38: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Uniform supersampling

• Compute image at resolution k*width, k*height• Downsample using low-pass filter

(e.g. Gaussian, sinc, bicubic)

Page 39: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Uniform supersampling• Advantage:

– The first (super)sampling captures more high frequencies that are not aliased

• Issues– Frequencies above the (super)sampling limit are still

aliased

• Works well for edges• Not as well for repetitive textures

Page 40: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Jittering

• Uniform sample + random perturbation• Sampling is now non-uniform• Signal processing gets more complex• In practice, adds noise to image• But noise is better than aliasing Moiré patterns

Page 41: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Jittered supersampling

• Regular, Jittered Supersampling

Page 42: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Jittering

• Displaced by a vector a fraction of the size of the subpixel distance

• Low-frequency Moire (aliasing) pattern replaced by noise

• Extremely effective• Patented by Pixar!

Page 43: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Reconsider Uniform supersampling

• Problem: supersampling only pushes the problem further: The signal is still not bandlimited

• Aliasing still happens

• We need a better solution for high frequency sections of the image

Page 44: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Adaptive sampling• Adjust your sampling rate and/or bucket size on-the-fly,

depending on results of previous samples

– attempt to concentrate more samples in high frequency areas (e.g., edges of objects) and fewer samples in low frequency areas (constant regions)

– get an approximate view of the function by first sampling with a low sampling rate and/or large bucket size over the entire domain

– then use that approximation to estimate where more samples should be taken by focusing on regions of high variance

– generally a recursive process

• Much better than naïve supersampling

Page 45: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Adaptive supersampling

• Use more sub-pixel samples around edges

Page 46: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Adaptive supersampling

• Use more sub-pixel samples around edgesCompute colour at small number of sample

If variance with neighbour pixels is high

Compute larger number of samples

Page 47: Sampling, Aliasing. Examples of Aliasing What is a Pixel? A pixel is not: –a box –a disk –a tiny little light A pixel looks different on different display.

Adaptive supersampling

• Use more sub-pixel samples around edgesCompute colour at small number of sample

If variance with neighbour pixels is high

Compute larger number of samples