the mathematics of digital photography

60
The Mathematics of Digital Photography Professor Nick Higham Director of Research School of Mathematics [email protected] http://www.manchester.ac.uk/~higham/

Upload: others

Post on 12-Sep-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Mathematics of Digital Photography

Research Matters

February 25, 2009

Nick HighamDirector of Research

School of Mathematics

1 / 6

The Mathematics ofDigital Photography

Professor Nick HighamDirector of Research

School of Mathematics

[email protected]://www.manchester.ac.uk/~higham/

Page 2: The Mathematics of Digital Photography

What is Color?

Human perception; depends on light source.

Retina has 3 types of cones⇒ trichromatic theory.

Why does yellow appear so bright?

Nick Higham Digital Photography 2 / 46

Page 3: The Mathematics of Digital Photography

What is Color?

Human perception; depends on light source.Retina has 3 types of cones⇒ trichromatic theory.

Why does yellow appear so bright?

Nick Higham Digital Photography 2 / 46

Page 4: The Mathematics of Digital Photography

What is Color?

Human perception; depends on light source.Retina has 3 types of cones⇒ trichromatic theory.

Why does yellow appear so bright?

Nick Higham Digital Photography 2 / 46

Page 5: The Mathematics of Digital Photography

Colour Blindness

John Dalton (1766–1844).Described his own c.b. inlecture to M/cr Lit & PhilSoc, 1794.He was a deuteranope.

Nick Higham Digital Photography 3 / 46

Page 6: The Mathematics of Digital Photography

Vector Space Model of ColourModel responses of the 3 cones as

ci =

∫ λmax

λmin

si(λ)f (λ)dλ, i = 1 : 3,

where f = spectral distrib. of light, si = sensitivity of i thcone, [λmin, λmax] = wavelengths of visible spectrum.

Discretizing gives

c = ST f , c ∈ R3, S ∈ Rn×3, f ∈ Rn.

For standardized S, c is the tristimulus vector.

Nick Higham Digital Photography 4 / 46

Page 7: The Mathematics of Digital Photography

Vector Space Model of ColourModel responses of the 3 cones as

ci =

∫ λmax

λmin

si(λ)f (λ)dλ, i = 1 : 3,

where f = spectral distrib. of light, si = sensitivity of i thcone, [λmin, λmax] = wavelengths of visible spectrum.Discretizing gives

c = ST f , c ∈ R3, S ∈ Rn×3, f ∈ Rn.

For standardized S, c is the tristimulus vector.

Nick Higham Digital Photography 4 / 46

Page 8: The Mathematics of Digital Photography

StandardizationCommission Internationale de l’Éclairage (CIE) definedstandard colour matching functions si(λ) (1931, 1964).CIE RGB space.CIE XYZ space: nonnegative si(λ), Y corresponds toperceived brightness.

Nick Higham Digital Photography 5 / 46

Page 9: The Mathematics of Digital Photography

Projective Transformation

Nick Higham Digital Photography 6 / 46

Page 10: The Mathematics of Digital Photography

CIE Chromacity Coordinates

x =X

X + Y + Z, y =

YX + Y + Z

(z = 1− x − y).

(x , y) chromacity diagram:

Nick Higham Digital Photography 7 / 46

Page 11: The Mathematics of Digital Photography
Page 12: The Mathematics of Digital Photography

Perceptual Uniformity: LAB Space

XYZ and RGB far from perceptually uniform.Search for (non)linear transformations that give moreuniform colour spaces.CIE L*a*b* (LAB, 1976) is more uniform:L = lightness, A = green–magenta, B = blue–yellow.LAB supported by Adobe Photoshop, MATLAB ImageProcessing Toolbox.

Nick Higham Digital Photography 9 / 46

Page 13: The Mathematics of Digital Photography

Dan Margulis on LAB (2006)

Nick Higham Digital Photography 10 / 46

Page 14: The Mathematics of Digital Photography

CMYK

Printers use subtractive colour model: dyes absorb powerfrom spectrum. To produce wide range of colours need cyan,yellow, magenta primaries.

But C + M + Y = K = black : why do we need K?

Printing 3 layers makes the paper very wet.Black as 3 layers requires accurate registration.C + M + Y will not give a true, deep black due toimperfections.Coloured ink is more expensive.

Nick Higham Digital Photography 11 / 46

Page 15: The Mathematics of Digital Photography

CMYK

Printers use subtractive colour model: dyes absorb powerfrom spectrum. To produce wide range of colours need cyan,yellow, magenta primaries.

But C + M + Y = K = black : why do we need K?

Printing 3 layers makes the paper very wet.Black as 3 layers requires accurate registration.C + M + Y will not give a true, deep black due toimperfections.Coloured ink is more expensive.

Nick Higham Digital Photography 11 / 46

Page 16: The Mathematics of Digital Photography

