cv192, hw #4 - bgucv192/wiki.files/cv192_hw4.pdf · 2019-05-02 · cv192, hw #4 oren freifeld...

13
CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment is focused on image filters. We also briefly touch upon Matrix groups. Version Log 1.02, 2/5/2019. In Fact 2, it is , not =. Updated the deadline from 6/5 to 13/5. 1.01, 27/3/2019. Corrected deadline. 1.00, 25/3/2019. Initial release. Contents 1 Filtering 2 1.1 Convolution .............................. 2 1.1.1 Viewing convolution as as one big matrix operation ... 4 1.1.2 Separable Filters ....................... 5 1.2 More General Filters ......................... 7 1.3 Laplacian and Laplacian of Gaussian ................ 8 1.4 Directional Filters .......................... 9 1.5 Computing the Spatial Derivatives (will be Required in a Later Assignment for Optical Flow) .................... 10 2 Matrix groups: Definition and Basic Properties 11 Few Words Before You Start 1. You will need opencv. If you can’t install opencv on your machine for some reason, you can always use the department machine, cicero2 (more details can be found at the course website). 2. You may find this link useful: http://docs.opencv.org/3.0-beta/modules/imgproc/doc/filtering. html 1

Upload: others

Post on 08-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

CV192, HW #4

Oren Freifeld

Release Date: 25/3/2019Submission Deadline: 13/5/2019, 20:00

Abstract

This HW assignment is focused on image filters. We also briefly touchupon Matrix groups.

Version Log

• 1.02, 2/5/2019. In Fact 2, it is ≤, not =. Updated the deadline from 6/5to 13/5.

• 1.01, 27/3/2019. Corrected deadline.

• 1.00, 25/3/2019. Initial release.

Contents

1 Filtering 21.1 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.1.1 Viewing convolution as as one big matrix operation . . . 41.1.2 Separable Filters . . . . . . . . . . . . . . . . . . . . . . . 5

1.2 More General Filters . . . . . . . . . . . . . . . . . . . . . . . . . 71.3 Laplacian and Laplacian of Gaussian . . . . . . . . . . . . . . . . 81.4 Directional Filters . . . . . . . . . . . . . . . . . . . . . . . . . . 91.5 Computing the Spatial Derivatives (will be Required in a Later

Assignment for Optical Flow) . . . . . . . . . . . . . . . . . . . . 10

2 Matrix groups: Definition and Basic Properties 11

Few Words Before You Start

1. You will need opencv. If you can’t install opencv on your machine forsome reason, you can always use the department machine, cicero2 (moredetails can be found at the course website).

2. You may find this link useful:http://docs.opencv.org/3.0-beta/modules/imgproc/doc/filtering.

html

1

Page 2: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

3. Throughout all computer exercises below, do not implement the convo-lutions yourself; rather, use standard implementations such as those inscipy.ndimage or OpenCV (e.g., cv2.filter2D). For oft-used filters, thereare usually already functions that will spare you the need to pass thefilter as an argument (e.g., cv2.GaussianBlur).

4. Get the data:https://www.cs.bgu.ac.il/~cv192/wiki.files/hw4_data.tar

5. Some of the data is saved as (Matlab) mat files. To read these in python,use scipy.io.loadmat, which returns a dictionary. For example:

Code:

import scipy.io as sio

mdict = sio.loadmat("are_these_separable_filters.mat")

print [k for k in mdict.keys() if not k.startswith("__")]

Output:

[’K3’, ’K2’, ’K1’]

Then you can get the data more directly (in effect, as numpy arrays) via:

K1=mdict["K1"]

K2=mdict["K2"]

K3=mdict["K3"]

1 Filtering

1.1 Convolution

Let I and h be two 2D digital arrays, of possibly different sizes. We will usuallythink of I as the input image, and of h as a filter, which is usually smaller.

Definition 1 (The correlation operator) The correlation operator, ⊗,creates a new image, I ⊗ h, via

