G RADIENT D OMAIN I MAGE P ROCESSING CS 89.15/189.5, Fall 2015 - - PowerPoint PPT Presentation

g radient d omain
SMART_READER_LITE
LIVE PREVIEW

G RADIENT D OMAIN I MAGE P ROCESSING CS 89.15/189.5, Fall 2015 - - PowerPoint PPT Presentation

G RADIENT D OMAIN I MAGE P ROCESSING CS 89.15/189.5, Fall 2015 Wojciech Jarosz wojciech.k.jarosz@dartmouth.edu Problems with direct copy/paste http://www.irisa.fr/vista/Papers/2003_siggraph_perez.pdf CS 89/189: Computational Photography,


slide-1
SLIDE 1

CS 89.15/189.5, Fall 2015

GRADIENT DOMAIN
 IMAGE PROCESSING

Wojciech Jarosz

wojciech.k.jarosz@dartmouth.edu

slide-2
SLIDE 2

Problems with direct copy/paste

CS 89/189: Computational Photography, Fall 2015 2 http://www.irisa.fr/vista/Papers/2003_siggraph_perez.pdf

slide-3
SLIDE 3

Solution: paste gradient

CS 89/189: Computational Photography, Fall 2015 3

hacky visualization of gradient

http://www.irisa.fr/vista/Papers/2003_siggraph_perez.pdf

slide-4
SLIDE 4

http://fstoppers.com/proof-viral-hurricane-shark-photo-in-street-is-fake

CS 89/189: Computational Photography, Fall 2015 4

slide-5
SLIDE 5

Photoshop healing brush

Slightly smarter version of what we learn today

  • higher-order derivative in particular
  • See also


http://www.petapixel.com/2011/03/02/how-to-use- the-healing-brush-and-patch-tool-in-photoshop/

CS 89/189: Computational Photography, Fall 2015 5

slide-6
SLIDE 6

What is a gradient?

Derivative of a multivariate function; for example, for f(x,y) For a discrete image, can be approximated with finite differences

CS 89/189: Computational Photography, Fall 2015 6

f = d f dx, d f dy ⇥ d f dx ≈ f(x + 1, y) − f(x, y) d f dy ≈ f(x, y + 1) − f(x, y)

slide-7
SLIDE 7

Gradient: intuition

CS 89/189: Computational Photography, Fall 2015 7

slide-8
SLIDE 8

Gradients and grayscale images

Grayscale image: n×n scalars Gradient: n×n 2D vectors Two many numbers! What’s up with this?

  • Not all vector fields are the gradient of an

image!

  • Only if they are curl-free (a.k.a. conservative)
  • But we’ll see it does not matter for us

CS 89/189: Computational Photography, Fall 2015 8

slide-9
SLIDE 9

CS 89/189: Computational Photography, Fall 2015 9

Text

Escher, Maurits Cornelis Ascending and Descending 1960 Lithograph 35.5 x 28.5 cm (14 x 11 1/4 in.)

slide-10
SLIDE 10

Color images

3 gradients, one for each channel We’ll sweep this under the rug for this lecture In practice, treat each channel independently

CS 89/189: Computational Photography, Fall 2015 10

slide-11
SLIDE 11

Questions?

CS 89/189: Computational Photography, Fall 2015 11

slide-12
SLIDE 12

Key gradient domain idea

  • 1. Construct a vector field that we wish was

the gradient of our output image

  • 2. Look for an image that has that gradient
  • 3. That won’t work, so look for an image that

has approximately the desired gradient Gradient domain image processing is all about clever choices for (1) and efficient algorithms for (3)

CS 89/189: Computational Photography, Fall 2015 12

slide-13
SLIDE 13

Solution: paste gradient

CS 89/189: Computational Photography, Fall 2015 13

hacky visualization of gradient

http://www.irisa.fr/vista/Papers/2003_siggraph_perez.pdf

slide-14
SLIDE 14

