In-Camera Image Processing for CV
In-Camera Image Processing for CV
Michael S. Brown
National University of Singapore
(York University, Canada)
Tutorial schedule
• Part 1 (General Part)
– Motivation
8.30am-10.25am
– Review of color/color spaces
– Overview of camera imaging pipeline
Coffee Break
• Part 2 (Specific Part) 10.25am – 11am
Motivation for
this tutorial?
Shifting landscape of cameras
4
DSLR/Mirrorless
Film
Market Analysis by
Mayflower Concepts
5
Mobile Phone
Cameras
Market Analysis by
Mayflower Concepts
6
OR ≈
1 50+
7
Image capture is mainstream
8
Not always a good thing . . .
9
Imaging for more than photography
10
Scientist’s view of photography
11
Photo by Uwe Hermann
Scientist’s view of photography
12
Camera = light-measuring device
Illumination source
(radiance)
13
Figure from Digital Image Processing, Gonzales/Woods
Image = radiant-energy measurement
Illumination source
(radiance)
14
Figure from Digital Image Processing, Gonzales/Woods
Assumption used in many places
Shape-from-shading
15
From Jon Mooser, CGIT Lab, USC From O’Reilly’s digital media forum
Camera = light-measuring device?
16
Light-measuring device?
Samsung Galaxy S6 edge HTC One M9
LG G4
Photographs taken from three different cameras with the same aperture, shutter speed,
white-balance , ISO, and picture style.
18
Modern photography pipeline
Scene Radiance
Pre-Camera
Lens Filter In-Camera
Lens CCD response (RAW)
Shutter CCD Demosaicing (RAW)
Aperture
“Photo-finishing Processing”
Starting point:
reality (in radiance)
Final output
Pre-Camera
Lens Filter In-Camera
Lens CCD response (RAW)
Shutter CCD Demosaicing (RAW)
Aperture
“Photo-finishing Processing”
Starting point:
reality (in radiance)
happening on a camera.*
*Camera pipelines are almost always proprietary, so knowing exactly what steps are performed for a
particular make/model is not possible. This tutorial examines the most common steps likely to be found
21
on most cameras.
Tutorial schedule
• Part 1 (General Part)
– Motivation
– Review of color/color spaces
– Overview of camera imaging pipeline
• Part 2* (Specific Part)
– Modeling the in-camera color pipeline
– Photo-refinishing
• Part 3 (Wrap Up)
– The good, the bad, and the ugly of commodity cameras
and computer vision research
– Concluding Remarks
22
* Mainly involves shameless self-promotion of my group’s work.
23
“Crash Course” on
Color & Color Spaces
Color
Def Color (noun): The property possessed by an
object of producing different sensations on the eye
as a result of the way it reflects or emits light.
Oxford Dictionary
24
Color is perceptual
• Color is not a primary physical property
• Red, Green, Blue, Pink, Orange, Atomic Tangerine,
Baby Pink, etc. . .
– Adjectives we assign to “color sensations”
25
[Link]
Subjective terms to describe color
Hue
Name of the color
(yellow, red, blue, green, . . . )
Value/Lightness/Brightness
How light or dark a color is. Hue
Value
Saturation/Chroma/Color Purity
How “strong” or “pure” a color is.
Chroma
Generally wavelengths
from 390 to 700nm are
visible to most individuals
27
“White light” through a prism
“white light”
Refracted light
Prism
Spectral “colors”
Relative Power
Short, Medium,
Long Cones Retina
Optical nerve
Eye
29
Cones and rods
• We have additional light sensitive cells called rods
that are not responsible for color
• Cones are most concentrated on the fovea
30
Spectral power distribution (SPD)
Lettuce SPD
stimulating
S=0.2, M=0.8,
L=0.8
SPD of “real lettuce”
33
Tristimulus color theory
Grassman’s Law states that a source color can be matched by a linear combination
of three independent “primaries”.
Three primaries and the
weights (R1, G1, B1) of each
= R1 + G1 + B1 primary needed to match the
source light #1 perceived
Source light 1 color.
= R2 + G2 + B2
weights (R2, G2, B2) of each
primary needed to match the
source light #2 perceived
Source light 2 color
If we combined source
lights 1 & 2 to get The amount of each primary needed to match the new source
a new source light 3
light 3 will be the sum of the weights that matched lights 1 & 2.
Source light 3 34
Radiometry vs. photometry
• Radiometry
– Quantitative measurements of radiant energy
– Often shown as spectral power distributions (SPD)
– Measures either light coming from a source (radiance) or light falling on a
surface (irradiance)
• Photometry/ colorimetry
– Quantitative measurement of perceived radiant energy based on human’s
sensitivity to light
– Perceived in terms of “brightness” (photometry) and color (colorimetry)
Object
Photometry/
Radiometry
colorimetry
Tomato’s SPD
Perception of the
Wavelength (λ) tomato’s SPD
35
Quantifying color
• We still need a way to quantify color &
brightness
• SPDs go through a “black box” (human visual
system) and are perceived as color
• The only way to quantify the “black box” is to
perform a human study
Wavelength (λ)
36
Experiments for photometry
Relative Power
_
The Luminosity Function (written as y(λ) or V(λ)) shows the eye’s sensitivity to radiant energy
into luminous energy (or perceived radiant energy) based on human experiments
(flicker fusion test).
*International Commission on Illumination (CIE comes from the French name Commission
internationale de l'éclairage) was a body established in 1913 as an authority on light,
illumination and color . . CIE is still active today -- [Link] 38
Colorimetry
• Based on tristimulus color theory, colorimetry
attempts to quantify all visible colors in terms
of a standard set of primaries
= R1 + G1 + B1
39
CIE RGB color matching
+/- Red (700nm)
+/-
Green (546nm)
“Standard Observer”
(Willing participant with no eye disease)
Experiments carried out by 40
W. David Wright (Imperial College) and John Guild (National Physical Laboratory, London) – Late 1920s
CIE RGB color matching
Primary is added to the test color!
+
+/- Red (700nm)
+/-
Green (546nm)
2◦ FoV
For some test colors, no
mix of the primaries could
give a match! For these cases,
the subjects were ask to add Same?
primaries to the test color
to make the match.
42
CIE RGB results
_ _ _
This shows the mixing coefficients x(λ), y(λ), z(λ) for the CIE 1931 2-degree standard
observer XYZ basis computed from the CIE RGB data. Coefficients are all now positive.
Note that the basis XYZ are not physical SPD like in CIE RGB, but linear combinations
defined by the matrix on the previous slide.
45
CIE XYZ 3D plot
• Given two SPDs, if their CIE XYZ values are equal, then they
are considered the same perceived color, i.e.
– I1 (λ), I2 (λ) → (X1, Y1, Z1) = (X2, Y2, Z2) [ perceived as the same color ]
47
SPD to CIE XYZ example
CIE XYZ Values
SPD1
SPD1
X=0.2841
Y=0.2989
From their CIE XYZ
Z=0.3254 mappings, we can
SPD2
determine
SPD2 that these two
SPDs will be
X=0.2841 perceived as the
Two SPDs Y=0.2989 same color (even
Z=0.3254 without needing
to see the color!)
49
Luminance-chromaticity space (CIE xyY)
50
Deriving CIE xyY
Project the CIE XYZ values onto the X=1, Y=1, Z=1 plane.
51
Figure from Ponce and Forsyth
Projection plot
A bit hard to visualize after seeing the
CIE XYZ 3D plot, but we do obtain
the shape on the previous slide from
the projection onto X=1, Y=1, Z=1
52
Projection plot
A bit hard to visualize after seeing the
CIE XYZ 3D plot, but we do obtain
the shape on the previous slide from
the projection onto X=1, Y=1, Z=1
53
CIE x-y chromaticity diagram
In the 1930s, CIE had a bad habit of over using the variables X, Y. Note that x, y are chromaticity coordinates,
54
_ _
x, y (with the bar above) are the matching functions, and X, Y are the imaginary SPDs of CIE XYZ.
CIE x-y chromaticity diagram
Moving along the outside
of the diagram gives
the hues.
Moving way from
the white point
represents more saturation.
55
CIE xyY
• Generally when we use CIE xyY, we only look at the
(x,y) values on the 2D diagram of the CIE x-y
chromaticity chart
• However, the Y value (the same Y from CIE XYZ)
represents the perceived brightness of the color
• With values (x,y,Y) we can reconstruct back to XYZ
𝑌 𝑌
𝑋= 𝑥 𝑍 = (1 − 𝑥 − 𝑦)
𝑦 𝑦
56
Fast forward 80+ years
• CIE 1931 XYZ, CIE 1931 xyY (2-degree standard
observer) color spaces have stood the test of
time
• Many other studies have followed (most
notably - CIE 1965 XYZ 10-degree standard
observer), . . .
• But in the literature (and in this tutorial) you’ll
find CIE 1931 XYZ color space making an
appearance often
57
What is perhaps most amazing?
• 80+ years of CIE XYZ is all down to the
experiments by the “standard observers”
A Standard Observer
58
CIE XYZ is based on 17 Standard Observers
10 by Wright, 7 by Guild
60
Re-quoted from the Mark Meyer’s “Deconstructing Chromaticity” article.
We are done with color, right?
Almost . . .
61
An object’s SPD
• In a real scene, an object’s SPD is a combination of the
its reflectance properties and scene illumination
Tomato SPD
.* .* .*
Wavelength (λ)
62
Color constancy
• Our visual system is able to compensate for
the illumination
Illuminant 1 SPD Illuminant 2 SPD Illuminant 3 SPD
X X X
λ λ
λ
64
Color constancy and illuminants
• To understand color constancy, we have to
consider SPDs of different illuminants
65
Figure from Ponce and Forsyth
Color temperature
• Illuminants are often described by their color temperature
• This is associated with theoretical “blackbody radiators” that produce SPDs
based on a given temperature (expressed in kelvins)
• We often map light sources (both real and synthetic) to their closest color
temperature (esp in Photography/Video production)
66
Color temperature
Typical description of
color temperature used
in photography & lighting
sources.
67
From B&H Photo
Plotted in CIE x-y chromaticity
68
Man made illuminants SPDs
69
Figure from Ponce and Forsyth
CIE standard illuminants
• CIE established several “synthetic” SPDs that serve as proxies for
common real illuminants
• Illuminant A
– tungsten-filament lighting (i.e. a standard light-bulb)
• Illuminant B
– noon sunlight
• Illuminant C
– average daylight
• Illuminant D series
– represent natural daylight at various color temps (5000K, 5500K,
6500K), generally denoted as D50, D55, D65
• Illuminant E
– idea equal-energy illuminant with constant SPD
– does not represent any real light source, but similar to D55
• Illuminant F series
– emulates a variety of fluorescents lamps (12 in total)
70
CIE standard illuminants
SPDs for CIE standard illuminant A, B, C SPDs for CIE standard illuminant D50, D55, D65
SPDs for CIE standard illuminant E SPDs for CIE standard illuminants F2, F8, F11
71
D, E, and F series images from [Link]
White point
• A white point is a CIE XYZ or CIE xyY value of
an ideal “white target” or “white reference”
• This is essentially an illuminants SPD in terms
of CIE XYZ/CIE xyY
– We can assume the white reference is reflecting
the illuminant
• The idea of chromatic adaptation is to make
white points the same between scenes
72
White points in CIE x-y chromaticity
CIE Illuminants
A, B, C, D65, E in terms of CIE x-y
A
CIE x , y
A 0.44757 , 0.40745
C
B 0.34842 , 0.35161
C 0.31006 , 0.31616
B D65 0.31271 , 0.32902
E E 0.33333 , 0.33333
D65
73
Color constancy (at its simplest)
• (Johannes) Von Kries transform
• Compensate for each channel corresponding
to the L, M, S cone response
𝐿2 1/𝐿1𝑤 0 0 𝐿1
𝑀2 = 0 1/𝑀1𝑤 0 𝑀1
𝑆2 0 0 1/𝑆1𝑤 𝑆1
L2, M2, S2 is the new LMS L1w, M1w, S1w is the LMS L1, M1, S1 are the input
response with the illuminant response to “white” under LMS space under an
divided “out”. In this case this illuminant illuminant.
74
white is equal to [1,1,1]
Illuminant to illuminant mapping
• More appropriate would be to map to another illuminant’s LMS
response (e.g. in the desired viewing condition)
• (LMS)1 under an illuminant with white-response (L1w, M1w, S1w)
• (LMS)2 under an illuminant with white-response (L2w, M2w, S2w )
𝐿2 𝐿2𝑤 /𝐿1𝑤 0 0 𝐿1
𝑀2 = 0 𝑀2𝑤 /𝑀1𝑤 0 𝑀1
𝑆2 0 0 𝑆2𝑤 /𝑆1𝑤 𝑆1
Simulation of different “white points” by photographing a “white” object under different illumination.
76
Images courtesy of Sharon Albert (Weizmann Institute)
Example
Here, we have mapped the
two input images to one below
to mimic chromatic adaptation.
Input The “white” part of the cup is
shown before and after to help
show that the illumination falling
on white appears similar after
the “chromatic adaptation”.
Adapted to
“target”
illuminant
77
Now we are finally done with color?
Almost (really) . . .
78
CIE XYZ and RGB
• While CIE XYZ is a canonical color space,
images/devices rarely work directly with XYZ
• XYZ are not real primaries
• RGB primaries dominate the industry
• We are all familiar with the RGB color cube
79
Device specific RGB values
Color Gamut
80
Trouble with RGB
Device 1
Device 2
Device 3
Actual formula is a bit complicated, but effectively this is gamma (I’ = 255*I(1/2.2)), where I’ is
the output intensity and I is the linear sRGB ranged 0-1, with a small linear transfer for
linearized sRGB values close to 0 (not shown in this plot). 84
Gamma justification
• Gamma encoding is used in hardware to compensate for the non-linear
characteristics of cathode ray tubes (CRT).
• The application of the gamma=1/(2.2) will be undone by the CRT’s non-
linear responsible to voltage to beam intensity to produce the desired
result
Gamma to
compensate
for CRT
85
Before (linear sRGB) & after (sRGB)
Final sRGB
Linear sRGB
0.7
0.8 Gamma
NTSC encoding
0.6
(2.2)-1
sRGB 0.6
0.5
0.4 0.4
2.2
0.3
0.2
Gamma
0.2
decoding
0
0 0.2 0.4 0.6 0.8 1
0.1
87
CIE XYZ ↔ NTSC/sRGB
(know your color space!)
Linear-sRGB back to XYZ
It is important to
known which color space
your image is in.
88
CIE XYZ: The mother of color spaces
grand
CIE XYZ
ProPhoto
Adobe RGB
L*ab sRGB NTSC
89
CIE XYZ: The mother of color spaces
grand
CIE XYZ
ProPhoto
Adobe RGB
L*ab sRGB NTSC
Camera
sRGB Image
91
Benefits of sRGB
• Like CIE XYZ, sRGB is a device independent
color space (often called an output color
space)
• If you have two pixels with the same sRGB
values, they will have the same CIE XYZ value,
which means “in theory” they will appear as
the same perceived value
• Does this happen in practice?
92
See for yourself
sRGB values that are the same will be perceived as the same on the screen. However,
from “real scene SPD” to final sRGB, cameras are clearly doing different things.
93
Congratulations!
You
26 June 2016
94
Crash course on color is over!
• A lot of information to absorb
• Understanding colorimetry is required to
understand imaging devices
• CIE XYZ and CIE illuminants will make many
appearances in color imaging/processing
discussions
95
Tutorial schedule
• Part 1 (General Part)
– Motivation
– Review of color/color spaces
– Overview of camera imaging pipeline
• Part 2 (Specific Part)
– Modeling the in-camera color pipeline
– Photo-refinishing
• Part 3 (Wrap Up)
– The good, the bad, and the ugly of commodity cameras
and computer vision research
– Concluding Remarks
96
Overview of the
Camera Imaging Pipeline
97
Pipeline for sRGB (JPEG)
Gain Control
White
A/D Converter
Balance
Possible LUT
AFE – Analog Front End
Sensor with color filter array
Sensor related processing
(CCD/CMOS)
JPEG Save to
Exif File Info storage
Compression
98
* Note that steps can be optional (e.g. noise reduction) or applied in slightly different order.
Pipeline for RAW
Gain Control
Lossless
A/D Converter
Compression
Possible LUT
AFE – Analog Front End
Sensor with color filter array
Sensor related processing
(CCD/CMOS)
99
*Technically speaking, RAW shouldn’t be all caps, it is not an acronym.
Imaging sensor A/D
Gain
etc
White
Balance
100
Imaging sensor A/D
Gain
etc
White
Balance
Basic imaging
sensor design
Microlens
Light to help increase
light collection
on the sensor
Photodiode Silicon/Circuitry
(Photon comes in,
electron pops out)
101
CCD & CMOS
CCD CMOS
CCD (charge coupled device) has a CMOS (complementary metal oxide
different readout technology to convert semiconductor) converts charge to voltage at
charge to voltage and buffer it for output. the pixel site. This allows faster readouts, but
The plus side is there is more space on less space for the photo sensor per pixel.
the pixel for the photo sensor.
102
Figures from Dave Litwiller, “CCD vs. CMOS”, Photonics Spectra, Jan 2001
Camera RGB sensitivity
• The color filter array (CFA) on the camera
filters the light into three primaries
Plotted from camera sensitivity database by Dr. Jinwei Gu from Rochester Institute of Technology (RIT)
103
[Link]
Black light subtraction
• Sensor values for pixels with “no light” should be
zero
• But, often, this is not the case for various reasons
– Cross talk on the sensor, etc. .
– This can also change with sensor temperature
• This can be corrected by capturing a set of pixels
that do not see light
• Place a dark-shield around sensor
• Subtract the level from the “black” pixels
104
Optical black (OB)
Sensor area(s)
capturing
“optical black”
105
Black light capturing areas (likely exaggerated) from Sony US Patent US8227734B2 (Filed 2008) .
Signal amplification (gain)
• Imaging sensor signal is amplified
• Amplification to assist A/D
– Need to get the voltage to the range required to
the desired digital output
• This gain could also be used to accommodate
camera ISO settings
– Unclear if all cameras do this here or use a simple
post-processing gain to the RAW for ISO settings
– DSLR cameras RAW is modified by the ISO setting
106
Defective pixel mask
• CCD/CMOS have pixels that are defective
• Dead pixel masks are pre-calibrated at the factory
– Using “dark current” calibration
– Take an image with no light
– Record locations reporting values to make “mask”
• Bad pixels in the mask are interpolated
• This process seems to happen before RAW is saved
– If you see dead pixels in RAW, these are generally new
dead pixels that have appeared after leaving the factory
107
Example
108
Image courtesy of Lu Zheng (CityU Hong Kong) and Moshe Ben-Ezra (MIT)
Nonlinear response correction
• Some image sensor (generally CMOS) often
have a non-linear response to different
amounts of irradiance
• A non-linear adjustment or look up table (LUT)
interpolation can be used to correct this
109
Other possible distortion correction
110
Ex: Flat field correction
Black level
subtraction and
linearization
111
Ex: Flat field correction
(non-uniform gain)
112
At this stage A/D
Gain
etc
Gain Control
Irradiance
Light IN A/D Converter
Possible LUT
AFE – Analog Front End
Sensor with Color Filter Array
Sensor related processing
(CCD/CMOS)
Digital Value
113
RAW – stop here A/D Lossless
Compression
Gain
etc
TIFF
encoding
(meta data)
CFA
115
WB manual settings
116
Image from [Link]
Examples of manual WB matrices
Nikon D7000
Sunny Incandescent Shade
2.0273 0 0 1.3047 0 0
2.4922 0 0
0 0 0
1.0000 0 1.0000 0
1.0000 0
0 0 0 2.2148
0 1.3906 0 0 1.1367
Canon 1D
Daylight Tungsten Shade
2.0938 0 0
1.4511 0 0 2.4628 0 0
0 0 0
1.0000
1.0000 0 0
1.0000 0
0 0 1.5020 0 0 2.3487 0 0 1.2275
Sony A57K
Daylight Tungsten Shade
2.6836 0 0 1.6523 0 0
3.1953 0 0
0 0 0 0 0
1.0000 1.0000
1.0000 0
0 0 1.5586 0 0 2.7422 0 0 1.2891
117
Auto white balance (AWB)
• If manual white balance is not used, then an
AWB algorithm is performed
• This is not entirely the same as chromatic
adaptation, because it doesn’t have a target
illuminant, instead AWB (as the name implies)
attempts to make what is assumed to be
white map to “pure white”
• Next slides introduce two well known
methods: “Gray World” and “White Patch”
118
AWB: Gray world algorithm
• This methods assumes that average reflectance of a scene is
achromatic (i.e. gray)
– Gray is just the white point not at its brightest, so it serves as an
estimate of the illuminant
– This means that image average should have equal energy, i.e. R=G=B
• Based on this assumption, the algorithm adjusts the input
average to be gray as follows:
Note: # of pixel per channel may be different if white balance is applied to the RAW image before
demosaicing. Some pipelines may also transform into another colorspace, e.g. LMS, to perform the white-
119
balance procedure.
AWB: Gray world algorithm
• Based on averages, white balance can be
expressed as a matrix as:
𝑅′ 𝐺𝑎𝑣𝑔 /𝑅𝑎𝑣𝑔 0 0 𝑅
𝐺′ = 0 1 0 𝐺
𝐵′ 0 0 𝐺𝑎𝑣𝑔 /𝐵𝑎𝑣𝑔 𝐵
Note: some (perhaps most) pipelines may also transform into another colorspace, e.g. LMS, to perform
120
the
white-balance procedure.
AWB: White patch algorithm
• This methods assumes that highlights represent specular
reflections of the illuminant
– This means that maximum R, G, B values are a good estimate of the
white point
• Based on this assumption, the algorithm works as follows:
121
AWB: White patch algorithm
• Based on RGB max, white balance can be
expressed as a matrix as:
𝑅′ 𝐺𝑚𝑎𝑥 /𝑅𝑚𝑎𝑥 0 0 𝑅
𝐺′ = 0 1 0 𝐺
𝐵′ 0 0 𝐺𝑚𝑎𝑥 /𝐵𝑚𝑎𝑥 𝐵
122
AWB example
123
Better AWB methods
• Gray world and white patch are very basic algorithms
– These both tend to fail when the image is dominated by
large regions of a single color (e.g. a sky image)
• There are many improved versions
• Most improvements focus on how to perform these
white point estimation more robustly
• Note: AWB matrix values are often stored in an
images Exif file
124
CFA demosaicing White
Balance
CFA
demos-
acing
Noise
B B B B
R G R G G G G G
R R R R
R R R B
G B G B R R R G
R R R R
R R R B
R G R G R R R G
R R R R
G4 ? G6
G8
B1 G2 B3
R5 G5 = G2 + G4 + G6 + G8
G4 R5 G6
B7 G8 B9 G5 ? 4
B5 ?
Simply interpolate B1 B3 B5 = B1 + B3 + B7 + B9
based on neighbor
values.
? 4
B7 B9
126
Simple “edge aware” interpolation
Case 1
B1 G2 B3 If (|G2–G8) && |(G4-G8)| both < Thres) G2
= G4 G6
G4 R5 G6 G5 = G2 + G4 + G6 + G8
G8
B7 G8 B9 4 All about the same.
G8
G6
G5 = G2 + G8 G2
G4 G6
2
G8
G4 and G6 differ
127
Demosaicing
• These examples are simple algorithms
• Cameras almost certainly use more complex
and proprietary algorithms
• Demosaicing can be combined with additional
processing
– Highlight clipping
– Sharpening
– Noise reduction
128
Noise Reduction (NR) CFA
demos-
acing
Noise
Reduction
Sharpening
129
NR – Rank order statistics
• Sliding window median filter
• Sort all pixels in a 3x3 (or larger) widow about
center pixel by value
• Select median (i.e. pixel #5 in rank)
10 11 10 10 11 10
9 5 10 [5,8,9,9,10,10,10,10,11] 9 10 10
10 8 9 rank #5 10 8 9
input output
Median filter is nice because is preserves edges.
130
NR – Rank order statistics
• Sliding window despeckle filter
• Sort all pixels in a 3x3 (or larger) widow about center
pixel by value
• If center pixel maps to extreme (rank 1 or 9) and is
significantly different than closest neighbor, take
neighboring ranked pixel value
10 11 10 10 11 10
9 19 10 [8,9,9,10,10,10,10,11,19] 9 11 10
10 8 9 10 8 9
rank #9
input output
Center pixel mapped to an extreme.
|Rank 9 (19) – Rank 8 (11)| > threshold
Replace with Rank 8 131
NR + Sharpening
• Another strategy is to apply a blur and add the detail
back in “content regions”, or even boost content to
perform sharpening
Sketch of the procedure here:
NR+Sharpened
Output
Com-
input I B(I) Output
bined
blur input
reduces noise
but blurs edges
For values with high-response
assume this is “content” and
- |I-B(I)| add it back to the blur version
(can even give a slight boost = sharpening).
Subtract I-B If low response, don’t do anything, then
(high pass filter) this region will have NR applied. 132
Input NR
133
Color space manipulation Noise
Reduction
Sharpening
Color
Transform
Tone
• We are now at one of the most crucial Reproduc-
tion
134
Color space transform
• Color Correction Matrix (CCM)
– Transforms sensor native RGB values into some
canonical colorspace (e.g. CIE XYZ) that will
eventual be transform to the final sRGB
colorspace
• It is important that the white-balance has
been performed correctly
135
Color transform conceptually
These LUT used to RAW sensor RGB values Tone-scale and sRGB
correct sensor RAW come in, and sRGB values gamma are applied
come out
Top figure from: Parulski & Spaulding, Chapter 12 “Color image processing for digital camera”, 136
Digital Color Imaging Handbook, 2003
Matrix decompositions
Focusing on the matrix part only.
Conceptually we could breakdown
the color transform in to a series
of transforms. It may desirable
to perform AWB in a different
colorspace, e.g. LMS, then to
sRGB (using CIE XYZ as an intermediate
colorspace to try things together)
138
Examples
Input
140
Note about tone-mapping
• It is worth noting, that up until this stage, our
color values (either RAW or linear sRGB) are
related to incoming light in a linear fashion
• After this step, that relationship is broken
• Unlike the sRGB gamma (which is known), the
tone-mapping is propriety and can only be
found by a calibration procedure
141
JPEG compression Tone
Reproduc-
tion
JPEG
Compress
-ion
142
JPEG approach
f(x,y) - 128
(normalize between –128 to 127)
T(u,v)
Take original image and
Break it into 8x8 blocks Differential 0
coding DC component
Huffman
JPEG bitstream
Encode RLE
AC Vector
Save to
• Exchangeable image file format (Exif) flash
memory
JPEG Save to
Exif File Info storage
Compression
146
* Note that steps can be optional (e.g. noise reduction) or applied in slightly different order.
Pipeline comments
• Again, important to stress that the exact steps
mentioned in these notes only serve as a
guide of common steps that take place
• For different camera makes/models, these
could be performed in different order (e.g.
white-balance after demosaicing) and in
different ways (e.g. combining sharpening
with demosaicing)
147
Color manipulation
Gain Control
White
A/D Converter
Balance
Possible LUT
AFE – Analog Front End
Sensor with Color Filter Array
Sensor related processing
(CCD/CMOS)
149
From the ICC –
ISO 22028
150
From the ICC This describes
a basic digital
ISO 22028 camera pipeline
in more detail.
RGB values
linked to the
device are
considered
“scene referred”.
151
Tone mapping/color rendering
• From the ICC ISO standards, we see this part is
more complex than just matrix + tone-map
• In fact, it can often involve 3D LUTs
3D LUT
(Color
prefer-
ences)
152
Camera image processors
• Steps applied after the sensor output are generally performed
by an “image processor” on the camera
• Different cameras use different processing boards/software
• High-end cameras and associated processors
– Nikon – Expeed
– Fuji – Real photo engine
– Canon – DIGIC
– Sony – BIONZ
– ...
• Mobile-devices
– Qualcomm - Snapdragon
– Nvidia - Tegra
153
Example: Expeed block diagram
154
[Link]
Example: Sony Exmor + BIONZ
155
From Sony’s website
Tutorial schedule
• Part 1 (General Part)
– Motivation
– Review of color/color spaces
– Overview of camera imaging pipeline
• Part 2* (Specific Part)
– Modeling the in-camera color pipeline
– Photo-refinishing
• Part 3 (Wrap Up)
– The good, the bad, and the ugly of commodity cameras
and computer vision research
– Concluding Remarks
156
* Mainly involves shameless self-promotion of my group’s work.
Part 2:
Modeling the onboard
camera color processing
pipeline
Part 2 Acknowledgements
S. J. Kim et al “A New In-Camera Imaging Model for Color Computer Vision and its
158
Application”, IEEE Transactions on Pattern Analysis and Machine Intelligence, Dec 2012
Standard color spaces are great
?
“The real scene” Camera
sRGB Image
sRGB -> CIE XYZ -> Display (ICC Profile)
159
Ideal (simple) camera pipeline
Sensor Image (RAW) sRGB Output
White Color Space
Transform (CST) 1
balance 0.8
3.24 −1.53 0.49 0.6
−0.96 1.87 0.04
0.4
0.05 −0.20 1.05
0.2
0
CIE XYZ 0 0.2 0.4 0.6 0.8 1
Camera-Speficic
White-balanced CST maps from camera Apply sRGB
R/G/B Sensitivity camera-specific color space to CIE XYZ. encoding gamma.
Functions
raw-RGB Then we go to linear-sRGB.
160
161
The world isn’t ideal
Samsung Galaxy S6 edge HTC One M9 LG G4
162
Tone-curve is camera-specific
Sensor Image (RAW)
White Color Space
Transform (CST) 1
balance 0.8
3.24 −1.53 0.49 0.6
−0.96 1.87 0.04
0.4
0.05 −0.20 1.05
0.2
0
CIE XYZ 0 0.2 0.4 0.6 0.8 1
f
CIE XYZ Linear-sRGB
163
Tone-curve is camera-specific
Sensor Image (RAW)
White Color Space
Transform (CST) 1
balance 0.8
3.24 −1.53 0.49 0.6
−0.96 1.87 0.04
0.4
0.05 −0.20 1.05
0.2
0
CIE XYZ 0 0.2 0.4 0.6 0.8 1
f
CIE XYZ Linear-sRGB
165
Nikon D7000 - RAW
166
NEUTRAL
167
STANDARD
168
PORTRAIT
169
LANDSCAPE
170
VIVID
171
Camera = light-measuring device
George Box
Professor Emeritus of Statistics
172
U. Wisconsin
Early work
“Radiometric Calibration”
175
Prior work
Mann and Picard, SPIE’95
Chakrabarti et al conclusions:
RAW is meaningful . . . .
Or is this
i model
rx f (e ) not
r rx e good
enough?
rxE rx
i f (e ) e E
gx = g gx
ibx f (ebx )
gx =
ebx
T gx
Ebx
178
Our experiment: data collection
• More than 10,000 images from 33 cameras from DSLRs to point-and-shoots
179
Lin et al, ICCV 2011; Kim et al, TPAMI 2012
Data collection
More than 10,000 images from 33 cameras
Different Cameras
Different WBs
180
Data collection
More than 10,000 images from 33 cameras
Different Cameras
Different WBs
181
Checked if f is fixed or scene dependent
• How?
• Plot the brightness transfer function (BTF)
– Plot points from image pairs of different scenes
– Each pair has the same ratio, τ , of exposure change
182
Checked if f is fixed or scene dependent
• How?
• Plot the brightness transfer function (BTF)
– Plot points from image pairs of different scenes
– Each pair has the same ratio, τ , of exposure change
183
Checked if f is fixed or scene dependent
• How?
• Plot the brightness transfer function (BTF)
– Plot points from image pairs of different scenes
– Each pair has the same ratio, τ , of exposure change
184
Scene 1
BTF
ki
Exposure ki
Exposure kj
Exposure ki (intensity)
kj
Exposure kj (intensity)
185
Scene 1
BTF
ki
Exposure ki
Exposure kj
Exposure ki (intensity)
Scene 2
kj
Exposure ki
Exposure kj
Scene 3 Exposure kj (intensity)
Exposure ki
Exposure kj 186
Scene 1
BTF ki
Exposure ki
Exposure kj
Exposure ki (intensity)
kj
Scene 2
Exposure ki
Exposure kj
Scene 3 Exposure kj (intensity)
Exposure ki
Exposure kj 187
Scene 1
BTF
Exposure ki
Exposure kj
Exposure ki (intensity)
Scene 2
Exposure ki
Exposure kj
Scene 3 Exposure kj (intensity)
189
For the most part . . . it was ok
outliers
190
Where are the outliners?
191
Gamut mapping
192
Proposed a new model
RAW sRGB
Tw
Ts
White balance (Tw) Gamut mapping Tone mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
193
Proposed a new model
RAW sRGB
Tw
Ts
White balance (Tw) Gamut mapping Tone mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
irx Erx
Introduce h, a 3D function
i f (h T E )
that takes in input RGB and
gx gx
maps it to a new RGB value
ibx E
bx
194
sRGB Image to RAW
f 1 (irx ) erx Erx
1
f (igx ) h egx h T E gx
f 1 (ibx )
= e = E
bx bx
Gamut Mapping
(h)
195
196
RAW sRGB
Tw
Ts
White balance (Tw) Gamut mapping Tone mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
197
RAW sRGB
Tw
Ts
White balance (Tw) Gamut mapping Tone mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
Gamut mapping
Canon EOS1D
199
Experiments : Mapping sRGB back to RAW
Canon EOS1D
200
Experiments : Mapping sRGB back to RAW
201
Experiments : Mapping sRGB back to RAW
Canon EOS550D
202
Experiments : Mapping sRGB back to RAW
Canon EOS550D
203
Experiments : Mapping sRGB back to RAW
Canon EOS1D
204
Experiments : Mapping sRGB back to RAW
Sony A200
205
Experiments : Mapping sRGB back to RAW
Sony A200
206
Experiments : Mapping sRGB back to RAW
Sony A200
207
Application: Photo Refinishing
208
209
RAW sRGB
Tw
Ts
White Balance (Tw) Gamut Mapping Tone Mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
210
RAW sRGB
Tw
Ts
White Balance (Tw) Gamut Mapping Tone Mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
211
RAW sRGB
Tw
Ts
White Balance (Tw) Gamut Mapping Tone Mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
212
RAW sRGB
Tw
Ts
White Balance (Tw) Gamut Mapping Tone Mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
What if you took a photo
with the wrong settings?
213
RAW sRGB
Tw
Ts
White Balance (Tw) Gamut Mapping Tone Mapping
Camera RAW to sRGB (Ts) (h) (f) sRGB
(RAW) (JPEG)
214
RAW sRGB
Tw -1
Ts -1
RAW sRGB
Tw
Ts
Camera sRGB
Tw -1
(RAW) (JPEG)
Ts -1
Photoshop result
218
Result - Canon EOS 1Ds Mark III
Refinished result
219
Result - Canon EOS 1Ds Mark III
Photoshop result
224
Result - Canon EOS 1Ds Mark III
Photoshop result
230
Result – Nikon D200
Refinished result
231
Result – Nikon D200
Photoshop result
236
Result - Sony α200
240
241
Aside: Probabilistic Approach
The mapping of the function, h, is not one-to-one. Chakrabarti et al [TPAMI 2014] has a
nice paper on a probabilistic approach for this inverse mapping problem.
Part 3:
Wrap Up
Image Credit: Timothy Anderson
248
No standard for RAW color space
• RAW is good because it is linear
• However, RAW is a scene-referred color space,
specific to the sensor
• This mean RAW RGB values from image on
difference cameras of the same scene will be
different
249
Example – RAW is not standard
Example
Top: RAW images from three cameras, all of the same scene.
Bot: Error plots showing the pixel-wise L2 difference between camera pairs
250
251
Problems in academic research
1. Lack of understanding of color on cameras
and relationship to “real” color spaces
252
Ugly Example – Color spaces
• Recall our color space transforms
• Camera images are saved in sRGB
253
Ugly examples
254
Ugly examples
255
Ugly examples
256
Analyzing ugly
• One of the most common examples in the
academic literature – obtaining the luminance
(CIE Y) channel from an sRGB image
sRGB CIE Y
257
Analyzing sRGB to luminance (Y)
258
Experimental setup
Generate “true CIE XYZ” images (ground truth)
SPD1
𝑆(x, 𝜆) Chromaticity
y
SPD2 (Y:38, x:0.24, y:0.61)
0.5
0
400 500 600 700
SPD2
Color Matching Functions
CIE XYZ Y 0 SPD1 (Y:50, x:0.56, y:0.37) 𝑥
400 500 600 700
(Luminance)
Scene (Spectral Power Distribution) Image under CIE XYZ color space
259
Test on two types of inputs
SPD1
𝑆(x, 𝜆)
SPD2
260
Generate synthetic camera images
Sensor Image (RAW)
261
Three common mistakes in the literature
(when attempting to map a sRGB camera image to CIE – Y)
262
1. White balance assumption
263
2. Wrong Equations
NTSC is used instead of sRGB (often under the guise of YUV/YIQ)
∗
Correct eq (𝑌 = 0.2126𝑅 + 0.7152𝐺 + 0.0722𝐺)
Average of RGB is used
* YUV/YIQ are actually defined with these weighted coefficients applied on the gamma-encoded
RGB. So, the entire equation is an incorrect interpretation of Y. 264
3. Linearization is incorrect
Sensor Image (RAW)
White- Color Space
Transform (CST) 1
balance 0.8
3.24 −1.53 0.49 0.6
−0.96 1.87 0.04
0.4
0.05 −0.20 1.05
0.2
0
CIE XYZ 0 0.2 0.4 0.6 0.8 1
0.8
0.4
equations 0.2
0
0 0.2 0.4 0.6 0.8 1
Wrong tone-curve
(sRGB gamma)
265
3. Linearization is not applied
Sensor Image (RAW)
White- Color Space
Transform (CST) 1
balance 0.8
3.24 −1.53 0.49 0.6
−0.96 1.87 0.04
0.4
0.05 −0.20 1.05
0.2
0
CIE XYZ 0 0.2 0.4 0.6 0.8 1
0.8
0.4
equations 0.2
0
0 0.2 0.4 0.6 0.8 1
Wrong tone-curve
(sRGB gamma)
266
3. No linearization – “Luma”
‘ ‘ ‘ ‘
‘ ‘ ‘ ‘
‘ ‘ ‘ ‘
267
How ugly is it?
268
White balance not correct
CIE – Y
Nikon camera – white balance is wrong, but we have ideal CST, sRGB gamma
271
Wrong equations (wrong tone-curve)
Commonly found
in academic papers 272
Wrong equations (no linearization)
274
Why bother with CIE-Y?
SIFT
Canny
276
Another ugly problem . . .
• Applying operations in the “wrong” context . . .
277
Camera processing pipeline
Gain Control
A/D Converter White Balance
Possible LUT
Sensor with color filter array
(CCD/CMOS)
JPEG Save to
Exif File Info storage
Compression
sRGB
278
Classic white balance results out-of-context
Reality: image has been run through the pipeline and some non-linear tone-curve f
280
Gamma/tone-curve effect on blur
linear input non-linear input
Tai Y.-W. , Chen X., Kim S., Kim S. J, Li F., Yang J., Yu J., Matsushita Y., Brown M. S. (2013) "Nonlinear Camera
Response Functions and Image Deblurring: Theoretical Analysis and Practice", IEEE Transactions on Pattern Analysis
and Machine Intelligence (TPAMI), 35(10), Oct 2013 281
RAW vs sRGB deblurring
282
State of affairs (The Ugly)
• Many researchers don’t understand camera color
283
284
285
From [Link]
Adobe Digital Negative (DNG)
• Public raw-camera image file specification
287
Android Camera2 API
288
DNG SDK “access” to the pipeline
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
289
sRGB
Matlab platform for color pipeline
manipulation
User has access to the image at each step in
the color processing pipeline.
Matlab
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
292
Reading RAW Image
293
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
294
Black light subtraction + linearization
295
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
296
Lens Correction
(non-uniform gain)
297
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
298
Demosaic
299
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
300
White balance + color space transform
301
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
302
Hue/Sat map application
303
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
304
Exposure curve application
EV+1
305
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
306
3D lookup table application
307
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
308
Tone curve application
309
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
310
Final color space conversion
(CIE XYZ -> linear sRGB)
311
Matlab camera platform / Adobe DNG
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
312
sRGB gamma curve application
313
All together now
Camera RAW
314
All together now
Black level
subtraction and
linearization
315
All together now
Lens correction
316
(non-uniform gain)
All together now
Demosaicing
317
+ Noise Reduction
All together now
White balance
318
+ color space transform (CIE XYZ)
All together now
Hue-saturation
319
adjustment
All together now
Exposure
320
Compensation
All together now
Tone-Curve 321
All together now
• Camera colorimetry
324
“White balance” in context
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
325
sRGB
White balance example
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Transform
327
sRGB
Example - colorimetry
Sensor Image (RAW)
White Color Space
Transform (CST) 1
balance 0.8
3.24 −1.53 0.49 0.6
−0.96 1.87 0.04
0.4
0.05 −0.20 1.05
0.2
0
CIE XYZ 0 0.2 0.4 0.6 0.8 1
328
Calibrate using X-Rite software
329
Four Android cameras
Samsung S6-Edge HTC M9 Motorola Nexus 6 LG-G4
Goal is that the colors for all the cameras are the same.
330
Color chart patches
RAW– (i.e. without any color transformation)
331
Color chart patches
RAW + white balanced and CST from the camera
332
Color chart patches
X-Rite profile calibration (CST)
333
Color chart patches
Our CST estimation
334
Based on a method by Bastani and Funt, SPIE 2014
Applied to other materials
81 Paint chips
335
Additional materials
RAW– (i.e. without any color transformation)
336
Additional materials
RAW (white balanced and CTM of camera)
337
Additional materials
X-rite Profile
338
Additional materials
Our CST estimation
339
True sRGB Example
Demosaicing
Black Light Lens Correction
Reading RAW
Subtraction
Image
Linearization
1 2 3 4
Exposure Curve
White Balance
Application Hue/Sat Map
Noise Reduction
Application Color Space
7 6 5 Conversion
340
sRGB
True sRGB vs. camera RGB
341
True sRGB vs. camera RGB
342
State of affairs (The Good)
• DNG allows access to processing pipeline
parameters
343
Concluding remarks
• Your camera performs a great deal of processing
• RAW
– Represents relatively unprocessed sensor response
– Does not represent CIE XYZ
– Transform to CIE XYZ is not readily available
– There is no standard RAW!
• sRGB
– Is defined with respect to CIE XYZ
– However, incoming radiant energy (SPDs) to sRGB is
not standardize (otherwise all camera images would
look the same)
344
Concluding remarks
• Our experiments found
– Mapping from RAW to sRGB changes for different
picture styles (portrait, landscape, vivid, standard,
etc. . )
– Picture styles can be modeled with a 3D function
+ tone-map
– White-balance (so far) seems independent of
picture styles
345
Good, Bad, Ugly Summary
• Cameras are black boxes
• sRGB is not standard across cameras
• Makes it hard to develop apps
347
Thank you for attending
348
Understanding Color Perception
350
And of course
353
Acknowledgements
This work was supported in part by generous
gifts from:
• Adobe Research
• Google Research (Faculty Award 2015)
354