Lecture 5: Math Review I Justin Johnson EECS 442 WI 2020: Lecture - - PowerPoint PPT Presentation

lecture 5 math review i
SMART_READER_LITE
LIVE PREVIEW

Lecture 5: Math Review I Justin Johnson EECS 442 WI 2020: Lecture - - PowerPoint PPT Presentation

Lecture 5: Math Review I Justin Johnson EECS 442 WI 2020: Lecture 5 - 1 January 23, 2020 Administrative HW0 due Wednesday 1/29 (1 week from yesterday) HW1 out yesterday, due Wednesday 2/5 (3 weeks from yesterday) Justin Johnson EECS 442


slide-1
SLIDE 1

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Lecture 5: Math Review I

1

slide-2
SLIDE 2

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Administrative

2

HW0 due Wednesday 1/29 (1 week from yesterday) HW1 out yesterday, due Wednesday 2/5 (3 weeks from yesterday)

slide-3
SLIDE 3

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Floating Point Arithmetic

3

slide-4
SLIDE 4

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

This Lecture and Next: Math

4

Two goals for the next two classes:

  • Math with computers ≠ Math
  • Practical math you need to know but may

not have been taught

slide-5
SLIDE 5

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

This Lecture and Next: Goal

5

  • Not a “Linear algebra in two lectures” – that’s

impossible.

  • Some of this you should know!
  • Aimed at reviving your knowledge and plugging any

gaps

  • Aimed at giving you intuitions
slide-6
SLIDE 6

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Adding Numbers

6

  • 1 + 1 = ?
  • Suppose 𝑦" is normally distributed with mean 𝜈 and

standard deviation 𝜏 for 1 ≤ 𝑗 ≤ 𝑂

  • How is the average, or )

𝝂 =

𝟐 𝑶 ∑𝒋0𝟐 𝑶

𝒚𝒋, distributed (qualitatively), in terms of variance?

  • The Free Drinks in Vegas Theorem: 2

𝜈 has mean 𝜈 and standard deviation

3 4 .

slide-7
SLIDE 7

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Free Drinks in Vegas

7

Each game/variable has mean $0.10, std $2 100 games is uncertain and fun! 100K games is guaranteed profit: 99.999999% lowest value is $0.064. $0.01 for drinks $0.054 for profits

slide-8
SLIDE 8

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Let’s make it big

8

  • What should happen qualitatively?
  • Theory says that the average is distributed with

mean 31 and standard deviation

5 678 ≈ 10;6

  • What will happen?
  • Reality: 17.47
slide-9
SLIDE 9

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Trying it out

9

Hmm. Hmm.

slide-10
SLIDE 10

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

What is a number?

10

1 1 1 1 27 26 25 24 23 22 21 20 1 185 185 128 + 32 + 16 + 8 + 1 =

slide-11
SLIDE 11

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Adding two numbers

11

“Integers” on a computer are integers modulo 2k Carry Flag

Result 28 27 1 26 25 1 24 1 23 1 22 21 20 1 185 1 1 1 1 105 1 34 1 1

slide-12
SLIDE 12

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Some Gotchas

12

Why? 32 + (3 / 4) x 40 = 32 32 + (3 x 40) / 4 = 62 32 + (3 / 4) x 40 = 32 + 0 x 40 = 32 + 0 = 32 Underflow 32 + (3 x 40) / 4 = 32 + 120 / 4 = 32 + 30 = 62 No Underflow

Ok – you have to multiply before dividing

slide-13
SLIDE 13

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Some Gotchas

13

42 32 + 9 x 40 / 10 = 32 + 104 / 10 = Overflow 32 + (9 x 40) / 10 =

uint8

32 + (9 x 40) / 10 = 68

math

Why 104? 9 x 40 = 360 360 % 256 = 104

Should be: 9x4=36

32 + 10 = 42

slide-14
SLIDE 14

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

What is a number?

14

27 1 26 25 1 24 1 23 1 22 21 20 1 185

How can we do fractions?

25 24 23 22 21 20 2-1 2-2 1 1 1 1 1 45.25 45 0.25

slide-15
SLIDE 15

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Fixed-Point Arithmetic

15

25 1 24 23 1 22 1 21 1 20 2-1 2-2 1 45.25