Bayer Filter

Sensor has 2green filters foreach red andblue.

Raw files are the unprocessed data off the sensor.

Nick Higham Digital Photography 12 / 46

Page 17: The Mathematics of Digital Photography

Demosaicing

Converts toRGB colourimage byinterpolation.

Nick Higham Digital Photography 13 / 46

Page 18: The Mathematics of Digital Photography

Compression

Original number string1 2 0 0 0 0 8 7 7 7 7 7 6 13

Lossless compression1 2 0 *4 8 7 *5 6 8

Lossy compression0 *6 7 *7 4

Jpeg is a lossy compression scheme.

Nick Higham Digital Photography 14 / 46

Page 19: The Mathematics of Digital Photography

Jpeg

Compressed RGB file.Filesizes reduced by orders of magnitude.Used by all digital cameras and imaging software.

tif (LZW) 12111 kjpg 12 1892 kjpg 8 917 kjpg 0 221 k

Nick Higham Digital Photography 15 / 46

Page 20: The Mathematics of Digital Photography

Jpeg 200× 200 px

Quality 8 Quality 0

Nick Higham Digital Photography 16 / 46

Page 21: The Mathematics of Digital Photography

Colour Space

Jpeg compression first converts from RGB to YCbCr colourspace where Y = luminance, Cb,Cr = blue, redchrominances, by Y

Cb

Cr

=

0.299 0.587 0.114−0.1687 −0.3313 0.5

0.5 −0.4187 −0.0813

RGB

.Vision has poor response to spatial detail in colouredareas of same luminance⇒ Cb, Cr can take greatercompression.Note:

∑row1 = 1,

∑row2 =

∑row3 = 0.

Nick Higham Digital Photography 17 / 46

Page 22: The Mathematics of Digital Photography

Discrete Cosine Transform

Algorithm breaks image into 8× 8 blocks.For each block luminance values expressed as linearcombination of cosine functions of increasing frequency

`x ,y =7∑

i=0

7∑j=0

fij cos((2x + 1)iπ

16

)cos

((2y + 1)iπ

16

),

where fij computed by a discrete cosine transform:

fij =7∑

x=0

7∑y=0

`x ,y cos((2x + 1)iπ

16

)cos

((2y + 1)iπ

16

).

Coefficients rounded, higher freqs de-emphasized.Same for Cb,Cr but more aggressive compression done.

Nick Higham Digital Photography 18 / 46

Page 23: The Mathematics of Digital Photography

Fingerprints—FBIDigitized at 500dpi⇒ 10Mb. Compression >∼ 10:1 req’d.Standardized on wavelet compression (1993).Jpeg: resonance of 8-pixel tiling w/ 500dpi scans, manyedges.Wavelets: gradual blurring as compression increased.

Nick Higham Digital Photography 19 / 46

Page 24: The Mathematics of Digital Photography

Panoramic Stitching

Nonlinear least squares, Levenberg–Marquardt:

(JT J + λD)d = JT r , J ∈ R3200×32 for 8 images.

Nick Higham Digital Photography 20 / 46

Page 25: The Mathematics of Digital Photography

Panoramic Stitching

Nonlinear least squares, Levenberg–Marquardt:

(JT J + λD)d = JT r , J ∈ R3200×32 for 8 images.

Nick Higham Digital Photography 20 / 46

Page 26: The Mathematics of Digital Photography

Panoramic Stitching

Nonlinear least squares, Levenberg–Marquardt:

(JT J + λD)d = JT r , J ∈ R3200×32 for 8 images.

Nick Higham Digital Photography 20 / 46

Page 27: The Mathematics of Digital Photography

Panoramic Stitching

Nonlinear least squares, Levenberg–Marquardt:

(JT J + λD)d = JT r , J ∈ R3200×32 for 8 images.

Nick Higham Digital Photography 20 / 46

Page 28: The Mathematics of Digital Photography

Cloning/Healing

Photoshop blends the source into the target by solving thebiharmonic equation

∂4f∂x4 + 2

∂4f∂x2∂y2 +

∂4f∂y4 = 0.

Originally used in mapping, contouring (1950s).

Nick Higham Digital Photography 21 / 46

Page 29: The Mathematics of Digital Photography

Cloning/Healing

Photoshop blends the source into the target by solving thebiharmonic equation

∂4f∂x4 + 2

∂4f∂x2∂y2 +

∂4f∂y4 = 0.

Originally used in mapping, contouring (1950s).

Nick Higham Digital Photography 21 / 46

Page 30: The Mathematics of Digital Photography

Transformations to improve images

Page 31: The Mathematics of Digital Photography
Page 32: The Mathematics of Digital Photography
Page 33: The Mathematics of Digital Photography
Page 34: The Mathematics of Digital Photography
Page 35: The Mathematics of Digital Photography
Page 36: The Mathematics of Digital Photography
Page 37: The Mathematics of Digital Photography
Page 38: The Mathematics of Digital Photography
Page 39: The Mathematics of Digital Photography
Page 40: The Mathematics of Digital Photography

