1 of 32

Nima Kalantari

CSCE 448/748 – Computational Photography

Blending

Many slides from Alexei A. Efros, James Hayes, Rob Fergus

2 of 32

Goal

  • Seamless copy of content from one image to another

3 of 32

Gradient manipulation

  • Observation:
    • Human visual system is sensitive to gradient
    • Gradient encodes edges and local contrast
  • Idea:
    • Do your editing in the gradient domain
    • Reconstruct image from gradient
  • Based on Perez et al. “Poisson Image Editing” SIGGRAPH 2003

Slide credit: F. Durand

4 of 32

Goal

5 of 32

Gradient domain cloning

6 of 32

Gradient blending (1D) – Example 1

source

target

7 of 32

Gradient blending (1D) – Example 1

source

target

8 of 32

Gradient blending (1D) – Example 2

source

target

9 of 32

Gradient blending (1D) – Example 2

It is impossible to faithfully preserve the gradients

source

target

10 of 32

Membrane interpolation

  • Laplace equation (a.k.a. membrane equation)

Slide credit: F. Durand

11 of 32

1D example: minimization

  • Minimize derivatives to interpolate

Slide credit: F. Durand

12 of 32

1D example: minimization

  • Minimize derivatives to interpolate

1

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

1

f0

f1

f2

f3

f4

f5

f6

f7

3

6

0

0

0

0

1

2

*

=

Slide credit: F. Durand

13 of 32

1D example

  • Minimize derivatives to interpolate
  • Pretty much says that second derivative should be zero
  • (-1 2 -1) is a second derivative filter

f0

f1

f2

f3

f4

f5

f6

f7

=

3

6

5

4

3

2

1

2

1

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

1

f0

f1

f2

f3

f4

f5

f6

f7

3

6

0

0

0

0

1

2

*

=

Slide credit: F. Durand

14 of 32

Membrane interpolation

  • Laplace equation (a.k.a. membrane equation)

Slide credit: F. Durand

15 of 32

Seamless Poisson cloning

  • Given vector field v (pasted gradient), find the value of f in unknown region that optimize:
  • Previously, v was null

Pasted gradient

Slide credit: F. Durand

16 of 32

Discrete 1D example: minimization

Slide credit: F. Durand

17 of 32

Discrete 1D example: minimization

1

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

1

f0

f1

f2

f3

f4

f5

f6

f7

3

6

2

-3

3

0

1

2

*

=

Slide credit: F. Durand

18 of 32

Discrete 1D example: minimization

1

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

-1

2

-1

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

1

f0

f1

f2

f3

f4

f5

f6

f7

3

6

2

-3

3

0

1

2

*

=

f0

f1

f2

f3

f4

f5

f6

f7

=

3

6

6

4

5

3

1

2

Slide credit: F. Durand

19 of 32

Simple 2d example

output, x

?

?

?

?

?

?

?

?

?

?

?

?

What properties do we want x to have?

source, s

target, t

mask

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

20 of 32

Simple 2d example

  1. For unmasked pixels, xi = ti
  2. For masked pixels, we want the laplacian at xi to match the laplacian at si

output, x

?

?

?

?

?

?

?

?

?

?

?

?

source, s

target, t

mask

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

21 of 32

Simple 2d example

source, s

target, t

mask

Pixel indexing

1

4

7

10

2

5

8

11

3

6

9

12

output, x

x1 = t1

x2 = t2

x3 = t3

x4 = t4

4x5 – x4 – x2 – x6 – x8 = 4s5 – s4 – s2 – s6 – s8

x6 = t6

x7 = t7

4x8 – x7 – x5 – x9 – x11 = 4s8 – s7 – s5 – s9 – s11

x9 = t9

x10 = t10

x11 = t11

x12 = t12

0

-1

0

-1

4

-1

0

-1

0

Laplacian

?

?

?

?

?

?

?

?

?

?

?

?

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

22 of 32

Simple 2d example

x1 = 0.2

x2 = 0.7

x3 = 0.9

x4 = 0.5

4x5 – x4 – x2 – x6 – x8 = 0.2

x6 = 0.9

x7 = 0.2

