Digital Photography II The Image Processing Pipeline EE367/CS448I: - - PowerPoint PPT Presentation

digital photography ii
SMART_READER_LITE
LIVE PREVIEW

Digital Photography II The Image Processing Pipeline EE367/CS448I: - - PowerPoint PPT Presentation

Digital Photography II The Image Processing Pipeline EE367/CS448I: Computational Imaging and Display stanford.edu/class/ee367 Lecture 4 Gordon Wetzstein Stanford University Review Sensors are Buckets collect photons integrate


slide-1
SLIDE 1

Digital Photography II

Gordon Wetzstein Stanford University EE367/CS448I: Computational Imaging and Display stanford.edu/class/ee367 Lecture 4 The Image Processing Pipeline

slide-2
SLIDE 2

Review – “Sensors are Buckets”

collect photons like a bucket integrate spectrum integrate incident directions

slide-3
SLIDE 3

Bayer pattern

wikipedia

Review – Color Filter Arrays

slide-4
SLIDE 4

Image Formation

i x

( )

≈ l x,θ,λ,t

( )

Ωθ ,λ ,t

∫∫∫

dθdλdt = l x,θ,λ,t

( )

Ωθ ,λ ,t

∫∫∫

c λ

( )ϕ θ ( )dθdλdt

plenoptic function spectral sensitivity

  • f sensor

angle-dependent factor

  • high-dimensional integration over angle, wavelength, time

plenoptic function: [Adelson 1991]

slide-5
SLIDE 5

More Ways to Capture Color

field sequential

wikipedia

multiple sensors vertically stacked

red sensor green sensor blue sensor

Prokudin-Gorsky Foveon X3

slide-6
SLIDE 6

More Ways to Capture Color

  • Russian chemist and photographer
  • used Maxwell’s color photography technique

(1855)

  • commissioned by Tsar Nicholas II, photo-

documented diversity of Russian empire from 1909-1915

  • ~3500 negatives

Alim Khahn, Emir of Bukhara, 1911

Prokudin-Gorsky

slide-7
SLIDE 7

More Ways to Capture Color

  • notable French inventor
  • Nobel price for color photography in

1908 = volume emulsion capturing interference

  • today, this process is most similar to

volume holography!

  • also invented integral imaging (will hear

more…)

Gabriel Lippmann Lippmann’s stuffed parrot

slide-8
SLIDE 8

Three-CCD Camera

Philips / wikipedia

beam splitter prism

slide-9
SLIDE 9

Stacked Sensor

Foveon X3 Sigma SD9

slide-10
SLIDE 10

Other Wavelengths

  • OmniVision:

RGB + near IR!

slide-11
SLIDE 11

Other Wavelengths

nostril pit organ for IR

  • thermal IR
  • ften use Germanium
  • ptics (transparent IR)
  • sensors don’t use

silicon: indium, mercury, lead, etc.

FLIR Systems

slide-12
SLIDE 12

Review: Photons to RAW Image

sensor ADC

(quantization)

amplifier

(gain,ISO)

photon noise additive noise photons RAW image fixed pattern noise quantization “noise”

slide-13
SLIDE 13

Image Processing Pipeline

RAW image (dcraw –D) JPEG image

slide-14
SLIDE 14

Image Processing Pipeline

  • demosaicking
  • denoising
  • digital autoexposure
  • white balancing
  • linear 10/12 bit to 8 bit gamma
  • compression
slide-15
SLIDE 15

Image Processing Pipeline

demosaicking gamut mapping denoising

RAW image JPEG image

compression

… … …

  • dead pixel removal
  • dark frame subtraction (fixed pattern / thermal noise

removal)

  • lens blur / vignetting / distortion correction
  • sharpening / edge enhancement

also:

slide-16
SLIDE 16

Image Processing Pipeline

Marc Levoy, CS 448

slide-17
SLIDE 17

Image Processing Pipeline

Marc Levoy, CS 448

slide-18
SLIDE 18

Exif Meta Data

exchangeable image file format

slide-19
SLIDE 19

Demosaicking (CFA Interpolation)

RAW

image from Kodac dataset Bayer CFA

slide-20
SLIDE 20

Demosaicking (CFA Interpolation)

RAW linear interpolation green channel

image from Kodac dataset

ˆ glin(x,y) = 1 4 g(x + m,y + n)

(m,n)

(m,n) = {(0,−1),(0,1),(−1,0),(1,0)} Bayer CFA

slide-21
SLIDE 21

Demosaicking (CFA Interpolation)

RAW linear interpolation

image from Kodac dataset

slide-22
SLIDE 22

