Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
Lecture 7: More Math + Image Filtering
1
Lecture 7: More Math + Image Filtering Justin Johnson EECS 442 WI - - PowerPoint PPT Presentation
Lecture 7: More Math + Image Filtering Justin Johnson EECS 442 WI 2020: Lecture 7 - 1 January 30, 2020 Administrative HW0 was due yesterday! HW1 due a week from yesterday Justin Johnson EECS 442 WI 2020: Lecture 7 - 2 January 30, 2020
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
1
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
2
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
3 https://cse.engin.umich.edu/event/numpy-a-look-at-the-past-present-and-future-of-array-computation
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
4
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
5
satisfy ๐ฉ๐๐ = ๐$๐๐ (๐ฉ๐๐ is scaled by ๐$)
you assume ๐๐
' = 1
๐ ๐ = ๐ฉ๐ stretches a vector x.
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 6
Suppose I have points in a grid
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 7
Now I apply f(x) = Ax to these points Pointy-end: Ax . Non-Pointy-End: x
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 8
Red box โ unit square, Blue box โ after f(x) = Ax. What are the yellow lines and why?
1.1 1.1
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 9
0.8 1.25 Now I apply f(x) = Ax to these points Pointy-end: Ax . Non-Pointy-End: x
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 10
Red box โ unit square, Blue box โ after f(x) = Ax. What are the yellow lines and why?
0.8 1.25
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 11
Red box โ unit square, Blue box โ after f(x) = Ax. Can we draw any yellow lines?
cos(๐ข) โsin(๐ข) sin(๐ข) cos(๐ข)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
12
(not necessarily) distinct eigenvalues
eigenvalue maximizes
๐๐ผ๐ฉ๐ ๐๐ผ๐ (smallest/min)
eigenvector maximizes ๐๐ผ๐ฉ๐
problems rely on (max/min)imizing this
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
13
Rotation Can always write a mxn matrix A as: ๐ฉ = ๐ฝ๐ป๐พ๐ผ Eigenvectors
Scale Sqrt of Eigenvalues
ฯ1 ฯ2 ฯ3
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
14
Rotation Can always write a mxn matrix A as: ๐ฉ = ๐ฝ๐ป๐พ๐ผ Eigenvectors
Scale Sqrt of Eigenvalues
Rotation Eigenvectors
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
15
number of linearly independent vectors
ฯ1 ฯ2 ฯ3
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
16
number of linearly independent vectors
ฯ1 ฯ2
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
17
number of linearly independent vectors
matrices
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
18
Start with two points (xi,yi) ๐ง@ ๐ง' = ๐ฆ@ 1 ๐ฆ' 1 ๐ ๐ ๐ = ๐ฉ๐ ๐ง@ ๐ง' = ๐๐ฆ@ + ๐ ๐๐ฆ' + ๐ We know how to solve this โ invert A and find v (i.e., (m,b) that fits points)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
19
Start with two points (xi,yi) ๐ง@ ๐ง' = ๐ฆ@ 1 ๐ฆ' 1 ๐ ๐ ๐ = ๐ฉ๐ ๐ง@ ๐ง' โ ๐๐ฆ@ + ๐ ๐๐ฆ' + ๐
'
๐ โ ๐ฉ๐ ' = = ๐ง@ โ ๐๐ฆ@ + ๐
' + ๐ง' โ ๐๐ฆ' + ๐ '
The sum of squared differences between the actual value of y and what the model says y should be.
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
20
Suppose there are n > 2 points ๐ง@ โฎ ๐งG = ๐ฆ@ 1 โฎ โฎ ๐ฆG 1 ๐ ๐ ๐ = ๐ฉ๐ Compute ๐ง โ ๐ต๐ฆ ' again ๐ โ ๐ฉ๐ ' = I
$J@ K
๐ง$ โ (๐๐ฆ$ + ๐) '
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
21
Given y, A, and v with y = Av overdetermined (A tall / more equations than unknowns) We want to minimize ๐ โ ๐ฉ๐ ๐, or find:
(The value of x that makes the expression smallest)
R@๐ฉ๐ผ๐
(Donโt actually compute the inverse!)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
22
Want n outputs, have n knobs to fiddle with, every knob is useful if A is full rank.
A: rows (outputs) > columns (knobs). Thus canโt get precise
knobs). So settle for โclosestโ knob setting.
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
23
Want n outputs, have n knobs to fiddle with, every knob is useful if A is full rank.
A: columns (knobs) > rows (outputs). Thus, any output can be expressed in infinite ways.
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
24
Given a set of unit vectors (aka directions) ๐๐, โฆ , ๐๐ and I want vector ๐ that is as orthogonal to all the ๐๐ as possible (for some definition of orthogonal)
๐ผ
๐ผ
Stack ๐๐ into A, compute Av
๐ผ๐
๐ผ๐
๐๐ ๐๐ ๐๐โฆ ๐ ๐ฉ๐ ๐ = I
๐ ๐
๐๐
๐ผ๐ ๐
Compute
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
25
v that minimizes ๐ฉ๐ ' .
๐
๐ฉ๐ '
'
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
26
Letโs look at ๐ฉ๐ '
'
' =
Rewrite as dot product
' = ๐๐ผ๐ฉ๐ผ๐๐ฐ = ๐ฐ๐ ๐๐๐ ๐ฐ
' = ๐๐ฐ Z(๐๐ฐ)
Distribute transpose We want the vector minimizing this quadratic form Where have we seen this?
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
27
๐ [J@ ๐ฉ๐ '
*Note: ๐ฉ๐ผ๐ฉ is positive semi-definite so it has all non-negative eigenvalues
(1) โSmallestโ* eigenvector of ๐ฉ๐ผ๐ฉ (2) โSmallestโ right singular vector of ๐ฉ Ubiquitious tool in vision: For min โ max, switch smallest โ largest
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
28
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
29
Remember derivatives? Derivative: rate at which a function f(x) changes at a point as well as the direction that increases the function
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 30
๐ ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 31
Whatโs special about x=2? ๐ ๐ฆ minim. at 2 ๐ ๐ฆ = 0 at 2 a = minimum of f โ ๐ ๐ = 0 Reverse is not true ๐ ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 32
Suppose I want to increase f(x) by changing x: Blue area: move left Red area: move right Derivative tells you direction of ascent and rate ๐ ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
33
system / use a cookbook
calculus)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
34
๐
' ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5 + ๐ง + 1 '
๐ ๐ฆ = ๐ฆ โ 2 ' + 5 ๐ ๐๐ฆ ๐ ๐ฆ = 2 ๐ฆ โ 2 โ 1 = 2(๐ฆ โ 2) ๐ ๐๐ฆ ๐
' ๐ฆ = 2(๐ฆ โ 2)
Pretend itโs constant โ derivative = 0
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 35
๐
' ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5 + ๐ง + 1 '
Dark = f(x,y) low Bright = f(x,y) high
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 36
๐
' ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5 + ๐ง + 1 '
Slice of y=0 is the function from before: ๐ ๐ฆ = ๐ฆ โ 2 ' + 5 ๐] ๐ฆ = 2(๐ฆ โ 2)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 37
๐
' ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5 + ๐ง + 1 ' a ab ๐ ' ๐ฆ, ๐ง is rate of
change & direction in x dimension
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 - 38
๐
' ๐ฆ, ๐ง = ๐ฆ โ 2 ' + 5 + ๐ง + 1 '
Gradient/Jacobian: Making a vector of โd= ๐๐ ๐๐ฆ , ๐๐ ๐๐ง gives rate and direction
Arrows point OUT of minimum / basin.
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
39
dimension: if ๐ in ๐(๐) has n dimensions, โd(๐ฆ) has n dimensions
rate of ascent
spaces
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
40
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
41
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
42
Slide Credit: D. Lowe
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 Out
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
43
1/3 1/3 1/3
10 12 9 11 10 11 12
10.33
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
44
1/3 1/3 1/3
10 12 9 11 10 11 12
10.33 10.66
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
45
1/3 1/3 1/3
10 12 9 11 10 11 12
10.33 10.66 10
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
46
1/3 1/3 1/3
10 12 9 11 10 11 12
10.33 10.66 10 10.66
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
47
1/3 1/3 1/3
10 12 9 11 10 11 12
10.33 10.66 10 10.66 11
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
48
I11 I12 I13 I21 I22 I23 I31 I32 I33 I14 I15 I16 I24 I25 I26 I34 I35 I36 I41 I42 I43 I51 I52 I53 I44 I45 I46 I54 I55 I56
F11 F12 F13 F21 F22 F23 F31 F32 F33
O11 O12 O13 O21 O22 O23 O31 O32 O33 O14 O24 O34
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
49
I11 I12 I13 I21 I22 I23 I31 I32 I33 I14 I15 I16 I24 I25 I26 I34 I35 I36 I41 I42 I43 I51 I52 I53 I44 I45 I46 I54 I55 I56
F11 F12 F13 F21 F22 F23 F31 F32 F33
O11
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
50
I11 I12 I13 I21 I22 I23 I31 I32 I33 I14 I15 I16 I24 I25 I26 I34 I35 I36 I41 I42 I43 I51 I52 I53 I44 I45 I46 I54 I55 I56
F11 F12 F13 F21 F22 F23 F31 F32 F33
O11
O12
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
51
I11 I12 I13 I21 I22 I23 I31 I32 I33 I14 I15 I16 I24 I25 I26 I34 I35 I36 I41 I42 I43 I51 I52 I53 I44 I45 I46 I54 I55 I56
F11 F12 F13 F21 F22 F23 F31 F32 F33
How many times can we apply a 3x3 filter to a 5x6 image?
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
52
I11 I12 I13 I21 I22 I23 I31 I32 I33 I14 I15 I16 I24 I25 I26 I34 I35 I36 I41 I42 I43 I51 I52 I53 I44 I45 I46 I54 I55 I56
O11 O12 O13 O21 O22 O23 O31 O32 O33 O14 O24 O34 F11 F12 F13 F21 F22 F23 F31 F32 F33
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
53
f g g g g f g g g g f g g g g Convolution doesnโt keep the whole image. Suppose f is the image and g the filter.
f/g Diagram Credit: D. Lowe
Full: Any part
Same: Output is same size as f Valid: Filter doesnโt fall off edge
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
54
Symm: fold sides over pad/fill: add value, often 0 f g g g g ? ? ? ? Circular/Wrap: wrap around
f/g Diagram Credit: D. Lowe
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
55
Input Image Box Filtered ??? Box Filtered ??? (Iโve applied the filter per-color channel) Which padding did I use and why?
Note โ this is a zoom of the filtered, not a filter of the zoomed
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
56
Input Image Box Filtered Symm Pad Box Filtered Zero Pad (Iโve applied the filter per-color channel)
Note โ this is a zoom of the filtered, not a filter of the zoomed
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
57
Slide Credit: D. Lowe
Original
1
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
58
Slide Credit: D. Lowe
Original
1
The Same!
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
59
Slide Credit: D. Lowe
Original
1
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
60
Slide Credit: D. Lowe
Original
1
Shifted LEFT 1 pixel
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
61
Slide Credit: D. Lowe
Original
1
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
62
Slide Credit: D. Lowe
Original
1
Shifted DOWN 1 pixel
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
63
Slide Credit: D. Lowe
Original
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
64
Slide Credit: D. Lowe
Original
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9
Blur (Box Filter)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
65
Slide Credit: D. Lowe
Original
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 2
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
66
Slide Credit: D. Lowe
Original
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 2
(Acccentuates difference from local average)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
67
Slide Credit: D. Lowe
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
68
Assume: I image f1, f2 filters Linear: apply(I,f1+f2) = apply(I,f1) + apply(I,f2) I is a white box on black, and f1, f2 are rectangles
Note: I am showing filters un-normalized and blown up. Theyโre a smaller box filter (i.e., each entry is 1/(size^2))
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
69
Assume: I image, f filter Shift-invariant: shift(apply(I,f)) = apply(shift(I,f)) Intuitively: only depends on filter neighborhood
Note: โShift-Invariantโ is standard terminology, but I think โShift- Equivariantโ is more correct
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
70
Often called โconvolutionโ. Actually cross-correlation. Cross-Correlation (Slide filter over image) Convolution (Flip filter, then slide it)
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
71
Property List: K. Grauman
Justin Johnson January 30, 2020 EECS 442 WI 2020: Lecture 7 -
72