What’s the largest number we can represent? 63.75 – Why? How precisely can we measure at 63? How precisely can we measure at 0? 0.25 0.25 Fine for many purposes but for science, seems silly

slide-16
SLIDE 16

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Floating Point Numbers

16

1 1 1 1 1

Sign (S) Exponent (E) Fraction (F)

−𝟐𝑻 𝟑𝑭@𝒄𝒋𝒃𝒕 𝟐 + 𝑮 𝟑𝟒 1 7 1

  • 1

27-7 = 20 =1 1+1/8 = 1.125

Bias: allows exponent to be negative (bias = -127 for float32) Note: fraction = significant = mantissa; exponents of all ones or all zeros are special numbers

slide-17
SLIDE 17

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Floating Point Numbers

17

Sign Exponent Fraction

0 0 0

  • 20 x 1.00 = -1

0/8

0 0 1

  • 20 x 1.125 = -1.125

1/8

  • 20 x 1.25 = -1.25

0 1 0

2/8

1 1 0 1 1 1

  • 20 x 1.75 = -1.75
  • 20 x 1.875 = -1.875

6/8 7/8

1 0 1 1 1

7-7=0 *(-bias)*

  • 1
slide-18
SLIDE 18

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Floating Point Numbers

18

Fraction

0 0 0

  • 22 x 1.00 = -4

0/8

0 0 1

  • 22 x 1.125 = -4.5

1/8

0 1 0 1 1 0 1 1 1

  • 22 x 1.25 = -5
  • 22 x 1.75 = -7
  • 22 x 1.875 = -7.5

2/8 6/8 7/8 Sign Exponent

1 1 0 0 1

9-7=2 *(-bias)*

  • 1
slide-19
SLIDE 19

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Floating Point Numbers

19

0 0 0 1 0 1 1 1

Sign Exponent Fraction

0 0 1

  • 20 x 1.00 = -1
  • 20 x 1.125 = -1.125

0 0 0 1 1 0 0 1 0 0 1

  • 22 x 1.00 = -4
  • 22 x 1.125 = -4.5

Gap between numbers is relative, not absolute

slide-20
SLIDE 20

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Adding Floating Point Numbers

20

Sign Exponent Fraction

1 1 0 0 1 0 0 0

  • 22 x 1.00 = -4

1 0 1 1 0 0 0 0

  • 2-1 x 1.00 = -0.5

1 1 0 0 1 0 0 1

  • 22 x 1.125 = -4.5

Actual implementation is complex

slide-21
SLIDE 21

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Adding Floating Point Numbers

21

Sign Exponent Fraction

1 1 0 0 1 0 0 0

  • 22 x 1.00 = -4

1 0 1 0 0 0 0 0

  • 2-3 x 1.00 = -0.125
  • 22 x 1.00 = -4

1 1 0 0 1 0 0 0 1 1 0 0 1 0 0 1 -22 x 1.125 = -4.5 ?

  • 22 x 1.03125 = -4.125
slide-22
SLIDE 22

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Adding Floating Point Numbers

22

Sign Exponent Fraction

1 1 0 0 1 0 0 0

  • 22 x 1.00 = -4

1 0 1 0 0 0 0 0

  • 2-3 x 1.00 = -0.125
  • 22 x 1.03125 = -4.125
  • 22 x 1.00 = -4

1 1 0 0 1 0 0 0

For a and b, these can happen a + b = a a+b-a ≠ b

slide-23
SLIDE 23

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Real Floating Point Numbers

23

S Exponent Fraction

8 bits 2127 ≈ 1038 23 bits ≈ 7 decimal digits

S

Exponent Fraction

11 bits 21023 ≈ 10308 52 bits ≈ 15 decimal digits IEEE 754 Single Precision / Single / float32 IEEE 754 Double Precision / Double / float64

slide-24
SLIDE 24

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Real Floating Point Numbers

24

S Exponent Fraction

5 bits 232 ≈ 109 10 bits ≈ 3 decimal digits IEEE 754 Half Precision / Half / float16 8 bits 2127 ≈ 1038

S Exponent Fraction

7 bits ≈ 2 decimal digits Brain Floating Point / bfloat16 Same range as FP32, but reduced precision

