Image Compositing and Aliasing: Combining Images and Eliminating Jaggies, Study notes of Computer Graphics

Image compositing, a technique for combining multiple images to create a single image. It introduces the concept of alpha channels and different compositing operators. Additionally, it covers aliasing, a common issue in digital imaging, and methods for reducing it through antialiasing techniques such as super-sampling and area-weighted sampling.

Typology: Study notes

Pre 2010

Uploaded on 03/16/2009

koofers-user-1b0-3
koofers-user-1b0-3 🇺🇸

10 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Image Compositing
Often want to combine a sequence of images together
different parts of final image can come from different sources
TV stations have been doing this for a long time
Introduce a new alpha channel in addition to RGB channels
•the αvalue of a pixel indicates its opacity
–if α=0, pixel is totally transparent
–if α=1, pixel is totally opaque
alternatively, can think of αas the fraction of the pixel actually
covered by the stored color
convenient to store colors with αpremultiplied Area α
(, ,, ) ( , , , )rgb r g b
α
αααα
Image Compositing
Compositing one image over another is most common choice
can think of each image drawn on a transparent plastic sheet
the final image is formed by stacking layers together
Given images A& B, we can compute C= Aover B
if we pre-multiply αvalues, this simplifies to
This is only one possible compositing operator
there are in fact 12 possible ways of combining 2 images
()
A
AB
CA B
α
αα
=+1
()
A
CA B
α
=+1
Example: Image Compositing
Given RGB colors and (.,.,.) (,,); .; .
AB
AB
α
α
= 0 8 0 61 0 = 111 =0 5 =0 2
Premultiply: ' (., .,.) ' (., .,.)
AB
AA BB
α
α
= = 040305 = = 020202
over
'''
() ' ( ) '
(.,.,.)
AB
A
CA B
CFAFB
AB
α
=
=+
=1 +1
=050406
() ( )
.(.). .
CAABB
AAB
FF
α
αα
αα
=+
=1 +1
=05+ 0502=06
De-premultiply: '/ ( . , . , . )
C
CC
α
= = 08306710
Read RGB
α
values from frame buffer
Write RGB
α
values back into frame buffer
Aliasing
We are often beset by the problem of aliasing
classic examples come up in rasterization (jaggies)
But aliasing can arise in other contexts
when converting from continuous to discrete representations
We want to get rid of this problem
we need methods for antialiasing
pf3
pf4
pf5
pf8

Partial preview of the text

Download Image Compositing and Aliasing: Combining Images and Eliminating Jaggies and more Study notes Computer Graphics in PDF only on Docsity!

Image Compositing Often want to combine a sequence of images together

  • different parts of final image can come from different sources• TV stations have been doing this for a long time

Introduce a new alpha channel in addition to RGB channels

  • the

α

value of a pixel indicates its opacity

  • if

α=

0, pixel is totally transparent

  • if

α=

1, pixel is totally opaque

  • alternatively, can think of

α

as the fraction of the pixel actually

covered by the stored color

  • convenient to store colors with

α

premultiplied

Area

α

,^

,^

,^

r g b

r

g

b

α

α

α

α

α

Image Compositing Compositing one image over another is most common choice

  • can think of each image drawn on a transparent plastic sheet• the final image is formed by stacking layers together

Given images

A

B

, we can compute

C

A

over

B

  • if we pre-multiply

α

values, this simplifies to

This is only one possible compositing operator

  • there are in fact 12 possible ways of combining 2 images

(^

A

A

B

C

A

B

α

α

α

A

C

A

B

α

Example: Image Compositing

Given RGB colors

and

A

B

A

B

α

α

Premultiply:

'^

'^

A

B

A

A

B

B

α

α

over

'^

'^

'^

A^

B

A

C

A

B

C

F A

F B

A

B

α

(^

.^

C^

A

A

B^

B

A^

A^

B

F

F

α

α

α

α

α

α

De-premultiply:

C

C

C

α

Read RGB

α

values from frame buffer

Write RGB

α

values back into frame buffer

Aliasing We are often beset by the problem of aliasing

  • classic examples come up in rasterization (jaggies)

But aliasing can arise in other contexts

  • when converting from continuous to discrete representations

We want to get rid of this problem

  • we need methods for antialiasing

Jaggies: Spatial Aliasing Jaggies are a particular instance of spatial aliasing

  • converting a spatial function to discrete representation

Note that increasing resolution decreases jaggies

  • consider the following two lines• they come from geometrically identical line descriptions• but are drawn on 300x300 vs. 8x8 grid• the higher resolution one is obviously better

Where Do Jaggies Come From? Our primitives don’t evenly cover all the pixels they touch

  • higher resolution helps because the pixels are smaller• and the amount of fractional coverage is smaller

What pixels do we fill in?

  • all that are completely covered — artificially shrinks object• all that are touched — artificially expands object

Getting Rid of Jaggies The key idea is to use area-weighted sampling

  • instead of simply filling in a pixel or not• compute how much of the pixel is covered by the object• and fill in with an appropriately scaled color
    • e.g., 35% coverage = RGB (0.35, 0.35, 0.35) for a black object– sounds familiar — a lot like alpha values

Getting Rid of Jaggies When we introduce area-weighted sampling

  • we transition from solid color jagged objects• to more smoothly colored objects with multiple tones• when viewed from a proper distance is hopefully smoother

A Closer Comparison

Aliasing in Time Our animations can also experience temporal aliasing

  • the motion of objects does not appear as it should

Consider a spoked wagon wheel

  • suppose it rotates 7/8 around in 1 second• and we take a picture of it every second• it appears to be rotating backwards!

Aliasing in Time In principle, this is the same phenomenon as spatial aliasing

  • converting from continuous to discrete representation• unlucky choice of discrete samples will give us bad results

Can solve the problem in the same way as spatial aliasing

  • temporal supersampling and average• in other words, motion blur

Final Thoughts on Aliasing Unfortunately, we can never really win

  • no matter how much we supersample, aliasing remains• it just gets less and less apparent• and at some point, humans can’t detect it anymore

We’ve skipped over vast amounts of theory

  • can develop rigorous theory of (anti)aliasing
    • based upon signal processing theory (see Foley)
      • in this course, focus on simple antialiasing in practice

Image Processing Construction of an image

B

as a function of an image

A

  • point processing: function of corresponding pixel only

example:

B

[

x,y

] = sqrt(

A

[

x,y

])

  • filtering: function of local neighborhood

example:

B

[

x,y

] =

average of neighbors of

A

[ x,y

]

  • largely based on signal processing theory

Image processing is a key component in:

  • retouching scanned photos (e.g., sharpening)• automatic segmentation (e.g., foreground vs. background)• image compression, particularly lossy schemes like JPEG• and many others …

Simple Point Processing Examples Invert image:

f(p)

= 1−

p

  • for grayscale images, maps black to white and white to black• affect on RGB images is a little less obvious

Grayscale Inversion

RGB Inversion

Simple Point Processing Examples Power law transformation:

f(p)

=

p

k

  • brightens

if

k

< 1

  • identity

if

k

= 1

  • darkens

if

k

1

p

k^ , k

1 0

p

k^ , k

1

k

= 0.

k

= 2.

Image Warping Instead of modifying pixel values, map pixels to new locationsFor example, we might apply a horizontal shearNeed to be careful when computing new image

  • simply moving pixels from source to target can leave holes• typically loop over target pixels and map them backwards into

the source image

'^

'^

x

y

x

f

x y

y

g x y

Using Filter Templates To compute the pixel at location

(x,y)

of the output image

find corresponding

(x,y)

location of input image

pick up local neighborhood matching filter template size

weight each value of the input according to the value in the template

add all the weighted values together

1.01.0 0.

0.4 0.

1

1

1 1 1

1

1 1

1

Blurring Filter Example

3x

5x

9x

Blurring Filter Example: A Closer Look

3x

5x

9x

Image Region Filling Often want to fill a connected region with a specific color

  • especially in interactive paint programs• typically use flood fill: start at a given point and fill all neighbors

which have the same color as the seed point; recurse

  • occasionally use boundary fill: keep filling neighbors until

pixels are reached which have a specified boundary color

Can define neighborhood in different ways

  • 8-connected: all neighboring pixels• 4-connected: only horizontal & vertical

4-connected

8-connected

seed poin

Example Code for Recursive Flood Fill Problem: Recursion depth can be very high

  • various more advanced versions• example: fill entire spans (connected horizontal sequences) at once

void FloodFill4(int x, int y, color oldValue, color newValue){

if( ReadPixel(x, y) == oldValue ){

WritePixel(x, y, newValue);FloodFill4(x, y-1, oldValue, newValue);FloodFill4(x, y+1, oldValue, newValue);FloodFill4(x-1, y, oldValue, newValue);FloodFill4(x+1, y, oldValue, newValue);

}

}

taken from Foley

et al