Demosaicking (CFA Interpolation)

image from Kodac dataset

  • riginal

RAW demosaicked

slide-23
SLIDE 23

Demosaicing – Low-pass Chroma

  • sampling problem (despite optical AA filter): (too) high-

frequency red/blue information

  • simple solution: low-pass filter chrominance – humans

are most sensitive to “sharpness” in luminance: 1. apply naïve interpolation 2. convert to Y’CbCr (related to YUV) 3. median filter chroma channels: Cb & Cr 4. convert back to RGB Y’ Cb Cr

slide-24
SLIDE 24

Demosaicing – Low-pass Chroma

demosaic

slide-25
SLIDE 25

Demosaicing – Low-pass Chroma

1.

  • 2. blur
  • 3. Y’CrCb to RGB

demosaic

slide-26
SLIDE 26

Demosaicing – Low-pass Chroma

Y’CrCb to RGB: RGB to Y’CrCb:

Y ' Cb Cr ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = 65.48 128.55 24.87 −37.80 −74.20 112.00 112.00 −93.79 −18.21 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥

M

! " ##### $ ##### R G B ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎛ ⎝ ⎜ ⎜ ⎜ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⎟ ⎟ ⎟ ⋅ 257 65535 + 16 128 128 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ R G B ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = M −1 Y ' Cb Cr ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ − 16 128 128 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎛ ⎝ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⋅ 65535 257

Matlab functions: rgb2ycbcr() and ycbcr2rgb() Pixel values for above equations between 0 and 255!

slide-27
SLIDE 27

Demosaicing – Low-pass Chroma

linear interpolation chrominance filtered

slide-28
SLIDE 28

Demosaicing – Edge-Directed Interpolation

from Gunturk et al. 2005

  • intuitive approach: consider 3x3 neighborhood
  • example: recover missing green pixel
slide-29
SLIDE 29

Demosaicing – Edge-Directed Interpolation

from Gunturk et al. 2005

  • better: consider 5x5 neighborhood
  • example: recover missing green pixel on red pixel
slide-30
SLIDE 30

Demosaicing – Edge-Directed Interpolation

  • insights so far:
  • larger pixel neighborhood may be better, but also more costly
  • using gradient information (edges) may be advantageous, even if

that info comes from other color channels!

  • nonlinear method is okay, but not great – linear would be best!
  • Malvar et al. 2004 – what’s the best linear filter for 5x5 neighborhood?
  • this is implemented in Matlab function demosaic() and part of HW2
slide-31
SLIDE 31

Demosaicing- Malvar et al. 2004

ˆ g(x,y) = ˆ glin(x,y)+αΔR(x,y) ˆ r(x,y) = ˆ r

lin(x,y)+ βΔG(x,y)

ˆ r(x,y) = ˆ r

lin(x,y)+γΔB(x,y)

  • interpolate R at G pixels:
  • interpolate R at B pixels:
  • interpolate G at R pixels:

ΔR(x,y) = r(x,y)− 1 4 r(x + m,y + n)

(m,n)

(m,n) = {(0,−2),(0,2),(−2,0),(2,0)}

red gradient:

  • gain parameters optimized from Kodak dataset: α = 1/ 2, β = 5 / 8,γ = 3/ 4
slide-32
SLIDE 32

Demosaicing - Malvar et al. 2004

  • write out math to get linear filters:
  • use normalized filters in practice,

i.e. scale numbers by sum of filter

slide-33
SLIDE 33

Demosaicing - Malvar et al. 2004

linear interpolation Malvar et al.

slide-34
SLIDE 34

common sources:

  • ut-of-focus blur

geometric distortion spherical aberration chromatic aberration coma

Captured image Input Input

Deblurring

from Heide et al. 2013

slide-35
SLIDE 35

Deblurring

  • solve with ADMM (read details in paper)
  • will discuss deconvolution in more detail next week

http://www.cs.ubc.ca/labs/imager/tr/2013/SimpleLensImaging/

slide-36
SLIDE 36

Denoising

noisy image (Gaussian iid noise, σ=0.2)

  • problem: have noisy image, want

to remove noise but retain high- frequency detail

slide-37
SLIDE 37

Denoising – Most General Approach

idenoised(x) = 1 w(x, ′ x )

all pixels ′ x

inoisy( ′ x )

all pixels ′ x

⋅w(x, ′ x )

  • many (not all) denoising techniques work like this
  • idea: average a number of similar pixels to reduce noise
  • question/difference in approach: how similar are two noisy pixels?
slide-38
SLIDE 38

Denoising – Most General Approach