slide-25
SLIDE 25

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Trying it out

25

a+b=a -> numerator is stuck, denominator isn’t Roundoff error occurs

slide-26
SLIDE 26

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Things to Remember

26

  • Computer numbers aren’t math numbers
  • Overflow, accidental zeros, roundoff error, and

basic equalities are almost certainly incorrect for some values

  • Floating point defaults and numpy try to protect

you.

  • Generally safe to use a double and use built-in-

functions in numpy (not necessarily others!)

  • Spooky behavior = look for numerical issues
slide-27
SLIDE 27

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Vectors

27

slide-28
SLIDE 28

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Vectors

28

[2,3] = + 3 x [0,1] 2 x [1,0] 2 x + 3 x e1 e2 2 x + 3 x

x = [2,3] Can be arbitrary # of dimensions (typically denoted Rn)

slide-29
SLIDE 29

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Scaling Vectors

29

x = [2,3] 2x = [4,6]

  • Can scale vector by a scalar
  • Scalar = single number
  • Dimensions changed

independently

  • Changes magnitude / length,

does not change direction.

slide-30
SLIDE 30

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Adding Vectors

30

y = [3,1] x+y = [5,4] x = [2,3]

  • Can add vectors
  • Dimensions changed independently
  • Order irrelevant
  • Can change direction and magnitude
slide-31
SLIDE 31

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Scaling and Adding

31

y = [3,1] 2x+y = [7,7] Can do both at the same time x = [2,3]

slide-32
SLIDE 32

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Measuring Length

32

y = [3,1] x = [2,3] Magnitude / length / (L2) norm of vector 𝒚 = 𝒚 G = H

" I

𝑦"

G 5/G

There are other norms; assume L2 unless told otherwise

𝒚 G = 13 𝒛 G = 10

Why?

slide-33
SLIDE 33

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Normalizing a Vector

33

x = [2,3] y = [3,1] 𝒚M = 𝒚/ 𝒚 𝟑 𝒛M = 𝒛/ 𝒛 𝟑 Diving by norm gives something on the unit sphere (all vectors with length 1)

slide-34
SLIDE 34

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Dot Products

34

𝒚M 𝒛M 𝒚 ⋅ 𝒛 = H

"05 I

𝑦"𝑧" = 𝒚𝑼𝒛

𝜄

𝒚 ⋅ 𝒛 = cos 𝜄 𝒚 𝒛 What happens with normalized / unit vectors?

slide-35
SLIDE 35

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Dot Products

35

𝒇𝟐 𝒇𝟑 𝒚 ⋅ 𝒛 = H

" I

𝑦"𝑧"

𝒚 = [2,3]

What’s 𝒚 ⋅ 𝒇𝟐, 𝒚 ⋅ 𝒇𝟑? Ans: 𝒚 ⋅ 𝒇𝟐 = 2 ; 𝒚 ⋅ 𝒇𝟑 = 3

  • Dot product is projection
  • Amount of x that’s also

pointing in direction of y

slide-36
SLIDE 36

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Dot Products

36

What’s 𝒚 ⋅ 𝒚 ? Ans: 𝒚 ⋅ 𝒚 = ∑𝑦"𝑦" = 𝒚 G

G

𝒚 ⋅ 𝒛 = H

" I

𝑦"𝑧"

𝒚 = [2,3]

slide-37
SLIDE 37

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Special Angles

37

𝒚M 𝒛M

𝜄

1 0 ⋅ 0 1 = 0 ∗ 1 + 1 ∗ 0 = 0 Perpendicular /

  • rthogonal vectors

have dot product 0 irrespective of their magnitude 𝒚 𝒛

slide-38
SLIDE 38

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Special Angles

38

𝑦5 𝑦G ⋅ 𝑧5 𝑧G = 𝑦5𝑧5 + 𝑦G𝑧G = 0 Perpendicular /

  • rthogonal vectors

have dot product 0 irrespective of their magnitude 𝒚M 𝒛M

𝜄

𝒚 𝒛

slide-39
SLIDE 39

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Orthogonal Vectors

39

𝒚 = [2,3]

  • Geometrically,

what’s the set of vectors that are

  • rthogonal to x?
  • A line [3,-2]
slide-40
SLIDE 40

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Orthogonal Vectors