Seamless Poisson cloning

Paste source gradient into target image inside a selected region Make the new gradient as close as possible to the source gradient while respecting pixel values at the boundary

CS 89/189: Computational Photography, Fall 2015 14

paste 
 source 
 gradient 
 here

keep target values here

slide-15
SLIDE 15

Seamless Poisson cloning

Given vector field v (pasted gradient), find the value of f in unknown region that optimizes:

CS 89/189: Computational Photography, Fall 2015

Pasted gradient Mask Background unknown
 region

15

slide-16
SLIDE 16
  • Copy

to

Discrete 1D example: minimization

1 2 3 4 5 6 1 2 3 4 5 6 7

  • 1
  • 1
  • 1

+2 +1

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

  • range: pixel outside the mask

red: source pixel to be pasted blue: boundary conditions (in background)

unknowns

boundary

slide-17
SLIDE 17
  • Copy

to

Discrete 1D example: minimization

1 2 3 4 5 6 1 2 3 4 5 6 7

  • 1
  • 1
  • 1

+2 +1

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

With 
 f1=6
 f6=1

Min [(f2-f1)-1]2 + [(f3-f2)-(-1)]2 + [(f4-f3)-2]2 + [(f5-f4)-(-1)]2 + [(f6-f5)-(-1)]2

slide-18
SLIDE 18

1D example: minimization

  • Copy

to

1 2 3 4 5 6 1 2 3 4 5 6 7

  • 1
  • 1
  • 1

+2 +1

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

Min [(f2-f1)-1]2 + [(f3-f2)-(-1)]2 + [(f4-f3)-2]2 + [(f5-f4)-(-1)]2 + [(f6-f5)-(-1)]2 ==> f22+49-14f2 ==> f32+f22+1-2f3f2 +2f3-2f2 ==> f42+f32+4-2f3f4 -4f4+4f3 ==> f52+f42+1-2f5f4 +2f5-2f4 ==> f52+4-4f5

slide-19
SLIDE 19

1D example: big quadratic

  • Copy

to

  • Min (f22+49-14f2

+ f32+f22+1-2f3f2 +2f3-2f2 + f42+f32+4-2f3f4 -4f4+4f3 + f52+f42+1-2f5f4 +2f5-2f4 + f52+4-4f5) 
 Denote it Q

1 2 3 4 5 6 1 2 3 4 5 6 7

  • 1
  • 1
  • 1

+2 +1

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

slide-20
SLIDE 20

1D example: derivatives

  • Copy

to

1 2 3 4 5 6 1 2 3 4 5 6 7

  • 1
  • 1
  • 1

+2 +1

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

Min (f22+49-14f2 + f32+f22+1-2f3f2 +2f3-2f2 + f42+f32+4-2f3f4 -4f4+4f3 + f52+f42+1-2f5f4 +2f5-2f4 + f52+4-4f5) 
 Denote it Q

slide-21
SLIDE 21

1D example: set derivatives to zero

  • Copy

to

1 2 3 4 5 6 1 2 3 4 5 6 7

  • 1
  • 1
  • 1

+2 +1

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

==> =0 =0 =0 =0

slide-22
SLIDE 22

1D example recap

  • Copy

to

1 2 3 4 5 6 1 2 3 4 5 6 7

  • 1
  • 1
  • 1

+2 +1

1 2 3 4 5 6 1 2 3 4 5 6 7

==>

slide-23
SLIDE 23

Questions?

slide-24
SLIDE 24

Membrane interpolation

  • What if v is null?
  • Laplace equation (a.k.a. membrane equation )
slide-25
SLIDE 25

1D example: minimization

  • Minimize derivatives to interpolate

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

With 
 f1=6
 f6=1

Min (f2-f1)2 + (f3-f2)2 + (f4-f3)2 + (f5-f4)2 + (f6-f5)2

slide-26
SLIDE 26

1D example: derivatives

  • Minimize derivatives to interpolate

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