idenoised(x) = 1 w(x, ′ x )

all pixels ′ x

inoisy( ′ x )

all pixels ′ x

⋅w(x, ′ x )

1. Local, linear smoothing 2. Local, nonlinear filtering 3. Anisotropic diffusion 4. Non-local methods

slide-39
SLIDE 39

Denoising – 1. Local, Linear Smoothing

  • naïve approach: average in local neighborhood, e.g. using a Gaussian

low-pass filter

w(x, ′ x ) = exp − ′ x − x

2

2σ 2 ⎛ ⎝ ⎜ ⎞ ⎠ ⎟

idenoised(x) = 1 w(x, ′ x )

all pixels ′ x

inoisy( ′ x )

all pixels ′ x

⋅w(x, ′ x )

slide-40
SLIDE 40

Denoising – 2. Local, Nonlinear Filtering

  • almost as naïve: use median filter in local neighborhood

idenoised(x) = median W inoisy,x

( )

( )

small window of image centered at

inoisy x

slide-41
SLIDE 41

Denoising

noisy image (Gaussian, σ=0.2) Gaussian Median

σ=0.1 σ=0.3 σ=0.5 w=1 w=3 w=5

slide-42
SLIDE 42

Denoising – 3. Bilateral Filtering

  • more clever: average in local neighborhood, but only average similar

intensities!

w(x, ′ x ) = exp − ′ x − x

2

2σ 2 ⎛ ⎝ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⋅exp − inoisy ′ x

( )− inoisy x ( )

2

2σ i

2

⎛ ⎝ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟

idenoised(x) = 1 w(x, ′ x )

all pixels ′ x

inoisy( ′ x )

all pixels ′ x

⋅w(x, ′ x )

spatial distance distance of intensities

slide-43
SLIDE 43

Denoising – Gaussian Filter

J: filtered output (is blurred) f: Gaussian convolution kernel I: step function & noise

slide-44
SLIDE 44

Denoising – Bilateral Filter

J: filtered output (is not blurred) f: Gaussian convolution kernel I: noisy image (step function & noise) difference in intensity as scale!

Tomasi & Manduchi, 1998

slide-45
SLIDE 45

Denoising – Bilateral Filter

  • riginal image

bilateral filter = “edge-aware smoothing”

slide-46
SLIDE 46

Denoising – Bilateral Filter

noisy image bilateral filter = “edge-aware smoothing”

slide-47
SLIDE 47

Denoising – 4. Non-local Means

  • very powerful approach: exploit self-similarity in image; average pixels

with a similar neighborhood, but don’t need to be close à non-local

w(x, ′ x ) = exp − W inoisy,x'

( )−W inoisy,x ( )

2

2σ 2 ⎛ ⎝ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟

idenoised(x) = 1 w(x, ′ x )

all pixels ′ x

inoisy( ′ x )

all pixels ′ x

⋅w(x, ′ x )

[Buades 2005]

slide-48
SLIDE 48

Denoising – 4. Non-local Means

  • define distance between global

image patches

  • average distant pixels with similar

neighborhood!

idenoised(x) = inoisy( ′ x )

all pixels ′ x

⋅w(x, ′ x )

[Buades 2005]

slide-49
SLIDE 49

Denoising – 4. Non-local Means

noisy Gaussian filtering anisotropic filtering TV bilateral filtering NL-means [Buades 2005]

slide-50
SLIDE 50

Denoising – Other Non-local Method BM3D

  • find similar image patches and group them in 3D blocks
  • apply collaborative filter on all of them:
  • DCT-transform each 3D block
  • threshold transform coefficients
  • inverse transform 3D block

[Dabov 2006]

slide-51
SLIDE 51

Denoising

  • many methods for denoising (check Buades 2005):
  • filtering wavelet or other coefficients
  • total variation denoising
  • patch-based or convolutional sparse coding …
  • state of the art: non-local methods, in particular BM3D
slide-52
SLIDE 52

White Balancing

  • usually the first step in the pipeline (show now for clarity)

lo(λ) = ρ λ

( )li λ ( )

li λ

( )

lo λ

( )

reflectance

slide-53
SLIDE 53

White Balancing

lo(λ) = ρ λ

( )li λ ( )

li λ

( )

lo λ

( )

slide-54
SLIDE 54

White Balancing

i(λ) = lo λ

( ) /li λ ( )

= ρ λ

( )

slide-55
SLIDE 55

White Balancing in Practice

pick predefined setting shoot reference white

Canon menu xrite

slide-56
SLIDE 56

