instructor :

​ Loannis Gkioulekas . Yannis

# lecture 1

# Linear shift-invariant image filtering

线性性(Linearity): 线性系统满足叠加原理,即对于输入信号 f1f_1f2f_2 以及常数 aabb,有:

L(af1+bf2)=aL(f1)+bL(f2)L(af_1 + bf_2) = aL(f_1) + bL(f_2)

其中,LL 表示线性系统。

平移不变性(Shift-Invariance): 平移不变性表示系统的特性不随输入信号的位置改变而改变。即如果输入信号 f(x,y)f(x,y) 平移了 (x0,y0)(x_0, y_0),则输出信号也相应平移相同的量:

L(f(xx0,yy0))=L(f)(xx0,yy0)L(f(x - x_0, y - y_0)) = L(f)(x - x_0, y - y_0)

在图像处理中,线性平移不变滤波通常用卷积操作来表示:

# 均值滤波器(Mean Filtering)

主要用于平滑图像,减少噪声。其基本思想是用一个卷积核(通常是一个大小为 n×nn \times nn×n 的矩阵)在图像上移动,每个像素点的值用其邻域内所有像素的平均值代替。

##### 操作步骤:

  1. 确定卷积核的大小(如 3x3, 5x5)。
  2. 对图像中的每个像素点,计算其邻域内所有像素的平均值。
  3. 用计算得到的平均值代替当前像素点的值。

(Ih)(x,y)=1Ni=N2N2j=N2N2I(xi,yj)(I * h)(x, y) = \frac{1}{N} \sum_{i=-\frac{N}{2}}^{\frac{N}{2}} \sum_{j=-\frac{N}{2}}^{\frac{N}{2}} I(x-i, y-j)

# 高斯滤波器(Gaussian Filtering)

基于高斯函数的线性滤波器,主要用于图像平滑和模糊处理。其特点是能保留图像的边缘细节,较少产生伪影。

# 操作步骤:
  1. 确定高斯核的大小和标准差(σ)。
  2. 生成高斯核,根据高斯函数计算每个核值。
  3. 使用高斯核对图像进行卷积操作,计算邻域内像素的加权平均值。

(Ih)(x,y)=1Ni=N2N2j=N2N2I(xi,yj)(I * h)(x, y) = \frac{1}{N} \sum_{i=-\frac{N}{2}}^{\frac{N}{2}} \sum_{j=-\frac{N}{2}}^{\frac{N}{2}} I(x-i, y-j)

# 中值滤波器(Median Filtering)

非线性滤波器,主要用于去除图像中的椒盐噪声。它通过取邻域内所有像素值的中值来替代当前像素点的值。

(Ih)(x,y)=median{I(x+i,y+j)N2i,jN2}(I * h)(x, y) = \text{median}\{ I(x+i, y+j) \mid -\frac{N}{2} \leq i, j \leq \frac{N}{2} \}

# 操作步骤:
  1. 确定滤波窗口的大小(如 3x3, 5x5)。
  2. 对图像中的每个像素点,取其邻域内所有像素值。
  3. 计算这些值的中值,用该中值替代当前像素点的值。

# Sobel 滤波器(Sobel Filter)

边缘检测滤波器,主要用于检测图像中的边缘。它通过计算梯度的大小和方向来识别图像中的显著变化。

# 操作步骤:
  1. 使用两个 3x3 的 Sobel 核,分别检测水平和垂直方向上的梯度。
  2. 对图像进行卷积操作,分别计算水平和垂直方向上的梯度图像。
  3. 计算梯度的大小和方向,得到边缘图像。

水平梯度:

Gx=[101202101]IG_x = \begin{bmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \end{bmatrix} * I

垂直梯度:

Gy=[121000121]IG_y = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bmatrix} * I

综合梯度:

G=Gx2+Gy2G = \sqrt{G_x^2 + G_y^2}

# 拉普拉斯滤波器(Laplacian Filter)

边缘检测滤波器,它通过计算图像的二阶导数来检测边缘。该滤波器对噪声敏感,通常在使用前需要对图像进行平滑处理.

# 操作步骤:
  1. 使用一个拉普拉斯核(如 3x3 的矩阵)。

  2. 对图像进行卷积操作,计算每个像素点的拉普拉斯值。

  3. 对拉普拉斯值进行阈值处理,得到二值化的边缘图像。

    h(i,j)=[010141010]Ih(i, j) = \begin{bmatrix} 0 & 1 & 0 \\ 1 & -4 & 1 \\ 0 & 1 & 0 \end{bmatrix} * I

# 方框滤波器 (Box Filter)

是一种特殊的均值滤波器,其中每个卷积核元素的值相等,且其和为 1。与均值滤波器类似

Box Filter 与均值滤波器的公式相同:

(Ih)(x,y)=1Ni=N2N2j=N2N2I(xi,yj)(I * h)(x, y) = \frac{1}{N} \sum_{i=-\frac{N}{2}}^{\frac{N}{2}} \sum_{j=-\frac{N}{2}}^{\frac{N}{2}} I(x-i, y-j)

####box filter

# 2D planar and linear transformations

image-20240727200023274

# Homogeneous coordinates

image-20240727200206731

Multiplication order matters! Transformations are applied from right to left.

# Classification of 2D transformations

image-20240727200254398

# Translation 2

\ \begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix} \

# Euclidean 3

(xy)=(cosθsinθtxsinθcosθty001)(xy1)\begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} \cos \theta & -\sin \theta & t_x \\ \sin \theta & \cos \theta & t_y \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}

# Similarity 4