4x8 – x7 – x5 – x9 – x11 = -1.6

x9 = 0.8

x10 = 0.2

x11 = 0.7

x12 = 0.9

source, s

target, t

mask

Pixel indexing

1

4

7

10

2

5

8

11

3

6

9

12

output, x

0

-1

0

-1

4

-1

0

-1

0

Laplacian

?

?

?

?

?

?

?

?

?

?

?

?

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

23 of 32

Simple 2d example

4x5 – 0.5 – 0.7 – 0.9 – x8 = 0.2

4x8 – 0.2 – x5 – 0.8 – 0.7 = -1.6

4x5– x8 = 2.3

4x8 – x5 = 0.1

x5 = 0.62

x8 = 0.18

In this simple case, we could solve for everything by hand.

source, s

target, t

mask

Pixel indexing

1

4

7

10

2

5

8

11

3

6

9

12

output, x

0

-1

0

-1

4

-1

0

-1

0

Laplacian

?

?

?

?

?

?

?

?

?

?

?

?

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

x1 = 0.2

x2 = 0.7

x3 = 0.9

x4 = 0.5

4x5 – x4 – x2 – x6 – x8 = 0.2

x6 = 0.9

x7 = 0.2

4x8 – x7 – x5 – x9 – x11 = -1.6

x9 = 0.8

x10 = 0.2

x11 = 0.7

x12 = 0.9

24 of 32

Simple 2d example

*

=

1

1

1

1

-1

-1

4

-1

-1

1

1

-1

-1

4

-1

-1

1

1

1

1

.2

.7

.9

.5

.2

.9

.2

-1.6

.8

.2

.7

.9

A

x

b

?

?

?

?

?

?

?

?

?

?

?

?

source, s

target, t

mask

Pixel indexing

1

4

7

10

2

5

8

11

3

6

9

12

output, x

0

-1

0

-1

4

-1

0

-1

0

Laplacian

?

?

?

?

?

?

?

?

?

?

?

?

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

25 of 32

Simple 2d example

*

=

1

1

1

1

-1

-1

4

-1

-1

1

1

-1

-1

4

-1

-1

1

1

1

1

.2

.7

.9

.5

.2

.9

.2

-1.6

.8

.2

.7

.9

A

x

b

?

?

?

?

?

?

?

?

?

?

?

?

source, s

target, t

mask

Pixel indexing

1

4

7

10

2

5

8

11

3

6

9

12

output, x

0

-1

0

-1

4

-1

0

-1

0

Laplacian

?

?

?

?

?

?

?

?

?

?

?

?

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

A * x = b

A-1A * x = A-1b

x = A-1b

26 of 32

Simple 2d example

*

=

.2

.7

.9

.5

.62

.9

.2

.18

.8

.2

.7

.9

source, s

target, t

mask

Pixel indexing

1

4

7

10

2

5

8

11

3

6

9

12

output, x

0

-1

0

-1

4

-1

0

-1

0

Laplacian

?

?

?

?

?

?

?

?

?

?

?

?

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

1

1

1

1

-1

-1

4

-1

-1

1

1

-1

-1

4

-1

-1

1

1

1

1

.2

.7

.9

.5

.2

.9

.2

-1.6

.8

.2

.7

.9

A

x

b

27 of 32

Simple 2d example

output, x

.2

.5

.2

.2

.7

.62

.18

.7

.9

.9

.8

.9

source, s

target, t

mask

Pixel indexing

1

4

7

10

2

5

8

11

3

6

9

12

0

-1

0

-1

4

-1

0

-1

0

Laplacian

.8

.6

.6

.6

.6

.6

.2

.6

.6

.8

.6

.6

.2

.5

.2

.2

.7

.7

.7

.7

.9

.9

.8

.9

.2

.7

.9

.5

.62

.9

.2

.18

.8

.2

.7

.9

x

28 of 32

Example

source

target

mask

no blending

gradient domain blending

29 of 32

What’s the difference?

no blending

gradient domain blending

-

=

30 of 32

Perez et al. SIGGRAPH 03

31 of 32

Perez et al. SIGGRAPH 03

32 of 32

Mixing gradients

Source

Average

Mixed