Min (f22+36-12f2 + f32+f22-2f3f2 + f42+f32-2f3f4 + f52+f42-2f5f4 + f52+1-2f5) 
 Denote it Q

slide-27
SLIDE 27

1D example: set derivatives to zero

  • Minimize derivatives to interpolate

1 2 3 4 5 6 1 2 3 4 5 6 7 ? ? ? ?

==>

slide-28
SLIDE 28

1D example

  • Minimize derivatives to interpolate
  • Pretty much says that second 


derivative should be zero (-1 2 -1) 
 is a second derivative filter

1 2 3 4 5 6 1 2 3 4 5 6 7

slide-29
SLIDE 29

Intuition

  • In 1D; just linear interpolation!
  • Locally, if the second derivative was not zero, this

would mean that the first derivative is varying, which is bad since we want (∇ f)2 to be minimized

  • Note that, in 1D: by setting f'', we leave two degrees of
  • freedom. This is exactly what we need to control the

boundary condition at x1 and x2

x1 x2

slide-30
SLIDE 30

In 2D: membrane interpolation

x1 x2 Not as simple

slide-31
SLIDE 31

Questions?

slide-32
SLIDE 32

What if v is not null?

slide-33
SLIDE 33

What if v is not null?

  • 1D case

Seamlessly paste

  • nto

Just add a linear function so that the boundary condition is respected target f* source g correction f solution f=f+g ^ gap f(x2)-g(x2) gap 
 f(x1)-g(x1)

x1 x2

^

slide-34
SLIDE 34

Matrix structure

denote this matrix A A is large!

  • (# cols = num pixels) x (# rows = num pixels)

but system is sparse!

  • most coefficients will be zero

CS 89/189: Computational Photography, Fall 2015 34

    4

−2 −2

4

−2 −2

4

−2 −2

4         f2 f3 f4 f5     =     16

−6

6 2    

slide-35
SLIDE 35

Solution methods

Direct solve (pseudoinverse)

  • can be numerically unstable and inefficient for

large systems

Orthogonal decomposition methods

  • more stable, but can be slower. e.g. QR decomp.

Iterative methods

  • e.g. steepest descent, conjugate gradients
  • efficient for sparse matrices
  • needs to be symmetric, positive-definite

CS 89/189: Computational Photography, Fall 2015 35

slide-36
SLIDE 36

Convergence

CS 89/189: Computational Photography, Fall 2015 36

gradient
 descent conjugate
 gradients

slide-37
SLIDE 37

Bells and whistles

slide-38
SLIDE 38

Contrast problem

  • Contrast is a multiplicative quantity
  • With Poisson, we try to reproduce linear

differences

  • Loss of contrast if pasting from dark to bright
slide-39
SLIDE 39

Contrast preservation: use the log

  • see A Perception-based Color Space for

Illumination-invariant Image Processing
 http://www.eecs.harvard.edu/~hchong/thesis/color_siggraph08.pdf

  • Or use covariant derivatives (next slides)

Poisson in linear color space Poisson in log color space

slide-40
SLIDE 40

Covariant derivatives & Photoshop

  • Photoshop Healing brush
  • Developed independently from Poisson editing by

Todor Georgiev (Adobe)

From Todor Georgiev's slides http://photo.csail.mit.edu/posters/todor_slides.pdf

slide-41
SLIDE 41

Eye candy

slide-42
SLIDE 42

Result (eye candy)

slide-43
SLIDE 43
slide-44
SLIDE 44
slide-45
SLIDE 45

Manipulate the gradient

  • Mix gradients of g & f: take the max
slide-46
SLIDE 46
slide-47
SLIDE 47
slide-48
SLIDE 48
slide-49
SLIDE 49

Questions?

slide-50
SLIDE 50

Slide credits

Frédo Durand Steve Marschner Matthias Zwicker

CS 89/189: Computational Photography, Fall 2015 50