(I ⊗ h)(i, j) =∑k,l

I(i+ k, j + l)h(k, l)

k′=i+kl′=j+l

=∑k′,l′

I(k′, l′)h(k′ − i, l′ − j) �

Definition 2 (The convolution operator) The convolution operator, ∗,creates a new image, I ∗ h, via

(I ∗ h)(i, j) =∑k,l

I(i− k, j − l)h(k, l)

k′=i−kl′=j−l

=∑k′,l′

I(k′, l′)h(i− k′, j − l′)︸ ︷︷ ︸(I⊗hflipped)(i,j)

= (h ∗ I)(i, j) �

2

Page 3: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

The summation in the definitions above is done over all relevant pixels (i.e.,where h is defined), and it is assumed that the central pixel of h is the origin;e.g ., if h is 3× 3, the notation

∑k,l I(i− k, j − l)h(k, l) is short for

1∑k=−1

1∑l=−1

I(i− k, j − l)h(k, l) .

Both the convolution and correlation operators are linear.A slightly different way of writing the same thing is as∑

xi

I(x− xi)h(xi) =∑xi

h(x− xi)I(xi) (1)

where x is the pixel under consideration. Note that x enters the computationonly via its difference from each of the xi’s.

For example, if the filter h is Gaussian, and g = I ∗ h, then

g(x) =1

c

∑xi

exp

(−1

2

(x− xi)2

σ2

)I(xi) (2)

where c typically is taken as a normalizer: c =∑

xiexp

(− 1

2(x−xi)

2

σ2

).

Remark 1 You should recognize this type of expression from our discussion on,e.g., the Lucas-Kanade method. �Remark 2 Usually, if g = I ∗ h, we consider g only on the same domain asthat of I. For example, we do not bother with computing g(−1, 17), since thefirst argument, −1, is outside the domain of I. A different question, however,is what do when computing, say, g(1, 17) (assuming 1-based indexing), whichis a pixel at the boundary of g; the problem is that if h is, say, 3 × 3, thenthe summation includes terms such as I(−1, 17)h(−1, 0), I(−1, 16)h(−1,−1),and I(−1, 18)h(−1, 1) but I(−1, 16), I(−1, 17), and I(−1, 18) are undefined.In other words, we need to decide how to handle boundary effects. There areseveral ways to go about it. For example, treating I as zero at every out-of-domain pixel. In this class (unlike standard classes on signal/mage processing)we will not explore the implications of the various choices one can make forhandling the boundary effects. �Problem 1 (convolution is associative) Let a, b and c be three digital im-ages. Show that

(a ∗ b) ∗ c = a ∗ (b ∗ c)

(thus we can drop the parentheses and simply write a ∗ b ∗ c). �Definition 3 (2D discrete-domain impulse signal)

δ(i, j) =

