# 2023 NTU CV Final Review
## CH7.
### Conditioning (調節)
:::success
1. Noise Cleaning (雜訊去除)
2. Background Normalization (背景標準化或稱歸一化)
3. Sharpening (銳利化)
由資訊的樣本組成, 該樣本經過uninteresting variations所修改而得進而得到更多資訊
:::
### Labeling operators
:::success
1. Threshold operation (門檻值運算)
2. Edge Detection (邊緣偵測)
3. Line Detection (線偵測)
4. Corner Detection (邊角偵測)
他就是基於一個方法或model,來找出每個pixel與哪一組pixel相連或相關。例如,如果一張影像的pixel只有高值(200~255) 和低值 (0~100) 像素,那我們就設定一個門檻值就可以視為標記操作。其他種類的標記操作包括邊緣檢測(門檻值處理),邊角偵測。
:::
### Noise Cleaning
:::success
1. 雜訊去除: 透過 鄰居空間連貫性 與 鄰居像素同質性 去除雜訊
- uses neighborhood spatial coherence
- uses neighborhood pixel value homogeneity
2. box-filter: separable
- 透過分割的方式可以減少計算量
- 使用遞迴的方式,是為了避免多重迴圈(Nested loop)

### 7.2.1 A Statistical Framework for Noise Removal
1. idealization (理想化): 全部 pixel 為同一顏色, e.g., 純色圖
2. 雜訊去除 - 權重圖
- pixel 乘上權重後的新結果, 經過規一化 (Normalizaton) 後, 能得到去除雜訊的效果
### 7.2.3 Outlier or Peak Noise(必考)
1. outlier or peak noise(離群值):一個像素, 其像素值與其相鄰像素值明顯不同, 即像素值會被隨機雜訊替換
2. neighborhood size: 鄰居大小, 所使用的鄰居運算子其大小需要大於雜訊 並 小於觀察物
- larger than noise, smaller than preserved detail
3. center-deleted: 不包含中心點的 box 周圍
4. 決定 y 點是否為 outlier:
| x1 | x2 | x3 |
| --- | --- | --- |
| x4 | y | x5 |
| x6 | x7 | x8 |
- x1, …, xn: center-deleted neighborhood
- y: center pixel value
- $\hat{\mu}$: $\frac{1}{N} \sum_{n=1}^N x_n$, mean estimator of center-deleted neighborhood
- (1). $Z_{outlier\_removal}$: 與鄰居相近, 不移除
- $Z_{outlier\_removal} = \left\{\begin{matrix}
y, if | y - \hat{\mu}| < \theta \\ \hat{\mu}, otherwise
\end{matrix}\right.$
- (2). $Z_{constract-dependent\_outlier\_removal}$: 與鄰居標準差接近, 不移除
- $Z_{constract-dependent\_outlier\_removal}= \left\{\begin{matrix}
y, if | \frac{y - \hat{\mu}}{\hat{\sigma}}| < \theta \\ \hat{\mu}, otherwise
\end{matrix}\right.$
- (3). $Z_{smooth\_replacement}$: 離散型的轉換
- $Z_{smooth\_replacement} = \frac{ |\frac{y - \hat{\mu}}{\hat{\sigma}}| } { |\frac{y - \hat{\mu}}{\hat{\sigma}}| + K } \hat{\mu} + \frac{K}{|\frac{y - \hat{\mu}}{\hat{\sigma}}| + K } y$
- K: 權重參數 (weighting parameter)
- K = 0: 使用上 $\hat{\mu}$
- K = ∞: 使用 $y$
### 7.2.4 K-Nearest Neighbor
- $**Z_{K\_nearestNeighbor}$: 加權平均K的鄰居點**
- The average equally weighted average of k-nearest neighbors.
### 7.2.5 Gradient Inverse Weighted(梯度逆加權)
- 
### 7.2.6 Order Statistic Neighborhood Operators(有序性的運算子)
- 對脈衝式雜訊很有效, ex: salt-and-pepper noise
- 
- Median Operator: 中位數運算子
- median root image: 重複做 中位數運算子, 直到不變的圖
- 
(1) $Z_{median} = x_{(\frac{N+1}{2})}$
(2)$Z_{Running\_Median\_Operator} = \left\{\begin{matrix}
y, if | \frac{y - Z_{median}}{Q}| < \theta \\ Z_{median}, otherwise
\end{matrix}\right.$
- Q: inter-quartile distance (4分位距, 75% - 25%) = $x_{(\frac{3N+2}{4})} - x_{(\frac{N+2}{4})}$
- 整理來說, 就是在檢驗差了幾個4分位距
(3) $Z_{trimmed\_mean}$: 去除前 k 後 k 個, 再取平均
- $Z_{trimmed\_mean} = \frac{1}{N- 2k} \sum_{n=1+k}^{n-k} x_{(n)}$
(4) $Z_{midrange}$: (最亮 + 最暗) / 2
- $Z_{midrange} = \frac{1}{2} [x_{(1)} + x_{(N)}]$
### 7.2.8 Hysteresis Smoothing (滯後平滑)
- 概念: 消除小波動,保持主要狀態
- removes minor fluctuations, preserves major transients
- finite state machine with two states: UP, DOWN
- applied row-by-row and then column-by-column
- 
### 7.2.9 Sigma Filter (標準差過濾器)
- 概念: 當前的pixel 只對其兩個標準差的值 做平均 (average only with values within two-sigma interval)
- $\hat{y} = \frac{1}{\#M} \sum_{n \in M } x_{n}$
- where $M = \{ n | y - 2\sigma \le x_n \le y + 2 \sigma \}$
### 7.2.10 Selected-Neighborhood Averaging
- 概念: 算出周遭 pixel 的標準差, 找出最小後平均該 pixel 的亮度
- mean value from the lowest variance neighborhood
### 7.2.11 Minimum Mean Square Noise Smoothing
- 概念: 每個 pixel 都視為具有 noise, 找到特定參數去除雜訊 (e.g. 用機器學習找下述的 α 與 β)
- $Z = Y + ξ$
- $\hat{Y} = αZ + β$
- Z: observed pixel value
- Y: pixel value
- ξ: noise
$\hat{Y}$: estimates pixel value
- α, β: variables
- Goal: choose α and β to minimize the mean square error
### 7.2.12 Noise-Removal Techniques Experiments
- types of noise:
1. Uniform
2. Gaussian
3. Salt and Pepper
4. Varying noise
- Image Quality Benchark(量測誤差指標)(必考):
- SNR (signal to noise ratio): $SNR = 20 * log_{10} \frac{\sqrt{VS}}{\sqrt{VN}}$
- VS: 灰階標準差 (image gray level variance)
VN: 雜訊標準差 (noise variance)
單位:dB
品質好 : 40
品質一般 : 10
:::
## 7.3 Sharpening (銳利化)
:::success
- Unsharp masking: 當前 pixel 減掉 周遭平均 並放大其值
- 概念: (原圖 - 模糊) 可得到反差, 擴大反差即為銳化
- 公式: $Z_{sharpened} = s [y - k \hat{\mu}]$
### 7.3.1 Extremum Sharpening (極值銳化)
- 概念: 更靠近 erosion後的值 還是 dilation 後的值, 就更新當前 pixel 為該值(看中心pixel值, 離鄰域的極大值或極小值這兩種極值,哪個極值較近就當作輸出)
- 定義 與 公式:
- $W$: neighborhood
- $Z_{min} = f \ominus W$
- $Z_{max} = f \oplus W$
:::
## 7.4 Edge Detection (邊緣偵測)
:::success
### 名詞解釋
- Digital edge (Edge in a digital image): Boundary where brightness values are significantly different. (要找出灰階有劇烈變化的邊界)
- Edge: Brightness value appears to jump
- Step Edge: exhibits a discontinuity in the magnitude of the image intensity.
- 圖片中, 亮度的不連續
- Roof Edge: exhibits a discontinuity in the first derivative of the image intensity.
- 圖片中, 一階微分能表現出不連續
- line edge: comprise two step edges that are close together.
- 兩個 step edges 構成一個 line edge

### 7.4.1 Gradient Edge Detectors (梯度 邊緣 檢測器)
- 透過 mask 檢查 圖片的梯度, 來做邊緣檢測
- 通常會設置 threshold 來判斷是否為 edge
- 作法 (HW):
- Roberts Operators (2*2 的 filter)
- 
- Prewitt edge detector
- 
- Sobel edge detector
- 
- Frei and Chen edge detector (改善 Soble 太平滑的圖片會合併edge的缺點)
- 
- Kirsch edge detector (8個 mask 取 max)
- 
- Robinson edge detector (4 個mask, 另一組取負號即可比 Kirsch 快上許多)
- 
- Nevatia and Babu (5 * 5 的 filter)
- 
- 方向:
- gradient direction (漸變方向): dark to light. (由暗到亮)
- used for edge organization, selection, linking
- 用於邊緣組織, 選擇 與連接
- edge contour direction (邊緣輪廓方向):
1. along the edge, right side bright left side dark. (延邊右亮左暗)
2. 90° more than the gradient direction (與 gradient direction 成 90度 夾角)

- edge operator 最好符合以下四個特性:
1. Accuracy in estimating gradient magnitude (梯度大小準確)
2. Accuracy in estimating gradient direction (梯度方向準確)
3. Accuracy in estimating step edge contrast (step邊 的 對比度準確)
4. Accuracy in estimating step edge direction (step邊 的 方向準確)
### 7.4.2 Zero-Crossing Edge Detectors (跨零點 邊緣檢測器)
- 概念: 一次微分配合 threshold 可能不足夠描述邊緣, 二次微分配合新的 threshold 可看出一次微分急遽變化的表現

- 亮度分佈 方程式: 將 $r, c$ 帶入 kernel 座標, 可得預想的亮度分佈所產生的 pixel 值
- $I(r, c) = k_1 + k_2 r + k_3 c + k_4 r^2 + k_5 rc + k_6 r^2$
- 透過亮度公式的二次微分可檢測亮度劇烈變化的部份
- 亮度公式二次微分: $\nabla^2 I = 2k_4 + 2k_6$ (所做出的 kernel 必須符合u左式才算能翠取出微分資訊的 kernel)
- 
- 快速檢驗法: kernel 滿足下式就是合法的 kernel
- 
- minimum-variance digital Laplacian:
當 noise 互相獨立, 且 variance 相同時, 此 kernel 效果很好
- 
:::warning
但這些 Laplacian 運算子對雜訊很敏感, 所以有以下兩種解法
1. Laplacian of the Gaussian kernel(LOG)
- 概念: 利用高斯濾波器先平滑後, 在經過 11 * 11 的 Laplacian kernel
- 
2. Difference of Gaussian (DOG):
- 概念: 兩個 Gaussian 濾波器的差值, 構成的 kernel
- 
演算最後步驟: 設定好新的 threshold, 檢查自己超過 threshold 且周遭有小於 threshold, 表示會經過 0 點,

:::
## 7.5 Line Detection (線段偵測)
:::success
- Line segment: A line segment on an image can be characterized as an elongated rectangular region having a homogeneous gray level bounded on both its longer sides by homogeneous regions of a different gray level.
- 拉長的矩陣, 內部有一致的灰階值, 且可被另一組區別出來
- Kernel example:
- 可檢測 1-pixel 寬度的線

- 可檢測 3-pixel 寬度的線
:::
## CH8.
## 8.1 Introduction
:::success
1. observed digital image (數位觀測圖): a noisy discretized sampling of a distorted version of this surface
- 所觀測的圖假設為 帶有雜訊離散採樣的扭曲或是失真版本
2. The Facet Model: 中間 pixel 往外蒐集其他點所構成的模型
- pixel 之間的關係, 可以是常數, 線性平面(斜平面), 二次方平面, 三次方平面, …
:::
## 8.2 Relative Maxima (相對最大值)
:::success
- 公式: 函數一次微分為 0, 且二次微分為負
- first derivative zero
- second derivative negative
- 在 1度空間中, 找出相對最大值得方式:
- 序列: f1, f2, …, fN
- 最小平方公式: $\hat{c}m^2 + \hat{b}m + \hat{a}$
- -k ≤ m ≤ k, k 表示滑動視窗的大小
- e.g.:
- f1, f2, …, f6 = (3, 4, 5, 2, 7, 8); k = 1
- (-1, 3), (0, 4), (1, 5)
- 透過 least squared error fitting 找出極端值
- 公式: $\epsilon_n^2 = \sum_{m=-k}^k(\hat{c}m^2 + \hat{b}m + \hat{a} - f_{n+m})^2$
- 對此公式一階分可找出參數 $\hat{c}, \hat{b}, \hat{a}$ 的值

- 當每個視窗所得出函數的 $\hat{c} < 0$ , 其附近稱為極大值
:::
## 8.3 Sloped Facet Parameter and Error Estimation (斜平面參數與錯誤偵測)
:::success
- 概念: 將 Section 8.2 推廣到 2D 平面
- 公式: $g(r, c) = \alpha r + \beta c + \gamma + \eta(r, c)$
- 其中, $\eta \sim N(0, \sigma^2)$
- 透過微分方式, 可得 $\alpha, \beta, \gamma$

- 透過卡方分配得出誤差 $\eta$ 的 varaince:
- 卡方分配: $\sigma^2 = \frac{\epsilon^2}{(\sum_r \sum_c 1) - 3}$
- 其中 3 表示 $\alpha, \beta, \gamma$ 所限制的自由度
:::
## 8.4 Facet-Based Peak Noise Removal (小平面為準的雜訊移除)
:::success
- 概念: 透過 Section 8.3 得出每個 pixel 的誤差, 其中 (0, 0) 表示當前 pixel

- 假定虛無假設為沒有noise, 將數值放入學生 t 分佈檢測誤差是否小於信心水準 (p value), 其中 p 值越小 表示拒絕虛無假設, 即有嚴重的 noise
- 書上套用表格與公式, $t = \frac{g(0, 0) - \hat{r}} {\sqrt{ (1+ \frac{1}{\# N}) \epsilon^2 }}$
- t 值大表越有可能是 noise
:::
## 8.5 Iterated Facet Model (迭代小平面模型)
:::success
- 概念: 反覆將 Section 8.3 的公式所得的值取代觀測值, 可以得到馬賽克的效果
- The iterated model for the ideal image:
- The spatial of the image can be partitioned into connected regions called facets.
- 圖都是有小平面的圖所構成
- Each of which satisfies certain gray level and shape constraints
- 滿足灰階與形狀的限制
:::
## 8.6 Gradient-Based Facet Edge Detection (梯度為準的小平面邊緣檢測)
:::success
- 概念: 使用 Section 8.3 的公式 (其中, $\sqrt{\hat{\alpha}^2 + \hat{\beta}^2}$ 為斜平梯度的大小, 可用此為基準做邊緣檢測)
- 計算整張 image 與 n-鄰居的 $\hat{\sigma^2} = \frac{ \frac{1}{N} \sum_{n=1}^{N} \epsilon_n^2}{(\sum_r \sum_c 1) - 3}$
- 假定 梯度 $G$ 符合卡方分配, 可得 $G = \frac{ \hat{\alpha^2} \sum_r \sum_c r^2 + \hat{\beta^2} \sum_r \sum_c c^2 + } { \hat{\sigma^2}} \sim \chi_2^2$
- 給定虛無假設 $\alpha = \beta = 0$ 時, 若卡方檢定拒絕虛無, 則說明此處有傾斜
- 其中, 不拒絕虛無假設就不傾斜, 即沒有 edge
- 當 $G ≥ t$ 時 判定為 edge
- 其中, 當 r, c 為 正方形(e.g., 3*3, 5*5), 可化簡成: $G = \frac{ \sum_r \sum_c r^2 } { \hat{\sigma^2}} ( \hat{\alpha^2} + \hat{\beta^2}) \sim \chi_2^2$
- 當 noise 越大時, threshold $t$ 要越大才能檢測出真正的邊
:::
## 8.7 Bayesian Approach to Gradient Edge Detection (貝式法決定閥值 t)
:::success
- 觀念: 透過機率方式找出 8.6 提到的 threshold $t$
- isEdge: $P(edge | G ) > P ( nonedge | G)$
- 通常無法直接拿到上式, 所以引入貝式判斷:
- $P(edge | G ) = \frac{P(G|edge) P (edge)} {P(G)}$
- $P(nonedge | G ) = \frac{P(G|nonedge) P (nonedge)} {P(G)}$
- 可得: $P( G | edge) P(edge) > P ( G | nonedge) P (nonedge)$
- $P ( G | nonedge)$: 梯度 $G$ 符合卡方分配 且 符合虛無假設 $\alpha = \beta = 0$, 得以獲取
- $P(edge), P (nonedge)$: 可透過先驗假設獲取
- $P ( G | edge)$: 透過 貝氏定理獲取
- 當 $P(edge | G ) = P ( nonedge | G)$ 時的$G$就是 threshold 的取點
:::
## 8.8 Zero-Crossing Edge Detector (跨零點邊緣檢測)
:::success
- 概念: 與 Section 7.4.2 類似
### 8.8.1 **Discrete Orthogonal Polynomials(離散正交多項式)**
- 索引集合 R $: \{ -1, 0, 1 \} \in R$
- 多項式集合 $P: \{1, r, r^2 - \frac{2}{3} \}$, 其中 $r$ 從索引集合中選取
- 正交多項式需滿足: $\sum_{r \in R} P_i(r) P_j(r) = 0, 0 ≤ i < j ≤ n-1$
- $\sum_{r \in R} P_0(r) P_1(r) = \sum_{r \in R} r = (-1 + 0 + 1) = 0$
- $\sum_{r \in R} P_0(r) P_2(r) = \sum_{r \in R} (r^2 - \frac{2}{3}) = (1/3 + (-2/3) + 1/3) = 0$
- $\sum_{r \in R} P_1(r) P_2(r) = \sum_{r \in R} (r^3 - \frac{2}{3}r) = ( (-1/3) + 0 + 1/3) = 0$
- 正交多項式能被遞迴的產生出來, 而所有的多項式都能被正交多項式所表達出來
- $f(r) = \sum_{n=0}^{N-1} a_nP_n(r)$, $a_n$ 為正交多項式的參數
### **8.8.2 Two-Dimensional Discrete Orthogonal Polynomials (二維情況)**
- 對索引集合 與 多項式集合 做 外積即可獲取

- 所有二維度的多項式都能被正交多項式所表達出來
- $f(r,c) = \sum_{n=0}^{R*C-1} a_nP_n(r,c)$, $a_n$ 為正交多項式的參數
### **8.8.3 Equal-Weighted Least-Squares Fitting Problem (透過最小化error決定參數)**
- 概念: 透過最小化錯誤法獲取多項式中 $a_n$ 參數
- 公式: $min \ \ e^2 = \sum_{r \in R} [ d(r) - \sum_{n = 0}^{K} a_n P_n(r) ]^2$ , 其中 d(r) 表示 pixel 的值
- 可推得結果: $a_m = \frac{ \sum_{r \in R} P_m(r) d(r)} { \sum_{s \in R} P_m^2(s) }$
- example:
- $f(r, c) = a_0 + a_1 r + a_2 c + a_3 (r^2 -2) + a_4 rc + a_5 (c^2 -2) + a_6(r^3 - 3.4 r) + a_7(r^2 -2)c + a_8 r(c^2-2) + a_9 (c^3 - 3.4c)$
- d =

- $P_1$ =

- $a_1 = \frac{ \sum_{(r,c) \in R \times C} P_1(r,c) d(r,c)} { \sum_{(r,c) \in R \times C} P_1^2(r, c)}$ $= \frac{40}{50} = 0.8$
### **8.8.4 Directional Derivative Edge Finder (方向微分邊緣找法)**
- 將 $f(r, c)$ 轉成極座標表示法 $f_\alpha(\rho)$, 用角度微分來判斷 edge
- edge 候選滿足下式:
- $f_\alpha^{'''}(\rho) < 0$
- $f_\alpha^{''}(\rho) = 0$
- $f_\alpha^{'}(\rho) \neq 0$
- 將反曲點移動到原點(函數本質不變): $f_\alpha(\rho) → g_{\alpha}(\rho)$
- $f_\alpha(\rho) = c_0 + c_1 \rho + c_2 \rho^2 + c_3 \rho^3$
- $g_\alpha(\rho) = C(S\rho - S^3 \rho^3)$
- $C = \frac{(c_2^2 - 3 c_1 c_3 )^{1.5}}{3^{1.5}c_3^2}$
- $S = \sqrt{\frac{3c_3^2}{c_2^2 - 3 c_1 c_3}}$
- 求解可得邊緣檢測, $**C$ 與 $S$ 差別越大 越不會是邊** :
- 理想邊界參數值:

- $C = 3.16257$
- $S = \frac{1.793157} {N},$ N 為鄰居的大小
- 課本的標準參數:
- Edge Contrast (對比) = $\frac {2C}{ 3.16257}$
- Edge Scale = $\frac{S \times N} {1.793157}$ (並有對應的 lower 與 upper bound)
- dynamic range: 影像最亮減去
- 若 Edge Contrast 大於 dynamic range 的 p 倍, 就將其視為 edge
- 推薦參數: p = 0.05, lb = 0.4, ub = 1.1
:::
## 8.9 Integrated Directional Derivative Gradient Operator (略)
:::success
概念: 用面積判斷邊 (略)
:::
## 8.10 Corner Detection
:::success
- Corner 的判斷:
1. 必定出現在 edge 上(the occurrence of an edge)
2. edge 方向有明顯的變化 (significant changes in edge direction)
- Example:

- Detection Method:
- 給予三個點 $(0, 0), (r_1, c_1), (r_2, c_2)$, 其中 $(r_1, c_1), (r_2, c_2)$ 與原點等距離
- $\theta(r_1, c_1) - \theta(r_2, c_2) > threshold$ (角度差超過閥值), 稱為 corner
- 示意圖:

:::
## 8.11 Isotropic Derivative Magnitudes (各向同性)
:::success
此章節證明: 梯度大小不會因為方向改變而改變
:::
## 8.12 Ridges and Ravines
:::success
- **Ridges (山脊): 自身灰階值與鄰居相比較大**
- **Ravines (峽谷): 自身灰階值與鄰居相比較小**
:::
## 8.13 Topographic Primal Sketch (地形判別)
:::success
- 定義:

1. Peak(局部最大):
- $|| \nabla f || = 0, \lambda_1 < 0, \lambda_2 < 0$

2. Pit (局部最小)
- $|| \nabla f || = 0, \lambda_1 > 0, \lambda_2 > 0$

3. Ridge(山脊): 滿足下式任一即可
- 概念: 單一方向局部最大
- $|| \nabla f || \ne 0, \lambda_1 < 0, \nabla f \cdot w^{(1)} = 0 \ or$
- $|| \nabla f || \ne 0, \lambda_2 < 0, \nabla f \cdot w^{(2)} = 0 \ or$
- $|| \nabla f || = 0, \lambda_1 < 0, \lambda_2 = 0$

4. Ravine(峽谷): 滿足下式任一即可
- 概念: 單一方向局部最小
- $|| \nabla f || \ne 0, \lambda_1 > 0, \nabla f \cdot w^{(1)} = 0 \ or$
- $|| \nabla f || \ne 0, \lambda_2 > 0, \nabla f \cdot w^{(2)} = 0 \ or$
- $|| \nabla f || = 0, \lambda_1 > 0, \lambda_2 = 0$

5. Saddle(鞍點): 山脊 與 峽谷的交集
- $|| \nabla f || = 0, \lambda_1 * \lambda_2 < 0$
6. Flat (平面):
- $|| \nabla f || = 0, \lambda_1 = 0, \lambda_2 = 0$
7. HillSide (山坡): gradient 不為0, 且沒有嚴格極大值
- 剩餘的都稱為山坡, 並可繼續細分成以下:
- Slope: $\lambda_1 = \lambda_2 = 0$
- Convex hill: $\lambda_1 ≥ \lambda_2 ≥ 0, \lambda_1 \ne 0$
- Concave hill: $\lambda_1 \leq \lambda_2 \leq 0, \lambda_1 \ne 0$

- Saddle hill: $\lambda_1 * \lambda_2 < 0$
- Inflection point (反曲點): 二次微分為 0 的點
:::
## CH9.
:::success
## 🔥 9.1 Introduction (介紹)(Statistical Texture Feature Approach 9.2 ~ 9.10; Model-based Technique 9.11 ~ 9.13)
- Texture - ad hoc: 紋理的判斷是沒有一般解的
- Texture:
- 具有統計性質 (An image obeying some statistical properties)
- 類似結構會重複發生 (Similar structure repeated over and over again)
- 有一定的隨機性(Often has some degree of randomness)
- The texture is a non-local property: 紋理要看大空間
- Texel (Texture element):
- 組成材質的元素, 或說組成材質的基本單位
- basic textural unit of some defining spatial relationships.

- Texture Primitive (紋理圖元):
- 相同屬性會被歸類成一類 (Connected set of pixels characterized by attribute set)
- 舉例: 具有相同灰階值可歸成一類 (Simplest primitive: pixel with gray level attribute)
- Characterizing Texture (紋理特性):
- 圖元類型 (types of its primitives)
- 圖元個數 (number of its primitives)
- 空間的組成(their spatial organization or layout)
- The texture is a scale-dependent phenomenon: 紋理與觀察的縮放大小很有關係(可想成紋理是相對比較出來的)
### 🔥**紋理分析 ( Texture Analyze ) - 必考**
- 概念: 在紋理上, 常見的問題為以下 3 個
- 樣本識別(**Pattern recognition):**
- 給定紋理區間, 決定此區間是由什麼組成
- Given the textured region, determine the class the region belongs to

- 產生模型(**Generative model):**
- 給定紋理區間為 model, 重複排列組合這個model可以產生原本的 image (重複排列)
- Given a textured region, determine a description or model for it

- 紋理分段(**Texture segmentation):**
- 給定圖片, 將不同紋理區別出來
- Given image has many textured areas, determine boundaries
- 將下圖 草 與 斑馬 區別出來

## 9.2-9.3 co-occurrence (共生矩陣)
### The variant of Co-Occurrence Matrix (共生矩陣的變化法)
- 一階統計特性:
- 單看 pixel 的特性
- 直方圖, 平均值, 中值, 變異數
- 二階統計特性:
- 觀看 pixel 間的相關性
- co-occurrence (共變異數)
- 共變異矩陣 ( CH3 寫過, 略)

- The variant of the Co-Occurrence Matrix (共現矩陣的變化法):
- 公式: $p(d) = \sum_i \sum_j P(i, j), | i - j | =d$
- **當 d 越小, 其 p(d) 越大 (如下圖), 表較為粗糙**

- 優缺點:
- 優點(Advantages):
- 固定解法, 不用因為不同texture改變算法
- Use spatial interrelationships of the gray levels to characterize a texture
- 使用灰階的空間相互關係來描述紋理
- Be able to do so by gray-level transformation, which is an invariant way
- 弱點(Weakness)
- 無法利用灰階 primitive (圖元) 的形狀方面去做分析
- Not capture the shape aspects of the gray level primitives.
- 對於由大面積 primitive (圖元) 組成的紋理 或是 primitive不是單一pixel 的類型 不太可能很好地工作
- Not likely to work well for textures composed of large-area primitives.
- Cannot capture the spatial relationships between primitives that are regions larger than a pixel.
### Strong Texture Measures and Generalized Co-Occurrence
- Strong Texture:
- 看 primitives 之間的關係
- takes into account the co-occurrence between texture primitives
- 選好特定的 primitives, 就能做進一步的分析, 如以下的關係性質
- primitives 的列表 (a list of primitives)
- 列表中的中心座標(their center coordinates)
- primitives 的屬性 (their attributes)
- Spatial Relationship (空間關係):
- 𝑄 : set of all primitives on the image
- 𝑇 : set of primitive properties
- 𝑓 : function assigning to each primitive in 𝑄 a property of T
- 𝑆⊆𝑄×𝑄 : binary relation satisfying spatial relationship
- 𝑡1,𝑡2 : properties which primitives have
- f: Q → T
- formula:
- $P(t1, t2) = \frac{\# \{ (q1, q2 \in S) | f(q1) = t1 \ and f(q2) = t2 \} }{\#S}$
- 概念: 符合 t1, t2 關係的比例
## 9.4 autocorrelation (自相關)
- 自相關函數用來描述 灰階primitives 的大小
- Autocorrelation function is a feature that describes the size of gray level primitives
- 範例:

- 正常還是隨機的材質:
- 正常: 有高有低
- 隨機: 只有一個高點, 且材質大小為 peak 的寬度
- 粗糙還是細膩:
- 粗操: 波型震盪頻率低
- 細膩: 波型震盪頻率高
## 9.5 digital transform methods (變換方法)
- 概念: 透過轉換方式轉到 frequency domain (如傅立葉轉換)
- 轉換後, 原材質圖 與 亮點分布的方向成垂直
- 轉換後, 越細膩的材質, 其所呈現分布的距離原點會越近
- 範例:

## 9.6 texture energy (材質能量) by convolution
- 概念: 透過 convolution 的計算, 得到 pixel 新的意義

- 1D 材質概念:
| L5 | (Level) | = [ 1 4 6 4 1 ] | gives a center-weighted local average |
| --- | --- | --- | --- |
| E5 | (Edge) | = [ -1 -2 -0 2 1 ] | responds to row or col step edges |
| S5 | (Spot) | = [ -1 -0 -2 -0 -1 ] | detects spots |
| R5 | (Ripple) | = [ 1 -4 -6 -4 1 ] | detects ripples |
- 2D 材質概念: 用 1D 材質作 外積

- 在 segmentation 來說, 比共生矩陣的效果好
---
## 9.7 texture edgeness (材質邊緣度)
- 概念: 透過單位面積的邊緣度來判斷 (Edge per unit area)
- 用閥值作為判斷依據
- 用 gradient 大小與方向可構築 直方圖做進階的分析
- Histogram of edge magnitude and direction for a region
---
## 9.8 vector dispersion (向量色散)
- 概念: 用上了 CH8 的小平面方法
- 單位平面上的法向量或差很多, 可判定材不同材質
- 範例:

- 判定標準:
- **係數越接近, 材質越平滑**; 反之, 係數越不接近, 材質越粗糙
---
## 9.9 relative extrema density (相對極值密度)
- 概念: 透過單位面積的相對最大最小來判斷
- 範例1:
- **fine: 相對極值出現頻率高**
- **coarse: 相對極值出現頻率低**


---
## 9.10 mathematical morphology (數學形態學)
- 概念: 用數學形態學輔助判斷, 主要分成以下兩大類
- Granularity (顆粒度)
- Fractal (碎形)
### The granularity (顆粒度) of a binary image F
- 數學表達式: $G(d) = 1 - \frac{\# (F \circ H_d) }{\#F}$
- 概念: 透過 opening 運算子來區別材質的顆粒度(d)
- $G(d)$: 比 d 還小的部分的比例
### Fractal (碎形)
- 概念: **recursive and self-similar** (可用遞歸且自類似所產生的圖)
- **定義: A fractal is a natural phenomenon or a mathematical set that exhibits a repeating pattern that displays at every scale.**
- 在不同尺度下都能有重複樣板
- 範例:

- 會定義出額外的 fractal signature S 來比較不同材質的差別(此處不太考)
---
## 9.11- 9.13 Model-based Technique (基於模型技法)
- 概念: 用樣板做估計, 並做額外的驗證
### 9.11 autoregression (自回歸)
- 前提假設: 下面一個 pixel, 由前面 pixel 與 noise組成
- 最後透過誤差來決定材質類別
- fine: 係數會非常不同
- coarse: 係數會非常接近

### 9.12 Markov random field
- 概念: 透過鄰居來推得與目標間的關係, 可用來做 segmentation
- 示意圖:

### 9.13 random mosaic models
- 概念:
- Provide a means of tessellating a plane into cells (將平面分成數個單元)
- Assign a property value to each cell (給每個單元一個特性值做判斷)
- 常用的分割方式:
- Poisson Line Model:
- 概念: 用 Poisson 分布產生參數, 在用參數形成的線作分割

- Occupancy Model:
- 概念: 用 Poisson 分布產生點, 以此為依據找出劃分依據

- Delaunay Model:
- 概念: Occupancy Model 的對應圖


## 🔥9.xx Application (應用)
- Segmentation: 圖片分割
- Synthetic Texture Image Generation: 材質合成圖

- **🔥Synthetic Texture Image Generation (合成材質產生法):**
- 步驟:
- step1: 找到區塊
- step2; 用相近的邊找到接近的區塊
- step3: 貼上該區塊
- step4: 重複 step2 ~ 3 直到整張圖完成
- step5: 邊緣優化
- 特性: 越大塊的單位, 產出的材質圖越平滑
- 範例:

- Shape from Texture (透過材質辨別 3D 物件的方向):
- 假設:觀察到的紋理區域沒有深度變化, 觀察到的紋理區域對應到3D物件後無特別紋理變化, 且沒有子紋理
- 範例:

:::
## CH10.
:::success
## 10.1 Introduction (介紹)
- image segmentation:
- partition of the image, which is the set of non-overlapping regions and its union of segmented regions is the entire image
- 由不重疊的區域構成的圖, 且分割的圖有其特殊意義
- example:

- Guideline (分割指引):
- 需有相似的屬性

- 不同區塊要能有所區別

- 簡單無小洞

- 簡單無鋸齒

- image segmentation 特性:
- ad-hoc
- 不同技法有不同妥協與強調的部分 (Different techniques rely on different **emphasis** and **compromise**)
---
## **🔥**10.2 Measurement-Space-Guided Spatial Clustering (空間叢集)
- Measurement space (觀測空間): The pattern of measurement data to be classified is represented as a measurement vector
- 被觀測向量所表達, 進而做到分類的樣板
- Spatial Clustering (空間叢集): A bounded group of occurrences and concentration to be unlikely to have occurred by chance.
- 有邊界且集中度的事件組所構成的叢集
- 範例:

- 演算法步驟 (step):
- Uses the measurement-space-clustering process to define a partition in measurement space (定義其特徵)
- Each pixel is assigned the label of the cell in the measurement-space partition to which it belongs. (給予 label 值)
- The image segments are defined as the connected components of the pixels having the same label. (用連接算子進行合併)
- 缺點 (Problem with measurement-space-clustering):
- There is no requirement for good spatial continuation. (若圖片太複雜就沒有良好的空間連續性)
- The resulting boundaries are very noisy and busy. (邊緣通常有許多噪點)
### Recursive Histogram-Directed Spatial Clustering (遞迴直方圖空間叢集)
- 概念: 透過直方均化圖, 遞迴的山峰叢集起來直到無變化

### 10.2.1 Threshold (閥值法)
- 概念: 若直方均化圖不是雙峰 (bimodal) 的解法
1. Local Histogram (區域內直方圖):
1. 切多個塊
2. 每塊都有直方圖與其閥值
3. 內插閥值
2. High Laplacian Magnitude: 找邊緣做為切割依據
3. Minimized Busyness: 看雜訊的程度來做切割
- **🔥Kohler's (1981) method: high-contrast edges and fewer lower-contrast edges.**
1. 給定兩 pixel 介於閥值兩端
2. 計算平均對比度
3. 找出平均對比度越大的為結果

- Panda and Rosenfeld(1978): Approach for segmenting white blob against the dark background (提取白塊)
- 概念: 低梯度取山谷 (valley), 高梯度取平均。即不同梯度用不同閥值

)
### 10.2.2 Multidimensional measurement-space clustering (高維度空間叢集)
- 概念: 衛星圖, 會用不同波段的方式紀錄影像
- 特性:
- band 與 band 之間有高度相關性
- 存在大量多餘的資料
- 有多個組合, 可以將不同波端進行進一步的叢集
---
## 10.3 Region Growing (區域擴增法)
### 10.3.1 Single-Linkage:
- 概念: pixel 相近就連起來
- 缺點: 漸層影像 會合再一起
### 10.3.2 Hybrid-Linkage:
- 概念: 用 k*k 的區域 與 屬性向量判斷
- 缺點: 過於依賴 邊緣運算子, 其太簡單會無效果
- 解法1: CH8 的 Zero-Crossing 運算子
- 解法2: 小平面模型 (概念為由定義好的區域來做合併的輸入)
### 10.3.3 Centroid-Linkage:
- 核心概念: 不在看鄰居的相似度
- Pairs of neighboring pixels are not compared for similarity
- 步驟:
1. 掃描整張圖
2. 計算區域平均
3. 更新區域平均
4. 若有類似就合併
5. 若無類似就形成新的區域
---
## 10.4 Hybrid-Linkage Combination (混合法):
- 概念: 結合 10.3.3 Centroid-Linkage 與 10.3.2 Hybrid-Linkage
- Centroid-Linkage 不能用到 ege pixels
- Region growing 不同跨 edge 合併
---
## 10.5 Spatial Clustering (空間叢集):
- 概念: 與 10.2 類似
- 實際算法:
- 找到直方均化圖的 peak, 由大到小依序做 region growning

---
## 10.6 Split and Merge (分割與合併):
- 步驟:
- 整張圖片 **不夠同質 就分割**
- 不夠同質的依據: Max-min, Variance
- 進行合併判斷
- 缺點:
- 邊界為方塊, 且 過於人為 (Boundaries tend to be squarish and artificial)
- 過多記憶體消耗 (Large memory usage)
- 無正確合併 (Miss-merging)
- 範例:

### 10.6.x Quad Tree
- 概念: 透過樹狀結構, 解決上述的問題
- 步驟:
- 先 split 在合併, 且依次會將 子節點 做分割 或是 合併
- 最後會進行最後的合併步驟 (final grouping procedure)
- 範例:

---
## 10.7 Rule-Based Segmentation (規則導向的分割)
- 概念: **定義資料, 屬性 (STM)** 與 **規則, 行為(LTM)**, 透過**匹配 STM 適合的 LTM 進行分割**
- **The short-term memory (STM)**: 處理的資料
- holds the input image, the segmentation data, and the output.
- **The long-term memory (LTM)**: 規則與行為
- system knowledge about low-level segmentation and control strategies.
- Level1: 根據情境編碼
- level 1 are knowledge rules that encode information properties of regions, lines, and areas in the form of situation-action pairs.
- Level2: 引入控制規則
- Focus-of-attention rules (每輪動作的資料類型)
- Inference rules (匹配與執行的順序)
- Level3: 策略, 選擇控制規則, 執行適當的策略
- Strategy rules.
- Select the set of control rules (level 2).
- Executes the most proper control strategy for a given set of data.
- workflow:

---
## 10.8 Motion-Based Segmentation (基於移動的分割)
- 概念: 針對連續影像作分割 (即針對影片分割)
### 10.8.1 Stationary camera: Tompson
- 概念: 不同速度就分割 (根據速度, 相似合併, 不同分割)
### 10.8.2 Non-stationary camera: Jain
- 概念: 引入 focus of expansion 做判斷 (See Chapter 15)
:::
## CH11. Arc Extraction and Segmentation (弧長與分段)
:::success
## 11.1 Introduction (介紹)
- Group Operation (群組運算): 將序列的pixel 組在一起的運算
- 可以用來找出 border 的座標
---
## 11.2 Extracting Boundary Pixels from a Segmented Image (萃取已分段圖片的邊界)

- 使用 link list 來快速找到邊界
- 迴圈由左到右, 由上到下
- 若當前 pixel 鄰居不在 list 的結尾
- 目前尚無此分段的list, 產生一組新的 list
- 若有此分段, 則略過此 pixel
- 若當前 pixel 鄰居在 list 的結尾
- 選擇能讓邊界形成順時針方向為主的 list 加入
- 若左, 上都為 list的結尾, 選擇上面的list

- 迴圈結束後, 串起不同分段的 list 即可
- 示意圖:

---
## 11.3 Linking One-Pixel-Wide Edges or Lines (線段串接)
- 簡介: 11.2是在說明分段後的邊界問題, 但有時候問題是不重視區塊並檢測線段, 所以可能更為複雜
- 找處下圖的線段

- 演算法:
- 先定義 pixel 不同的類型, 並對於不同類型做不同的處理
- isolated point (孤立點)
- interior pixel (內部點)
- junction (交匯點)
- corner (轉角)
- …
- 遇到 junction (交匯點) 或 corner (轉角) 結束一個線段, 並開啟新的線段
- 結果1: 將 (5,3) 的點是為 corner 結果為下

- 結果2: 將 (5,3) 的點是為 interior pixel, 結果為下

---
## 11.4 Edge and Line Linking Using Directional Information
- 概念: 加入方向性的考量, 並用 t 檢定合併線段
---
## 11.5 Segmentation of Arcs into Simple Segments (分割弧線形成線段)
### 11.5.1 iterative endpoint fit and split
- 輸入: 弧線與兩端點
- 步驟1: 算出兩端點的直線方程L
- 弧線中的點B, 找出其與L的距離 $d_i$
- 若最大的 $d_i$ 超過閥值, 就將其分段

### 11.5.2 Tangential Angle Deflection
- 概念: 透過 cos函數找到最大角度, 進而推出交匯點 P, 用P作為分段依據
### 11.5.3 Uniform Bounded-Error Approximation
- 概念: 用一個區域線段做分段
- 步驟:
- 由 P 點發出射線, 遇到障礙就停止
- Q點也發出設線, 與 P點停止的射線平行, 即找到點 y

### 11.5.4 and 11.5.5
- 概念: 說明優化分段的小細節
- breakpoint optimization:
- break point 的優化, 將點分成 odd 與 even
- 移動 odd 結尾點, 若錯誤減少則為新的break point
- 移動 even 結尾點, 若錯誤減少則為新的break point
- split and merge:
- 將弧線切開, 若合併錯誤會減少合併
- 最後調整 break point
### 11.5.6 Isodata segmentation
- 概念: 用 line-fit 做叢集
### 11.5.7 Curvature 曲率
- 概念: 用2次微分的係數做判斷
---
## 🔥 11.6 Hough Transform (霍夫轉換)
- 概念: 找一條線使得經過的點最多
- 演算是透過斜率 與 accumulator array 紀錄, 來完成
- 其中, 由於斜率可能會無限大, 所以換成與原點的距離

- 角度有360 度 且 距離值d 並不多, 所以矩陣大小應當不大

- Finding Circles (找圓) 也是相同原理, 只是多了幾個參數而已
## 11.7 Line Fitting (擬合線段)
- 概念: 透過最小平方法找到直線方程式的係數
- 演算流程: 寫下直線方程式與其限制式, 將點帶入直線方程式, 微分求解即可。

- **11.7.2 Principal-Axis Curve Fit (曲線的fitting)**
- 概念: 與上述相同, 只是參數量變多而已

:::
## TA's Research (必考)
:::success
### 1. AIoT Development Platform for Active Speaker Detection
- Purpose:
1. To develop an Active Speaker Detection System
- Method:
1. Nvidia Jetson Nano Developer Kit 2GB
2. Visual Feature Encoder, Audio Feature Encoder, Detector
- Result:
1. Show active speaker with bounding box in every frame
### 2. ECG ARTIFACT REMOVAL FROM SINGLE-CHANNEL SURFACE EMG USING FULLY CONVOLUTIONAL NETWORKS
- Purpose:
1. Remove ECG artifacts from single-channel sEMG based on FCN denoising method.
- Method:
1. Input Contaminated sEMG signal => FCN => Output reconstructed sEMG.
- Result:
1. Make the reconstructed sEMG to have very low ECG artifacts.
### 3.LinFusion: Millimeter Wave Radar and Color Camera Fusion for People Tracking
- Purpose:
1. Deep learning-based coordinate calibration and spatial position estimation methods to improve fusion accuracy.
- Method:
1. Time synchronization on two sensors’ input data -> Position Estimation & Coordinate Calibration -> UID Assignment based on Hungarian Algorithm
- Result:
1. This system maintains consistent IDs for targets within the range of both sensors.
### 4. Speech Enhancement in Edge Devices
- Purpose:
1. AVSE for feature extraction and BLSTM for speech enhancement
- Method:
1. Separate video into image and audio, extract lip motion from video, then feed both into model
- Result:
1. AVSE-SSL has best quality, AVSE second, and AOSE third
### 5. Reducing obstructive sleep apnea after OGS surgery by evaluating the cephalometric parameters : single medical center study
- Purpose:
1. Reducing obstructive sleep apnea after OGS surgery
- Method:
1. By evaluating the cephalometric parameters from single medical center
- Result:
1. Apply these significant data in doing simulation to reduce OSA after surgery
:::