(xy)=(scosθssinθtxssinθscosθty001)(xy1)\begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} s \cos \theta & -s \sin \theta & t_x \\ s \sin \theta & s \cos \theta & t_y \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}

# Affine 6

(xy)=(abtxcdty001)(xy1)\begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} a & b & t_x \\ c & d & t_y \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}

# Projective 8

(xyw)=(abcdefgh1)(xy1)\begin{pmatrix} x' \\ y' \\ w \end{pmatrix} = \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}

# Solving linear systems

# Heterogeneous linear systems

image-20240727201246348

with the optimization problem:

minxAxb2\min_{\mathbf{x}} \| A \mathbf{x} - \mathbf{b} \|^2

image-20240727201328214

# Homogeneous linear systems

image-20240727201451582

image-20240727201517001

# 解决问题
  • image A and B, find a way of transform to aligns image B to image A.
  • Support we have already find 4 pairs of corresponding points by some method:
    A:$ (x_1, y_1), (x_2, y_2), (x_3, y_3), (x_4, y_4)$

​ B:(x1,y1),(x2,y2),(x3,y3),(x4,y4)(x_1', y_1'), (x_2', y_2'), (x_3', y_3'), (x_4', y_4')

We wish to find an affine transformation matrix T :

(xy1)=(abcdef001)(xy1)\begin{pmatrix} x' \\ y' \\ 1 \end{pmatrix} = \begin{pmatrix} a & b & c \\ d & e & f \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}

We can expand the matrix equation into two linear equations:

{x=ax+by+cy=dx+ey+f\begin{cases} x' = ax + by + c \\ y' = dx + ey + f \end{cases}

For each pair of corresponding points, we have a set of such equations. For four pairs of corresponding points, we have eight equations:

{x1=ax1+by1+cy1=dx1+ey1+fx2=ax2+by2+cy2=dx2+ey2+fx3=ax3+by3+cy3=dx3+ey3+fx4=ax4+by4+cy4=dx4+dy4+f\begin{cases} x_1' = ax_1 + by_1 + c \\ y_1' = dx_1 + ey_1 + f \\ x_2' = ax_2 + by_2 + c \\ y_2' = dx_2 + ey_2 + f \\ x_3' = ax_3 + by_3 + c \\ y_3' = dx_3 + ey_3 + f \\ x_4' = ax_4 + by_4 + c \\ y_4' = dx_4 + dy_4 + f \end{cases}

We can write these equations in matrix form Ax=bA \mathbf{x} = \mathbf{b}, where:

A=(x1y11000000x1y11x2y21000000x2y21x3y31000000x3y31x4y41000000x4y41)A = \begin{pmatrix} x_1 & y_1 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & x_1 & y_1 & 1 \\ x_2 & y_2 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & x_2 & y_2 & 1 \\ x_3 & y_3 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & x_3 & y_3 & 1 \\ x_4 & y_4 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & x_4 & y_4 & 1 \\ \end{pmatrix}

x=(abcdef)\mathbf{x} = \begin{pmatrix} a \\ b \\ c \\ d \\ e \\ f \end{pmatrix}

b=(x1y1x2y2x3y3x4y4)\mathbf{b} = \begin{pmatrix} x_1' \\ y_1' \\ x_2' \\ y_2' \\ x_3' \\ y_3' \\ x_4' \\ y_4' \end{pmatrix}

通过求解正常方程 $ATAx=ATb $,我们可以得到最小二乘解 X.

# Eigenvector

Av=λvAv=λv

对于一个矩阵 A,如果存在一个非零向量 vv 和一个标量 λλ 使得Av=λvAv=λv,那么 vv 就是 A 的特征向量,λλ 是对应的特征值。

# SVD

A=UΣVTA=UΣV^T

UU: Left Singular Vectors for AATAA^T U=[u1,u2,,uM]U=[u1,u2,…,uM]

ΣΣ: Singular Values

Σ=(σ1000σ2000σr)whereσi=λi\Sigma = \begin{pmatrix} \sigma_1 & 0 & \cdots & 0 \\ 0 & \sigma_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \sigma_r \end{pmatrix} \quad where\quad \sigma_i = \sqrt{\lambda_i}

VV: Right Singular Vectors for ATAA^TA V=[v1,v2,,vN]V=[v1,v2,…,vN]

为了最小化 Ax2∥Ax∥^2 并满足 x2=1∥x∥^2=1,我们可以利用 SVD 的结果:

  1. 将优化问题转换为标准形式: 通过 SVD,我们可以将原优化问题转化为:

    Ax2=UΣVTx2∥Ax∥^2=∥UΣVTx∥^2

    因为 UU 是正交矩阵,保持向量的范数不变,所以我们可以忽略 UU

    minxΣVTx2\min⁡_{\mathbf{x}}∥ΣV^Tx∥^2

  2. 定义新变量: 令 $ y=V^Tx$,则 yy 也是一个单位向量(因为 VV 是正交矩阵)。我们需要最小化:

    Σy2∥Σy∥^2

  3. 选择最小奇异值对应的方向ΣΣ 是一个对角矩阵,其中的奇异值按降序排列。为了使 Σy2∥Σy∥^2 最小,yy 应该选择与最小奇异值对应的方向。

  4. 恢复原变量: 最后,利用 y=VTxy=V^Tx,我们可以求出满足 x2=1∥x∥^2=1xx

###Basic reading

  • Szeliski textbook, Sections 2.1, 3.6.
  • Hartley and Zisserman textbook, Section 2.

# lecture 2

阅读次数

请我喝[冰淇凌]~( ̄▽ ̄)~*

Aleo F. Leibowitz 微信支付

微信支付

Aleo F. Leibowitz 支付宝

支付宝