{1 if i = 0 and j = 00 otherwise

(3)

�A filter h is also called the “impulse response” (of some system) since its

convolution with an impulse signal is h ∗ δ = δ ∗ h = h.

3

Page 4: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

Problem 2 Show that h ∗ δ = δ ∗ h = h. �Computer Exercise 1 The image used here is mandrill.png. Display it andthe results for convolving it with each one of the following filters: an isotropic7×7 Gaussian with σ = 3; an isotropic 21×21 Gaussian with σ = 10; a uniform21× 21 blur kernel ( e.g., in Python: h=np.ones((21,21))/(21**2)). �Some Python commands you may find useful for the exercise above:

scipy.ndimage.gaussian_filter; scipy.ndimage.uniform_filter;

cv2.blur,cv2.GaussianBlur.

1.1.1 Viewing convolution as as one big matrix operation

Let x ∈ RM×N be an input image. Let h ∈ Rm×n. Let y = x ∗ h. Sinceconvolution is linear, and since y is also M ×N , we may rewrite this operationas

y︸︷︷︸(MN)×1

= H︸︷︷︸(MN)×(MN)

x︸︷︷︸(MN)×1

(4)

where x is a vectorized version of x and y is a vectorized version of y. Thevalues of H are determined by h. If h is small (or large but sparse) then H issparse (i.e., most of its elements are zero).

Problem 3 Assume a zero-boundary condition. In effect, in 1-based indexing,we set I(i−k, j− l) = 0 whenever at least one of the following is true: i−k ≤ 0;i− k > M ; j − l ≤ 0; j − l > N . Assume the vectorization is done by stackingthe rows on top of each other, and that h ∈ R3×3:

x =[x(1, 1) . . . x(1, N) . . . x(M, 1) . . . I(M,N)

]T;

y =[y(1, 1) . . . y(1, N) . . . y(M, 1) . . . y(M,N)

]T;

h =

[h1,1 h1,2 h1,3

h2,1 h2,2 h2,3

h3,1 h3,2 h3,3

]∈ R3×3 .

Write the expression for the entries of H; i.e., write down the expression forHi,j for every i and j such that i ∈ {1, . . . ,MN} and j ∈ {1, . . . ,MN} whereHi,j is the entry of H in the ith row and jth column. Note that most theseentries are zero; i.e., H is (very) sparse. �Computer Exercise 2 In continue to the previous exercise, let M = 12 andN = 16. Implement H for the three different filters,

h1 =1

9

[1 1 11 1 11 1 1

]h2 =

1

8

[−1 0 1−2 0 2−1 0 1

]h3 = hT2 , (5)

and display (using imshow with “interpolation” set to “None”; use colorbar andinformative titles) the resulting H matrices (as opposed to, say, displaying someimage convolved with h).

Also note that: h1 is a uniform blur filter; h2 is the horizontal Sobel filter;h3 is the vertical Sobel filter.

Remark: if M and N are much larger (e.g.,500), we can still easily imple-ment H using a sparse matrix (e.g., using scipy.sparse.lil). But for displayingpurposes, we will have to convert it to a dense matrix, and then memory mightbe an issue. �

4

Page 5: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

Some Python commands you may find useful in the exercise above:

a.ravel; a.reshape (when a is a numpy array); plt.title; plt.colorbar.

Problem 4 Assume you are given y ∈ RM×N and h ∈ Rm×n but not x (butyou do know that x ∈ RM×N ). Suppose further that you know that y = h ∗ x.

Part (i) Under what condition on H can we invert the convolution (an oper-ation called “deconvolution”) to recover x?

Part (ii) Now suppose

h =

1 0 00 1 00 0 1

.Clearly, the 3 × 3 matrix h is invertible. Can we invert the convolution andrecover x? �Problem 5 Let

h =

[0 0 0 0 00 0 0 0 00 0 0 0 00 0 0 0 10 0 0 0 0

]. (6)

What is the effect of convolving an image with this h? (optional: try it yourselfon a computer to verify your answer) �1.1.2 Separable Filters

If we are given two 1D filters, we can build a separable filter from them (see thepractical session). Now we will address the other direction: given a 2D filter, wewould like to know whether it is separable or not. We will do this using SVD(defined below).

Definition 4 (a square orthogonal matrix) An n × n matrix Y is calledorthogonal if Y Y T = In×n . �Problem 6 Let Y be an orthogonal square matrix. Let y1, . . . ,yn denote thecolumns of Y .

Part (i) Can you uniquely determine det(Y )? If not, is there still somethingyou can say about det(Y )?

Part (ii) Show that Y T is an orthogonal square matrix.

Part (iii) Let i ∈ {1, . . . , n}. Find yTi yi.

Part (iv) Let i ∈ {1, . . . , n}. Find ‖yi‖`2 .

Part (v) Let i, j ∈ {1, . . . , n} where i 6= j. Find yTi yj. What is the anglebetween yi and yj?

Part (vi) Fix n, a positive integer. Show that n× n orthogonal matrices forma matrix group1. This group is called the orthogonal group – that isthe standard name, but perhaps the “orthonormal group” would be amore informative name. �

1For a definition, see the section on matrix groups at the end of this document

5

Page 6: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

Definition 5 (the Singular Value Decomposition (SVD) of a square matrix)The SVD of an n× n matrix A is

A = U︸︷︷︸n×n

S︸︷︷︸n×n

V T︸︷︷︸n×n

(7)

U and V are orthogonal square matrices. Columns of U (resp. V ) are calledthe left (right) singular vectors of A. The matrix S is diagonal. Its diagonalelements, {si}ni=1, are nonnegative and called the singular values of A. SVDroutines usually return the singular values sorted with s1 ≥ s2 ≥ sn. �Fact 1 Let K be a square 2D filter. It is separable if and only if its SVD hasexactly one non-zero singular value. �Example 1 The SVD of a 3× 3 K is

K = USV T =[u1 u2 u3

] s1 0 00 s2 00 0 s3

[ v1 v2 v3

]T=

3∑i=1

siuivTi . (8)

If s1 > 0 and s2 = s3 = 0 then

K = s1u1vT1 (9)

and K is evidently separable, with, e.g.,

• a vertical filter√s1u1.

• a horizontal filter√s1v

T1 . �

Computer Exercise 3 Get K1, K2 and K3 fromare_these_separable_filters.mat. Using svd, determine, based on the sin-gular values of these filters, which one is separable and which is not. Remark:due to numerical errors, you are not going to get perfect zeros even if the filter isseparable. You will have to settle for treating very small numbers ( e.g., 10−12)as zero. �Some Python commands you may find useful for the exercise above:

scipy.linalg.svd, np.diag, np.allclose.

Fact 2 If A and B are two, possibly-rectangular, matrices such that their ma-trix product, AB, is defined, then

rank(AB) ≤ min(rank(A), rank(B)) .

�Problem 7 Let K be an n×n separable filter. Is the n×n matrix K invertible?(note well, you are not asked whether the operation of convolving an image withK is invertible). �

6

Page 7: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

1.2 More General Filters

The convolution operator (similarly to the correlation operator) is not just alinear operation, it is also space invariant (also called location invariant).

More generally, we can define the following operation: I and h is given by

g(i, j) =∑k,l

I(i− k, j − l)hi,j(k, l) . (10)

The difference from convolution is that here the filter depends on the location,(i, j). For example, consider a situation where we want to blur the image butalso have reasons to expect more noise on the right part of the image. In whichcase, we may want to use a Gaussian filter such that its standard deviationincreases with x. While this filter is space-dependent (and thus applying it isnot a convolution with some filter), this filter is still linear and still does notdepend on I.

An even more general approach is to adapt the filter to the image itself; i.e.,make it a function of I. For example, suppose we want to blur an image but doit in a way that preserves edges (more on that later in this document). Thereare several ways to go about it. One of them is what is called bilateral filtering:

g(x) =1

c

∑xi

fr(|I(x)− I(xi)|)fd(|x− xi|)I(xi) (11)

c =∑xi

fr(|I(x)− I(xi)|)fd(|x− xi|) (12)

where fr controls the weight as a function of the distance in the range (i.e.,intensity difference) and fd controls the weight as as function of the distance inthe domain (i.e., spatial distance) For example we can take both these to beGaussians, of different variances:

g(x) =1

c

∑xi

exp

(−1

2

I(x)− I(xi))2

σ2r

)exp

(−1

2

(x− xi)2

σ2d

)I(xi) (13)

c =∑xi

exp

(−1

2

I(x)− I(xi))2

σ2r

)exp

(−1

2

(x− xi)2

σ2d

). (14)

Problem 8 Is bilateral filtering a linear operation? Explain. �The main purpose of the bilateral filter is to preserve edges while blurring,

as shown in the figure below:

7

Page 8: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

0 20 40 60 80

0

20

40

60

80

original noisy image

0.2

0.0

0.2

0.4

0.6

0.8

1.0

1.2

0 20 40 60 80

0

20

40

60

80

Gaussian blur

0.0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1.0

0 20 40 60 80

0

20

40

60

80

Bilateral Filter

0.00

0.15

0.30

0.45

0.60

0.75

0.90

0 20 40 60 800.4

0.2

0.0

0.2

0.4

0.6

0.8

1.0

1.2

1.4middle row

0 20 40 60 800.0

0.2

0.4

0.6

0.8

1.0middle row

0 20 40 60 800.2

0.0

0.2

0.4

0.6

0.8

1.0

1.2middle row

Computer Exercise 4 Get the (noisy) image from bilateral.mat (shown inthe left column in the figure above), and, using bilateral filtering and playing withits parameters, get a result similar to the one in the rightmost figure above. �A Python command you may find useful for the exercise above:

cv2.bilateralFilter

1.3 Laplacian and Laplacian of Gaussian

Problem 9 Calculate, by taking analytical derivatives, the Laplacian of anisotropic Gaussian (in a continuous setting); i.e.,

∇2G(x, y, σ) ,∂2G(x, y, σ)

∂x2+∂2G(x, y, σ)

∂y2=

(∂2

∂x2+

∂2

∂y2

)G(x, y, σ) ,

where

G(x, y, σ) =1

2πσ2exp(−x

2 + y2

2σ2) ,

and show it is indeed given by

∇2G(x, y, σ) =

(x2 + y2

σ4− 2

σ2

)G(x, y, σ) .

(an expression you saw in class). �

8

Page 9: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

Since G(x, y, σ) = G(x2 +y2, σ) (a sloppy notation indicating that G(x, y, σ)

depends on x and y only through r2 , x2 + y2) and since(x2+y2

σ4 − 2σ2

)can be

written as another function of x2+y2 (and σ), it is obvious that, at a given point(x, y), ∇2G(x, y, σ) is invariant w.r.t. spatial rotations of I about this point. It istempting to think that this is solely because G is rotational invariant. However,it turns out that the Laplacian of I itself is also rotationally invariant:

Problem 10 Let

x′ = x cos θ − y sin θ

y′ = x sin θ + y cos θ

and show that, independently of the value of θ ∈ [0, 2π), it always holds (assum-ing I is twice differentiable) that

∇2I(x, y) = ∇2I(x′(x, y), y′(x, y)) ,

Equivalently,

∂2I(x, y)

∂x2+∂2I(x, y)

∂y2=∂2I(x′(x, y), y′(x, y))

∂(x′)2+∂2I(x′(x, y), y′(x, y))

∂(y′)2.

�Two 3 × 3 simple discrete approximations of the Laplacian operator are

convolutions with one of the following filters: 0 −1 0−1 4 −10 −1 0

or

−1 −1 −1−1 8 −1−1 −1 −1

. (15)

Consistently with the previous exercise, we can see some (approximated) radialsymmetry (more so in the second filter).

1.4 Directional Filters

Let

g(x, y) =1√

2πσ2exp

(−1

2

x2 + y2

σ2

).

Note that:

∂xg(x, y) = − x

σ2g(x, y)

∂yg(x, y) = − y

σ2g(x, y) (16)

The top row of the figure below shows g, ∂∂xg, ∂

∂xg and u ∂∂xg + v ∂

∂y g whereu = cos θ and v = sin θ with θ = 115◦. In other words, the last filter providesan approximated directional derivative in the (u, v) direction. The second rowshows the results of convolving an image (from ascent.jpg) with these filters.

9

Page 10: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

0 5 10 15 20

0

5

10

15

20

g(x, y)

0.0020.0040.0060.0080.0100.0120.0140.016

0 5 10 15 20

0

5

10

15

20

gx

0.032

0.024

0.016

0.008

0.000

0.008

0.016

0.024

0.032

0 5 10 15 20

0

5

10

15

20

gy

0.032

0.024

0.016

0.008

0.000

0.008

0.016

0.024

0.032

0 5 10 15 20

0

5

10

15

20

∇(u, v)g

0.024

0.016

0.008

0.000

0.008

0.016

0.024

0 100 200 300 400 500

0

100

200

300

400

500

I ∗ g

0 100 200 300 400 500

0

100

200

300

400

500

I ∗ gx

0 100 200 300 400 500

0

100

200

300

400

500

I ∗ gy

0 100 200 300 400 500

0

100

200

300

400

500

I ∗ (u× gx + v× gy)

Computer Exercise 5 The image used here is ascent.jpg. Create 5 filtersthat correspond to the directional derivatives in 5 different angles of your choos-ing. Show the filters and the results of applying them to the image. �Some Python commands you may find useful in the exercise above:

np.mgrid, np.exp,np.cos,np.sin, a.sum() (where a is a numpy array),

ndimage.convolve, plt.subplots_adjust

1.5 Computing the Spatial Derivatives (will be Requiredin a Later Assignment for Optical Flow)

Computer Exercise 6 Get img1 from imgs_for_optical_flow.mat. Usingderivative filters, compute, for I=img1, the following images:

Ix =∂

∂xI = I ∗ hx, Iy =

∂yI = I ∗ hy,

Ixx =∂2

∂x2I = I ∗ hxx, Iyy =

∂2

∂y2I = I ∗ hyy .

where hx is a filter which approximates the derivative in the x direction, hy is afilter which approximates the derivative in the y direction, hxx is a filter whichapproximates the second derivative in the x direction, and hyy is a filter whichapproximates the second derivative in the y direction. You may want to blur1

I a little by convolving it with g0, a Gaussian of small standard deviation, σ0,before taking these derivatives, or, equivalently, convolve I with the derivativesof g0. �A Python command you may find useful for the exercise above:

cv2.getDerivKernels.

Note that the output of cv2.getDerivKernels will in fact be two 1D filters,

1To avoid amplifying noise and/or spatial “aliasing” – the latter is a topic covered insignal/image processing classes.

10

Page 11: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

which you can use as input to cv2.sepFilter2D. Alternatively, you can take

these two 1D filters and create a 2D filter from them:

h1,h2=cv2.getDerivKernels(1,0,3)

h1.shape is (3, 1)

h2.shape is (3, 1)

h2.dot(h1.T) then gives

array([[-1., 0., 1.],

[-2., 0., 2.],

[-1., 0., 1.]], dtype=float32)

Regarding how to compute the second derivative:

In principle, you can use cv2.sobel twice if you want. But it is better to do

it in a single operation.E.g., suppose you are using 3x3 filters.

cv2.getDerivKernels(1,0,3) gives you the "d/dx" filter.

cv2.getDerivKernels(0,1,3) gives you the "d/dy" filter.

cv2.getDerivKernels(2,0,3) gives you the "d^2/dx^2" filter.

cv2.getDerivKernels(0,2,3) gives you the "d^2/dy^2" filter.

2 Matrix groups: Definition and Basic Proper-ties

Definition 6 (Matrix Lie groups) Let n be a fixed positive integer. A ma-trix Lie group is a set G of n×n matrices together with the binary operation ofmatrix product on G (that is, the domain is G×G) such that:

(G1) In×n ∈ G;

(G2) A,B ∈ G⇒ AB ∈ G;

(G3) A ∈ G⇒ A−1 exists, A−1 ∈ G. (note AA−1 = A−1A = I) �Remark 3 The word “Lie” was the last name of the famous mathematicianSophus Lie. Note it is pronounced “LEE”, and not as the English verb “lie”. �• Matrix Lie groups are also called matrix groups, the terms being identi-

cal. It is possible to use a similar definition for matrix Lie groups whoseelements take complex values; however, we restrict the discussion to real-valued matrix Lie groups.

• Let G be a matrix group. Basic linear algebra shows that:

(G4) A ∈ G⇒ AIn×n = In×nA = A

(G5) A,B,C ∈ G⇒ (AB)C = A(BC) = ABC

(G6) A ∈ G⇒ AA−1 = A−1A = In×n.

• What (G1) through (G6) imply is that the set G, together with the binaryoperation of matrix product, is a group and that In×n is the identityelement of the group. So unsurprisingly, every matrix group is a group.When n is understood from the context, we will sometimes denote theidentity matrix by I instead of In×n.

11

Page 12: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

• If G is a set of n×n matrices, which may or may not form a matrix grouponce taken together with matrix product, it may be the case that there issome other binary operation, denoted by, say, � : G × G → G, such thatthe pair (G, �) forms a group. This group, however, is not a matrix group,although it is a “group of matrices”; e.g ., if G is n× n matrices and � ismatrix addition, than the group (G, �) is not a matrix group.

• Henceforth, by a slight abuse of notation, we will write expressions such as“G is a matrix Lie group”, with the convention that we will mean that theset G, together with matrix product, is a matrix Lie group. Similarly, wewill write “the matrix Lie group G is given by the following set”, meaningthat the set, together with matrix product, defines the matrix Lie groupof interest.

Definition 7 (The difference between two elements in a matrix Lie group)Let G be a matrix Lie group, and let A and B be in G. The group difference ofA and B is given by A−1B; it is not symmetric. �• Note that (G2) and (G3) imply the following:

(G7) A,B ∈ G⇒ A−1B ∈ G.

Properties (G2), (G3), and (G7), are referred to as the group (algebraic)closure under its operations of composition, inversion, and difference, re-spectively. Suppose our data can be represented as elements of a matrixLie group. These closure properties imply that the representation is con-sistent.

Definition 8 (Abelian matrix Lie group) If AB = BA for any A and Bin a matrix Lie group G, then G is called Abelian. �

The class of matrix Lie groups is contained in the more general class of(finite-dimensional) Lie groups: every matrix Lie group is a Lie group while theconverse is false. Matrix Lie groups are simpler to work with (and define) thanthe more general case of Lie groups. We will restrict discussion to matrix Liegroups.

Definition 9 (The general linear group of order n) The general linear groupof order n, denoted by GL(n), is given by

{Q |Q ∈ Rn×n ,detQ 6= 0}

Problem 11 Show that GL(n) is a matrix group. �Remark 4 GL(n) is not a connected space.

To see that, pick a matrix A in GL(n) with a positive determinant and amatrix B in GL(n) with a negative determinant. Then, set p = A and q = B.As det : Rn×n → R is continuous continuous curve between p and q must passthrough a matrix of zero determinant; i.e., the curve must make an excursionoutside of GL(n). In fact, it can be shown that GL(n) has exactly two connectedcomponents. �

12

Page 13: CV192, HW #4 - BGUcv192/wiki.files/CV192_HW4.pdf · 2019-05-02 · CV192, HW #4 Oren Freifeld Release Date: 25/3/2019 Submission Deadline: 13/5/2019, 20:00 Abstract This HW assignment

Definition 10 (The identity component) The identity component of a ma-trix Lie group is one that contains In×n. The identity component of a matrixLie group is always a matrix Lie group by itself. �Definition 11 (GL+(n)) The identity component of GL(n), denoted by GL+(n),is given by

{Q |Q ∈ Rn×n ,detQ > 0} .

Problem 12 Show that GL+(n) is a matrix group. �Problem 13 Show that

{Q |Q ∈ Rn×n ,detQ < 0}

is not a matrix group. �Not every set of n×n invertible matrices is a matrix group. E.g ., consider SPDmatrices. Even if A and B are SPD, C = AB is usually not SPD. The problemis not with the positive definiteness, but with the symmetry.

Problem 14 Let A and B be two n×n symmetric matrices, namely, A = AT

and B = BT . Show that, usually, AB 6= (AB)T . �Definition 12 (US(n)) The uniform scale group, denoted by US(n), is givenby

{Q |Q = SIn×n, S ∈ R>0}.

Problem 15 show the the uniform scale group is a matrix group. �

13