Gamma Correction

  • from linear 10/12 bit to 8 bit (save space)
  • perceptual linearity for optimal encoding with specific bit depth
  • sensitivity to luminance is roughly γ=2.2

perceptually linear spacing!

slide-57
SLIDE 57

Gamma Correction in sRGB

  • standard 8 bit color space of most images, e.g. jpeg
  • roughly equivalent to γ=2.2

CsRGB = 12.92Clinear Clinear ≤ 0.0031308 (1+ a)Clinear

1/2.4 − a

Clinear > 0.0031308 ⎧ ⎨ ⎪ ⎩ ⎪ a = 0.055

linear gamma γ=2.2 CsRGB

slide-58
SLIDE 58

Compression – JPEG (joint photographic experts group)

jpeg – ps quality 0 jpeg – ps quality 2

  • riginal
slide-59
SLIDE 59

Compression – JPEG (joint photographic expert group)

1. transform to YCbCr 2. downsample chroma components Cb & Cr

  • 4:4:4 – no downsampling
  • 4:2:2 – reduction by factor 2 horizontally
  • 4:2:0 – reduction by factor 2 both horizontally and vertically

3. split into blocks of 8x8 pixels 4. discrete cosine transform (DCT) of each block & component 5. quantize coefficients 6. entropy coding (run length encoding – lossless compression)

slide-60
SLIDE 60

Compression – JPEG (joint photographic expert group)

DCT basis functions RLE of “same frequency” coefficients

wikipedia

slide-61
SLIDE 61

Compression – JPEG (joint photographic expert group)

http://xiph.org/~xiphmont/demo/daala/demo1.shtml

slide-62
SLIDE 62

Compression – JPEG (joint photographic expert group)

http://xiph.org/~xiphmont/demo/daala/demo1.shtml

slide-63
SLIDE 63

Compression – JPEG (joint photographic expert group)

http://xiph.org/~xiphmont/demo/daala/demo1.shtml

slide-64
SLIDE 64

Compression – JPEG (joint photographic expert group)

http://xiph.org/~xiphmont/demo/daala/demo1.shtml

slide-65
SLIDE 65

Compression – JPEG (joint photographic experts group)

jpeg – ps quality 0 jpeg – ps quality 2

  • riginal
slide-66
SLIDE 66

Image Processing Pipeline

demosaicking gamut mapping denoising

RAW image JPEG image

compression

… … …

slide-67
SLIDE 67

Notes

  • what we didn’t cover: hundreds of papers in this area, but you get

the idea

  • implement parts of the image processing pipeline in Matlab
slide-68
SLIDE 68

Homework 2

  • calculate and plot depth of field of different cameras
  • implement a simple image processing pipeline in Matlab and

explore demosaicking, denoising, etc.

slide-69
SLIDE 69

Next: Sampling & Deconvolution

  • sampling
  • filtering
  • deconvolution
  • sparse image priors
  • ADMM
slide-70
SLIDE 70

References and Further Reading

Denoising

  • S. Paris,

s, P. Kornprobst st, J.

  • J. Tum

Tumblin, F. Durand “A Gentle Introduction to Bilateral Filtering and its s Applications” s”, SIGGRAPH 2007 course se notes

  • Bu

Buades, M , Morel, “ , “A n non-lo local l alg lgorit ithm for im image denoisi sing”, ”, CVPR 2005

  • Dabov, Foi, Katkovnik, Egiazarian, “Image denoising by sparse 3D transform-domain collaborative filtering”, IEEE Trans. Im. Proc. 2007

Demosaicking

  • Malva

var, H , He, C , Cutl tler, “ , “High-quality y Linear Interpolation for Demosa saicki king of Baye yer-patterned Color Images” s”, Proc. ICASSP 2004

  • Gunturk, Glotzbach, Alltunbasak, Schafer, “Demosaicking: Color Filter Array Interpolation”, IEEE Signal Processing Magazine 2005

Plenoptic function

  • E. Adelson, J. Bergen “The Plenoptic Function and Elements of Early Vision”, Computational Models of Visual Processing, 1991
  • G. Wetzstein, I. Ihrke, W. Heidrich “On Plenoptic Multiplexing and Reconstruction”, Int. Journal on Computer Vision, 2013

Other, potentially interesting work

  • Heide, Steinberger, Tsai, Rouf, Pajak, Reddy, Gallo, Liu, Heidrich, Egiazarian, Kautz, Pulli, “FlexISP: A Flexible Camera Image Processing

Framework”, ACM SIGGRAPH Asia 2014

  • Kodac dataset (especially good and standard for demosaicking): http://r0k.us/graphics/kodak/http://r0k.us/graphics/kodak/