Fundamentals of Rendering - Image Pipelinevda.univie.ac.at/.../04_imagingPipeline.pdf · Colour...
Transcript of Fundamentals of Rendering - Image Pipelinevda.univie.ac.at/.../04_imagingPipeline.pdf · Colour...
© Machiraju/Möller
Fundamentals of Rendering - Image Pipeline
CMPT 461/761Image Synthesis Torsten Möller
© Machiraju/Möller
Reading• Chapter 23 of “Fundamentals of
Computer Graphics, Third Edition”, 3rd edition by Shirley
• Chapter 5 of “Physically Based Rendering” by Pharr&Humphreys (2nd edition)
• Chapter 12 in Foley, van Dam et al.• “Illumination and Color in Computer
Generated Imagery,” by Roy Hall.2
© Machiraju/Möller
Image Pipeline
SPD XYZ ToneReproduction
RGB
DitherDisplay γ
© Machiraju/Möller
Image Pipeline
SPD
© Machiraju/Möller
Visible Light
5
© Machiraju/Möller
SPD• Light not a single
wavelength• Combination of
wavelengths• A spectrum, or
spectral power distribution (SPD).
Fluorescent light
Lemon skin
© Machiraju/Möller
Image Pipeline
SPD XYZ
© Machiraju/Möller
3-Component Color
• The de facto representation of color on screen display is RGB. (additive color)
• Most printers use CMY(K), (subtractive color)
• Why?– Color spectrum can be represented by 3
basis functions?
© Machiraju/Möller
Human eye and vision
• Eye is an amazing device !– Vision is even more so
• Yet, can trick it rather easily• Need to understand what is important• CG has to be tuned to perception
– Already used three receptor fact – got RGB
© Machiraju/Möller
The eye and the retina
© Machiraju/Möller
Retina detectors• 3 types of color sensors - S, M, L (cones)
– Works for bright light– Peak sensitivities located at approx. 430nm,
560nm, and 610nm for "average" observer.– Roughly equivalent to
blue, green, and red sensors
© Machiraju/Möller
Retina detectors• 1 type of
monochrome sensor (rods)
– Important at low light• Next level: lots of
specialized cells– Detect edges, corners,
etc.
• Sensitive to contrast– Weber’s law: DL ~ L
© Machiraju/Möller
• Contrast:
• For most intensities, contrast of .02 is just noticeable
• We’re sensitive to contrasts, not intensity!
I
I+ΔI
Just Noticeable Differences
€
ΔII
© Machiraju/Möller
Contrast
• Inner gray boxes are the same intensity
© Machiraju/Möller
Contrast sensitivity• In reality, different sensitivity for different
frequencies– Max at ~8 cycles/degree– Look at the pictures in
your book or web pictures• Loose sensitivity
in darkness• More sensitive to
achromatic changes– Try the same but red on green pattern– Practical consequence: color needs fewer bits
• Used in video coding
© Machiraju/Möller
Constancies
• Ability to extract the same information under different conditions– approximately the same info, in fact
• Size constancy: object at 10m vs. 100m• Lightness constancy: dusk vs. noon• Color constancy: tungsten vs. sunlight• Not completely clear how this happens
© Machiraju/Möller
Adaptation
• Partially discard “average” signal– If everything is yellowish – ignore this
• Receptors “getting tired” of the same input
• Need some time to adapt when condition change– Stepping into sunlit outside from inside
• Model “adaptation” to look more realistic– Viewing conditions for monitors might be
very different
© Machiraju/Möller
Tone mapping• Real world range (physical light energy units)• Monitors cover very small part of it• Sensible conversion is needed
– Tone mapping procedure– Book describes a few methods
• Often ignored in many applications– Might calibrate Light = (1,1,1), surface = (0.5, 0.5,
0.5)– No “right” basis for light– Works because of real-world adaptation process
© Machiraju/Möller
Image Pipeline
SPD XYZ ToneReproduction
© Machiraju/Möller
~105cd/m2~10-5 cd/m2
Tone Reproduction
~100 cd/m2~1 cd/m2
Same Visual Response ?
Real world
Monitors
© Machiraju/Möller
Ranges
© Machiraju/Möller
High Dynamic Range (HDR)• The range of light in
the real world spans 10 orders of magnitude!
• A single scene’s luminance values may have as much as 4 orders of magnitude difference
• A typical CRT can only display 2 orders of magnitude
• Tone-mapping is the process of producing a good image of HDR 2002 Reinhard et al
© Machiraju/Möller
Approaches• Tone Reproduction or Mapping• Mapping from image Yw to display luminance
Yd
• Use a scale factor to map pixel values
• Spatially uniform vs spatially varying?– Spatially uniform – monotonic, single factor s– Non-uniform – scale (s) varies
• Histogram methods€
Yd x,y( ) = s x,y( )Yw x,y( )
© Machiraju/Möller24The Tetons and the Snake River (1942) - Ansel Adams
© Machiraju/Möller
Zone System• Used by Ansel Adams. Utilizes measured
luminance to produce a good final print• Zone: an approximate luminance level. There
are 11 print zones• Middle-grey: Subjective middle brightness
region of the scene, typically map to zone V• Key: Subjective lightness or darkness of a
scene
2002 Reinhard et al
© Machiraju/Möller
Zone System
• Measure the luminance on a surface perceived as middle-gray - map to zone V
• If dynamic range < 9 zones then full range can be captured in print
• All light outside these zones is mapped to either white (zone X) or black (zone 0)
• Otherwise withhold or add light in development to lighten or darken the final print
© Machiraju/Möller
Examples - Zone Mapping
2002 Reinhard et al
© Machiraju/Möller
Examples - Zone Mapping
2002 Reinhard et al
© Machiraju/Möller
Running Example
12 Zones 2002 Reinhard et al
© Machiraju/Möller
Scaling Factor
• Which scaling factor to use?– Photographic– Maximum-to-white– Contrast based– High-contrast operator
• What neighborhood to base it on?– Global– Local - uniform– Local - adaptive
© Machiraju/Möller
€
Yd (x,y) = s ⋅Yw (x,y) =aYwa ⋅Yw (x,y)
Photographic Scaling• In a normal-key image middle-gray maps
to a key value a = .18 suggesting the function:
• Ya is the adaptation luminance (some kind of average)
© Machiraju/Möller
Photographic Maps
2002 Reinhard et al
© Machiraju/Möller
Maximum-to-White Scaling• Map brightest pixel to max luminance of
display
• Problems for very well lit scenes• Nothing about the
visual system€
s x,y( ) = sm =max Yd( )max Yw( )
2004 Pharr & Humphrey
© Machiraju/Möller
Maximum-to-White Maps
s=10sm
2004 Pharr & Humphrey
2004Pharr & Humphrey 2004 Pharr & Humphrey
s=100sm
© Machiraju/Möller
Contrast Based• Our eye is sensitive to contrast, NOT to total
luminance• Idea: scale contrast in image to contrast on the
screen (or print etc).• What is the smallest noticeable difference of
luminance in the image? Map this to the smallest noticeable difference on the display.
• JND – Just noticable difference• ΔY(Ya) is the JND for adaptation luminance
Ya
© Machiraju/Möller
Contrast Based• Mapping:• How to measure ΔY(Ya)?
• Hence:
€
ΔY Y a( ) = 0.0594 1.219 + Y a( )0.4( )
2.5
€
sc =1.219 + Yd
a( )0.4
1.219 + Ywa( )0.4
⎛
⎝
⎜ ⎜
⎞
⎠
⎟ ⎟
2.5€
ΔY Yda( ) = s ⋅ ΔY Yw
a( )
s=100sm s=sc
2004 Pharr & Humphrey 2004 Pharr & Humphrey
© Machiraju/Möller
High Contrast Operator• TVI – threshold vs. intensity• JND(Ya) very similar to TVI(Ya)• Perceptual capacity = given a particular Ya,
how many JND’s are covered by a particular luminance range:
• Using
• We can• Hence, we can use this mapping
€
Y1 −Y2TVI Y a( )
€
C Y( ) =dY
TVI Y( )0
Y∫
€
Y1 −Y2TVI Y a( )
= C Y1( ) −C Y2( )
€
Yd x,y( ) =Ydmax C Yw( ) −C Ymin( )
C Ymax( ) −C Ymin( )
© Machiraju/Möller
Adaptation Luminance
• Use log-average luminance to approximate adaptation luminance
• Use log since small bright areas do not influence unduly
€
Ywa = exp 1
Nlog δ +Yw (x,y)( )
x,y∑
⎛
⎝ ⎜ ⎜
⎞
⎠ ⎟ ⎟
© Machiraju/Möller
Global vs. Local• Global - Contrast Operator• Local - Uniform radius for adaptation
luminance– Radius with roughly 10 pixels in the
example– Halo artifacts
global sc
2004 Pharr & Humphrey 2004 Pharr & Humphrey
local sc
© Machiraju/Möller
Spatially Non-Uniform Maps
• Idea - enlarge neighborhood until the contrast in this local neighborhood becomes to large
• B(x,y) = blurred version of image• Local contrast lc(x,y):
• With blur radius r
€
lcr x,y( ) =Br x,y( ) − B2r x,y( )
Br x,y( )
© Machiraju/Möller
Size of Local Neighborhood
2002 Reinhard et al
© Machiraju/Möller
Size of Local Neighborhood
2002 Reinhard et al
© Machiraju/Möller
Spatially Non-Uniform Maps• Find largest r, such that • Now we pick• This in combination with the high-
contrast operator:€
lcr x,y( ) < ε
€
Y a x,y( ) = Br x,y( )
2004 Pharr & Humphrey
© Machiraju/Möller
Neighborhood Sizes
• Small radius - black
• lc for r=1.5 pixel
© Machiraju/Möller
Ad-hoc approach
• Scale factor s independent on (x,y), but dependent on Y– Bring everything within range– Leave dark areas alone
• In other words– Should be a curve from 0..1– Asymptote at 1– Derivative of 1 at 0
© Machiraju/Möller
Ad-hoc approach
• Simple example
€
Yd x,y( ) = s x,y( ) ⋅Yw x,y( ) =1
1+Yw x,y( )Yw x,y( )
© Machiraju/Möller
Global Operator Results
8 Zones 7 Zones2002 Reinhard et al2002 Reinhard et al
© Machiraju/Möller
Global Operator Results
12 Zones 2002 Reinhard et al
© Machiraju/Möller
Global Operator Results
15 Zones
2002 Reinhard et al
© Machiraju/Möller
Ad-hoc approach• Control burn out of high luminance –
global operator (Ywhite is the smallest luminance mapped to pure white)
€
Yd x,y( ) = s x,y( ) ⋅Yw x,y( ) =1+
Yw x,y( )Ywhite2
1+Yw x,y( )Yw x,y( )
© Machiraju/Möller
Controlled Burn-out is OK
No detail expected when looking into the sun (sunspots)
2002 Reinhard et al
© Machiraju/Möller
Local Adaptation
• Need a properly chosen neighborhood• Dodging-and-burning is applied to
regions bounded by large contrasts€
Yd x,y( ) = s x,y( ) ⋅Yw x,y( ) =1
1+ Br x,y( )Yw x,y( )
© Machiraju/Möller
Local Operator Results
15 Zones
Light bulb visible Small halo
around lamp shade
Text on book visible2002 Reinhard et al
© Machiraju/Möller
Automatic Dodging-and-Burning
• Details recovered by using dodging-and-burning
2002 Reinhard et al
© Machiraju/Möller
Durand et al. Reinhard et al.
Comparison
© Machiraju/Möller
Durand et al. Reinhard et al.
Comparison
© Machiraju/Möller
Image Pipeline
SPD XYZ ToneReproduction
RGB
© Machiraju/Möller
Colour Systems• Response:• Detector response is linear
– Scaled input -> scaled response– response(L1+L2) = response(L1)+response(L2)
• Choose three basis lights L1, L2, L3– Record responses to them– Can compute response to any linear combination– Tristimulus theory of light
• Most color systems are just a different choice of basis lights
– Could have “RGB” lights as a basis
© Machiraju/Möller
Colour Systems
• Our perception registers:– Hue– Saturation– Lightness or brightness
• Artists often specify colours in terms of– Tint– Shade– Tone
© Machiraju/Möller
Tristimulus Response• Given spectral power distribution S(λ)
• Given S1, S2: if the X, Y, and Z responses are the same then they are metamers wrt to the sensor
© Machiraju/Möller
CIE Standard
• CIE: International Commission on Illumination (Comission Internationale de l’Eclairage).
• Human perception based standard (1931), established with color matching experiment
• Standard observer: a composite of a group of 15 to 20 people
© Machiraju/Möller
CIE Color Matching Experiment
• Basis for industrial color standards and “pointwise” color models
© Machiraju/Möller
CIE Experiment
© Bill Freeman
© Machiraju/Möller
CIE Experiment Result
• Three pure light sources: R = 700 nm, G = 546 nm, B = 438 nm.
• r, g, b can be negative
© Machiraju/Möller
CIE Experiment
© Bill Freeman
© Machiraju/Möller
CIE Color Space• 3 hypothetical light sources,
X, Y, and Z, which yield positive matching curves
• Use linear combinations of real lights (e.g. –R, G-2R,B+R)
– One of the lights is grey and has no hue
– Two of the lights have zero luminance and provide hue
• Y: roughly corresponds to luminous efficiency characteristic of human eye
© Machiraju/Möller
CIE tristimulus values
• Particular way of choosing basis lights– Gives rise to a standard !!!
• Gives X, Y, Z colour values– Y corresponds to achromatic (no colour)
channel• Chromaticity values:
– x=X/(X+Y+Z); y=Y/(X+Y+Z)– Typically use x,y,Y
© Machiraju/Möller x, y: hue or chromatic part
Chromaticity• Normalize XYZ by
dividing by luminance
• Project onto X+Y+Z=1
• Doesn’t represent all visible colors, since luminous energy is not represented
© Machiraju/Möller
Chromaticity
© Machiraju/Möller
Color Gamut
• area of colors that a physical device can represent
• hence - some colors can't be represented on an RGB screen
© Machiraju/Möller
Color Gamut
© Machiraju/Möller
Color Gamut
• no triangle can lie within the horseshoe and cover the whole area
© Machiraju/Möller
RGB <-> XYZ
• Just a change of basis• Need detailed monitor information to do
this right– Used in high quality settings (movie
industry, lighting design, publishing)• Normalized (lazy) way:
– (1,1,1) in RGB <-> (1,1,1) in XYZ– matrices exist
€
XYZ
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
=
0.5149 .3244 .16070.2654 .6704 .06420.0248 .1248 .8504
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
RGB
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
© Machiraju/Möller
The RGB Cube
• RGB color space is perceptually non-linear
• Dealing with > 1.0 and < 0 !• RGB space is a subset of the
colors human can perceive• Con: what is ‘bloody red’
in RGB?
© Machiraju/Möller
Other colour spaces• CMY(K) – used in printing• LMS – sensor response• HSV – popular for artists• Lab, UVW, YUV, YCrCb, Luv, • Opponent color space – relates to brain input:
– R+G+B(achromatic); R+G-B(yellow-blue); R-G(red-green)
• All can be converted to/from each other– There are whole reference books on the subject
© Machiraju/Möller
Differences in Color Spaces
• What is the use? For display, editing, computation, compression, …?
• Several key (very often conflicting) features may be sought after:– Additive (RGB) or subtractive (CMYK)– Separation of luminance and chromaticity– Equal distance between colors are equally
perceivable (Lab)
© Machiraju/Möller
CMY(K): printing• Cyan, Magenta, Yellow (Black) –
CMY(K)• A subtractive color modeldye color absorbs reflects
Cyan red blue and green
Magenta green blue and red
yellow blue red and green
Black all none
© Machiraju/Möller
RGB and CMY
• Converting between RGB and CMY
€
CMY
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
=
111
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
−
RGB
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
€
CMYK
⎡
⎣
⎢ ⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥ ⎥
=
max(R,G,B)max(R,G,B)max(R,G,B)
1
⎡
⎣
⎢ ⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥ ⎥
−
RGB
max(R,G,B)
⎡
⎣
⎢ ⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥ ⎥
© Machiraju/Möller
RGB and CMY
© Machiraju/Möller
Primary Colors
© Machiraju/Möller
© Machiraju/Möller
Secondary Colors
© Machiraju/Möller
Tertiary Colors
© Machiraju/Möller
HSV
© Machiraju/Möller
HSV
© Machiraju/Möller
HSV
• This colour model is based on polar coordinates, not Cartesian coordinates.
• HSV is a non-linearly transformed (skewed) version of RGB cube– Hue: quantity that distinguishes colour
family, say red from yellow, green from blue– Saturation (Chroma): colour intensity
(strong to weak). Intensity of distinctive hue, or degree of colour sensation from that of white or grey
– Value (luminance): light colour or dark colour
© Machiraju/Möller
HSV Hexcone
• Intuitive interface to color
© Machiraju/Möller
Munsell Atlas
Courtesy Gretag-Macbeth 88
© Machiraju/Möller
Interactive Munsell Tool
• From www.munsell.com
Courtesy of Maureen Stone
89
© Machiraju/Möller
Luv and UVW
• A color model for which, a unit change in luminance and chrominance are uniformly perceptible
• Chrominance is defined as the difference between a color and a reference white at the same luminance.
• Luv is derived from UVW and Lab, with all components guaranteed to be positive
90
© Machiraju/Möller
Yuv and YCrCb: digital video• Initially, for PAL analog video, it is now also
used in CCIR 601 standard for digital video • Y (luminance) is the CIE Y primary.
Y = 0.299R + 0.587G + 0.114B • It can be represented by U and V -- the color
differences. U = B – Y; V = R - Y
• YCrCb is a scaled and shifted version of YUV and used in JPEG and MPEG (all components are positive)
Cb = (B - Y) / 1.772 + 0.5; Cr = (R - Y) / 1.402 + 0.5
© Machiraju/Möller
Examples (RGB, HSV, Luv)
© Machiraju/Möller
Image Pipeline
SPD XYZ ToneReproduction
RGB
γ
© Machiraju/Möller
Colour Matching on Monitors
• Use CIE XYZ space as the standard
• Use a simple linear conversion
• Color matching on printer is more difficult, approximation is needed (CMYK)
€
xyz
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
=
XR XG XB
YR YG YBZR ZG ZB
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
RGB
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
= MC
€
C2 = M2−1M1C1
© Machiraju/Möller
Gamma Correction
• displayed intensity = aᵞ• ɣ is dependent on the monitor• clever way to compute ɣ:• 0.5 = aᵞ ⟶ ɣ = ln 0.5 / ln a
95(c) Peter Shirley
© Machiraju/Möller
Gamma correction
96Wikipedia - http://en.wikipedia.org/wiki/Gamma_correction
© Machiraju/Möller
Image Pipeline
SPD XYZ ToneReproduction
RGB
Dither γ
© Machiraju/Möller
Half-toning
• If we cannot display enough intensities? reduce spatial resolution and increase intensity resolution by allowing our eyes to perform spatial integration
• example is halftoning– approximate 5 intensity levels with the
following 2x2 patterns.
© Machiraju/Möller
Dithering
• maintain the same spatial resolution• diffuse the error between the ideal
intensity and the closest available intensity to neighbouring pixels below and to the right
• try different scan orders to "better" diffuse the errors
• e.g. Floyed-Steinberg:
© Machiraju/Möller
Image Pipeline
SPD XYZ ToneReproduction
RGB
DitherDisplay γ