UoM turquoise is (L,A,B) ≈ (85,−12,−3).Convert to LAB then A← −A.

Now have (L,A,B) ≈ (85,12,−3).

Page 41: The Mathematics of Digital Photography
Page 42: The Mathematics of Digital Photography
Page 43: The Mathematics of Digital Photography
Page 44: The Mathematics of Digital Photography
Page 45: The Mathematics of Digital Photography
Page 46: The Mathematics of Digital Photography
Page 47: The Mathematics of Digital Photography
Page 48: The Mathematics of Digital Photography
Page 49: The Mathematics of Digital Photography

Mean

Nick Higham Digital Photography 41 / 46

Page 50: The Mathematics of Digital Photography

Median

Nick Higham Digital Photography 42 / 46

Page 51: The Mathematics of Digital Photography

Max

Nick Higham Digital Photography 43 / 46

Page 52: The Mathematics of Digital Photography

Min

Nick Higham Digital Photography 44 / 46

Page 53: The Mathematics of Digital Photography

Variance

Nick Higham Digital Photography 45 / 46

Page 54: The Mathematics of Digital Photography

Summary

Mathematics is intrinsic to digital imaging: modelling theeye’s response to colour, colour spaces, capturingimages, storing and processing them.Modern developments in Photoshop, Lightroom, etc., relyon clever mathematical algorithms as well as exploitingfaster processors—and, increasingly, GPUs.Most of the relevant mathematics is covered in ourhonours degree programme.

Talk, including references, available athttp://www.maths.manchester.ac.uk/~higham/talks/digphot.pdf

Nick Higham Digital Photography 46 / 46

Page 55: The Mathematics of Digital Photography

Acknowledgements for Graphics

Wikipedia:http://en.wikipedia.org/wiki/Image:CIE1931_XYZCMF.pnghttp://upload.wikimedia.org/wikipedia/commons/b/b0/CIExy1931.pnghttp://en.wikipedia.org/wiki/Bayer_filter

http://www2.cmp.uea.ac.uk/Research/compvis/ColourIntro/ColourIntro.htm

Fraser [4].

Nick Higham Digital Photography 1 / 6

Page 56: The Mathematics of Digital Photography

References I

D. Austin.What is . . . JPEG?Notices Amer. Math. Soc., 55(2):226–229, 2008.

C. M. Brislawn.Fingerprints go digital.Notices Amer. Math. Soc., 42(11):1278–1283, 1995.

J. B. Cohen.Visual Color and Color Mixture: The Fundamental ColorSpace.University of Illinois Press, Urbana and Chicago, USA,2001.

Nick Higham Digital Photography 2 / 6

Page 57: The Mathematics of Digital Photography

References II

B. Fraser.Raw capture, linear gamma, and exposure.www.adobe.com/products/photoshop/pdfs/linear_gamma.pdf.

B. Fraser.Understanding digital raw capture.www.adobe.com/products/photoshop/pdfs/understanding_digitalrawcapture.pdf.

Nick Higham Digital Photography 3 / 6

Page 58: The Mathematics of Digital Photography

References III

N. J. Higham.Color spaces and digital imaging.In N. J. Higham, M. R. Dennis, P. Glendinning, P. A.Martin, F. Santosa, and J. Tanner, editors, The PrincetonCompanion to Applied Mathematics, pages 808–813.Princeton University Press, Princeton, NJ, USA, 2015.

A. R. Hill.How we see colour.In R. McDonald, editor, Colour Physics for Industry, pages211–281. Society of Dyers and Colourists, Bradford,England, 1987.

Nick Higham Digital Photography 4 / 6

Page 59: The Mathematics of Digital Photography

References IV

D. M. Hunt, K. S. Dulai, J. K. Bowmaker, and J. D. Mollon.The chemistry of John Dalton’s color blindness.Science, 267:984–988, 1995.

JPEG file interchange format, version 1.02.http://www.w3.org/Graphics/JPEG/jfif3.pdf.

D. Margulis.Photoshop LAB Color: The Canyon Conundrum andOther Adventures in the Most Powerful Colorspace.Peachpit Press, Berkeley, CA, USA, 2006.

C. Poynton.A guided tour of color space, 1997.www.poynton.com/PDFs/Guided_tour.pdf.

Nick Higham Digital Photography 5 / 6

Page 60: The Mathematics of Digital Photography

References V

G. Sharma and H. J. Trussell.Digital color imaging.IEEE Trans. Image Processing, 6(7):901–932, 1997.

S. Westland and C. Ripamonti.Computational Colour Science Using MATLAB.Wiley, New York, 2004.

Nick Higham Digital Photography 6 / 6