40

  • What’s the set of vectors that are
  • rthogonal to x = [5,0,0]?
  • A plane/2D space of vectors/any vector

[0, 𝑏, 𝑐]

  • What’s the set of vectors that are
  • rthogonal to x and y = [0,5,0]?
  • A line/1D space of vectors/any vector

[0,0, 𝑐]

  • Ambiguity in sign and magnitude

𝒚 𝒚 𝒛

slide-41
SLIDE 41

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Cross Product

41

  • Set {𝒜: 𝒜 ⋅ 𝒚 = 0, 𝒜 ⋅ 𝒛 = 0} has an

ambiguity in sign and magnitude

  • Cross product 𝒚×𝒛 is: (1) orthogonal

to x, y (2) has sign given by right hand rule and (3) has magnitude given by area of parallelogram of x and y

  • Important: if x and y are the same

direction or either is 0, then 𝒚×𝒛 = 𝟏

  • Only in 3D!
  • (See wedge product for D != 3)

𝒚 𝒛 𝒚×𝒛

Image credit: Wikipedia.org

slide-42
SLIDE 42

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Operations You Should Know

42

  • Scale (vector, scalar → vector)
  • Add (vector, vector → vector)
  • Magnitude (vector → scalar)
  • Dot product (vector, vector → scalar)
  • Dot products are projection / angles
  • Cross product (vector, vector → vector)
  • Vectors facing same direction have cross product 0
  • You can never mix vectors of different sizes
slide-43
SLIDE 43

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrices

43

slide-44
SLIDE 44

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrices

44

Horizontally concatenate n, m-dim column vectors and you get a mxn matrix A (here 2x3)

𝑩 = 𝒘5, ⋯ , 𝒘I = 𝑤5g 𝑤Gg 𝑤hg 𝑤5i 𝑤Gi 𝑤hi

a

(scalar) lowercase undecorated a (vector) lowercase bold or arrow

A

(matrix) uppercase bold

slide-45
SLIDE 45

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrices

45

Horizontally concatenate n, m-dim column vectors and you get a mxn matrix A (here 2x3)

𝑩 = 𝒘5, ⋯ , 𝒘I = 𝑤5g 𝑤Gg 𝑤hg 𝑤5i 𝑤Gi 𝑤hi

Watch out: In math, it’s common to treat D-dim vector as a Dx1 matrix (column vector); In numpy these are different things

slide-46
SLIDE 46

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrices

46

Vertically concatenate m, n-dim row vectors and you get a mxn matrix A (here 2x3)

𝐵 = 𝒗5

l

⋮ 𝒗I

l

= 𝑣5g 𝑣5i 𝑣5o 𝑣Gg 𝑣Gi 𝑣Go

Transpose: flip rows / columns

𝑏 𝑐 𝑑

l

= 𝑏 𝑐 𝑑 (3x1)T = 1x3

slide-47
SLIDE 47

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrix-vector Product

47

𝒛Gq5 = 𝑩Gqh𝒚hq5 𝒛 = 𝑦5𝒘𝟐 + 𝑦G𝒘𝟑 + 𝑦h𝒘𝟒

Linear combination of columns of A

𝑧5 𝑧G = 𝒘𝟐 𝒘𝟑 𝒘𝟒 𝑦5 𝑦G 𝑦h

slide-48
SLIDE 48

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrix-vector Product

48

𝒛Gq5 = 𝑩Gqh𝒚hq5 𝑧5 = 𝒗𝟐

𝑼𝒚

Dot product between rows of A and x

𝑧G = 𝒗𝟑

𝑼𝒚

𝒗𝟐

𝑼

𝒗𝟑

𝑼

𝑧5 𝑧G = 𝒚

3 3

slide-49
SLIDE 49

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrix Multiplication

49

− 𝒃𝟐

𝑼

− ⋮ − 𝒃𝒏

𝑼

− | | 𝒄𝟐 ⋯ 𝒄𝒒 | | 𝑩𝑪 =

Generally: Amn and Bnp yield product (AB)mp

Yes – in A, I’m referring to the rows, and in B, I’m referring to the columns

slide-50
SLIDE 50

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrix Multiplication

50

− 𝒃𝟐

𝑼

− ⋮ − 𝒃𝒏

