# Homework 0

The autoreload extension is already loaded. To reload it, use:


# Question 1: Linear Algebra Review

Please implement all the required methods in linalg.py.

## Question 1.1 (5 points)

Define the following using numpy:
$$M = \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \ 10 & 11 & 12 \end{bmatrix}$$

$$a = \begin{bmatrix} 1 & 1 & 0 \end{bmatrix}$$

$$b = \begin{bmatrix} -1 \ 2 \ 5 \end{bmatrix}$$

M =
[[ 1  2  3]
[ 4  5  6]
[ 7  8  9]
[10 11 12]]
a =  [1 1 0]
b =  [[-1]
[ 2]
[ 5]]


## Question 1.2 (5 points)

Implement the dot_product method in linalg.py and check that it returns the correct answer for $a^Tb$.

numpy函数：np.dot

[1]


## Question 1.3 (5 points)

Implement the matrix_mult method in linalg.py and use it to compute $(a^T b)Ma$

numpy函数：np.matmul(

[ 3  9 15 21]


## Question 4 (10 points)

Implement the get_singular_values method. In this method, perform singular value decomposition on the input matrix and return the largest n singular values (n specified in the method calls below).

numpy函数：np.linalg.svd

[ 25.46240744]
[ 25.46240744   1.29066168]


## Question 1.5 (10 points)

Implement the get_eigen_values_and_vectors method. In this method, perform eigen value decomposition on the following matrix and return the largest n eigen values and corresponding eigen vectors (n specified in the method calls below).

numpy函数：np.linalg.eig

$$M = \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \end{bmatrix}$$

Values =
[ 16.11684397]
Vectors =
[[-0.23197069 -0.78583024  0.40824829]]
Values =
[ 16.11684397  -1.11684397]
Vectors =
[[-0.23197069 -0.78583024  0.40824829]
[-0.52532209 -0.08675134 -0.81649658]]


# Part 2: Image Manipulation

## Question 2.1 (5 points)

Implement the load method in imageManip.py and read the display method below. We will use these two methods through the rest of the notebook to visualize our work.

## Question 2.2 (10 points)

Implement the change_value method by converting images according to $x_n = 0.5*x_p^2$ for every pixel, where $x_n$ is the new value and $x_p$ is the original value.

## Question 2.3 (10 points)

Implement the convert_to_grey_scale method and convert the image into grey scale.

## Question 2.4 (10 points)

Implement the rgb_decomposition, in which the input image is decomposed into the three channels: R, G and B and return the image excluding the specified channel.

RGB分解，在scikitimage中，R，G，B分别对应numpy的0,1,2三个通道。

## Question 2.5 (10 points)

Implement the lab_decomposition, in which the input image is decomposed into the three channels: L, A and B and return the values for the specified channel.

LAB分解，在scikitimage中，L，A，B分别对应numpy的0,1,2三个通道

color.rgb2lab将图像进行RGB->LAB空间。

## Question 2.6 (10 points)

Implement the hsv_decomposition, in which the input image is decomposed into the three channels: H, S and V and return the values for the specified channel.

HSV分解，在scikitimage中，H,S,V分别对应numpy的0,1,2三个通道

## Question 2.7 (10 points)

In mix_images method, create a new image such that the left half of the image is the left half of image1 and the
right half of the image is the right half of image2. If the channels are specified, exclude the specified channel for the given image.

numpy函数np.concatenate进行矩阵的拼接。