𝑼

− | | 𝒄𝟐 ⋯ 𝒄𝒒 | | 𝑩𝑪 = 𝒃𝟐

𝑼𝒄𝟐

⋯ 𝒃𝟐

𝑼𝒄𝒒

⋮ ⋱ ⋮ 𝒃𝒏

𝑼 𝒄𝟐

⋯ 𝒃𝒏

𝑼 𝒄𝒒

𝑩𝑪"w = 𝒃𝒋

𝑼𝒄𝒌

Generally: Amn and Bnp yield product (AB)mp

slide-51
SLIDE 51

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Matrix Multiplication

51

  • Dimensions must match
  • Dimensions must match
  • Dimensions must match
  • (Yes, it’s associative): ABx = (A)(Bx) = (AB)x
  • (No it’s not commutative): ABx ≠ (BA)x ≠ (BxA)
slide-52
SLIDE 52

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Operations they don’t teach

52

𝑏 + 𝑓 𝑐 + 𝑓 𝑑 + 𝑓 𝑒 + 𝑓 𝑏 𝑐 𝑑 𝑒 + 𝑓 𝑔 𝑕 ℎ = 𝑏 + 𝑓 𝑐 + 𝑔 𝑑 + 𝑕 𝑒 + ℎ

You Probably Saw Matrix Addition

𝑏 𝑐 𝑑 𝑒 + 𝑓 =

What is this? FYI: e is a scalar

slide-53
SLIDE 53

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Broadcasting

53

𝑏 𝑐 𝑑 𝑒 + 𝑓 = 𝑏 𝑐 𝑑 𝑒 + 𝑓 𝑓 𝑓 𝑓 = 𝑏 𝑐 𝑑 𝑒 + 𝟐GqG𝑓

If you want to be pedantic and proper, you expand e by multiplying a matrix of 1s (denoted 1) Many smart matrix libraries do this automatically. This is the source of many bugs.

slide-54
SLIDE 54

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Broadcasting Example

54

𝑸 = 𝑦5 𝑧5 ⋮ ⋮ 𝑦I 𝑧I 𝒘 = 𝑏 𝑐

Given: a nx2 matrix P and a 2D column vector v, Want: nx2 difference matrix D

𝑬 = 𝑦5 − 𝑏 𝑧5 − 𝑐 ⋮ ⋮ 𝑦I − 𝑏 𝑧I − 𝑐 𝑸 − 𝒘l = 𝑦5 𝑧5 ⋮ ⋮ 𝑦I 𝑧I − 𝑏 𝑐 𝑏 𝑐 ⋮

Blue stuff is assumed / broadcast

slide-55
SLIDE 55

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Two uses for Matrices

55

  • 1. Storing things in a rectangular array (images,

maps)

  • Typical operations: element-wise operations,

convolution (which we’ll cover next)

  • Atypical operations: almost anything you learned in a

math linear algebra class

  • 2. A linear operator that maps vectors to another

space (Ax)

  • Typical/Atypical: reverse of above
slide-56
SLIDE 56

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Images as Matrices

56

Suppose someone hands you this matrix. What’s wrong with it?

No contrast!

slide-57
SLIDE 57

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Contrast: Gamma Curve

57

Typical way to change the contrast is to apply a nonlinear correction pixelvalueˆ The quantity 𝛿 controls how much contrast gets added

slide-58
SLIDE 58

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Contrast: Gamma Curve

58

10% 50% 90% Now the darkest regions (10th pctile) are much darker than the moderately dark regions (50th pctile). new 10% new 50% new 90%

slide-59
SLIDE 59

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 - 59

Contrast: Gamma Correction

slide-60
SLIDE 60

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 - 60

Phew! Much Better.

Contrast: Gamma Correction

slide-61
SLIDE 61

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Implementation

61

imNew = im**4 Python+Numpy (right way): Python+Numpy (slow way – why? ): imNew = np.zeros(im.shape) for y in range(im.shape[0]): for x in range(im.shape[1]): imNew[y,x] = im[y,x]**expFactor

slide-62
SLIDE 62

Justin Johnson January 23, 2020 EECS 442 WI 2020: Lecture 5 -

Next Time: Vectorization, Tensors, Linear Algebra

62