# 2023 NTU CV Midterm Review
## 一些關於這堂課的基本概念= =
### 1.老師的姓名 (必考)
:::success
傅楸善
:::
### 2.老師的金句 (必考)
:::success
笑話比本文重要
:::
### 3. Computer vision
:::success
- 指用攝影機和電腦代替人眼對目標進行辨識、跟蹤和測量等,並進一步做圖像處理,用電腦處理成為更適合人眼觀察或傳送給儀器檢測的圖像
- 應用: 瑕疵檢測、物件偵測
:::
### 4. Gray-level image
:::success
- 灰階就是指不同程度的灰⾊,通常由8 bit 儲存,0為最暗,255為最亮。灰階圖可以看成是圖的亮度。灰⾊圖像是由彩⾊圖像的3個通道(RGB)轉換成1個通道⽽來,原先彩⾊圖像共有$256^3$種顏⾊變化,⽽灰度圖像只有256種,將其轉換的⽬的能讓圖片依然清楚,同時能減少後續的計算量。
:::
### 5. Pattern recognition (圖型識別):
:::success
用數學技術方法來研究圖形的處理和判讀。
:::
### 6. Conditioning
:::success
- **110 official answer:**
- 內容:Conditioning is based on a model that suggests that the observed image is composed of an informative pattern modified by uninteresting variations that typically add to or multiply the informative pattern. (調節是基於一個模型,該模型觀察到的圖像由帶有資訊的形狀組成,這些帶有資訊的圖形被我們不會感興趣的變化所修改,這些變化通常是加法或乘法。)
- 目的:去除無用的資訊、雜訊
- 應用:降躁、背景均一化
- 給分標準:三取二。去除無用的資訊、降躁
:::
### 7. Labeling
:::success
- **110 official answer:**
- 內容:Labeling is based on a model that suggests that the informative pattern has a structure as a spatial arrangement of events, each spatial event being a set of connected pixels. (標記是基於一個模型,該模型帶有資訊的形狀具有作為事件的空間排列的結構,每個空間事件都是一組連接的像素。)
- 目的:讓電腦將相同特性的像素給予相同編號
- 應用:閥值化、邊緣檢測、自駕車、機器人、相片搜尋、影片檢索、商品搜尋、辨識影像中的各種物體、thresholding、edge detection、corner finding
- 給分標準:三取二
:::
### 8. Grouping
:::success
- **110 official answer:**
- 內容:The grouping operation identifies the events by collecting together or identifying maximal connected sets of pixels participating in the same kind of event. (分組操作通過收集或識別參與同一類事件的最大連接像素集來識別事件。)
- 目的:有利於將群組化後的資訊進行一些計算
- 應用:segmentation分割、edge linking邊緣鏈接
- 給分標準:三取二、只寫「圈出來」不給分
:::
## CH2
### Q1. What is Thresholding? And please describe it in detail. (必考)
:::success
Answer:
Thresholding is a labeling operation on a gray scale image. Thresholding distinguishes pixels that have higher gray values from pixels that have lower gray values. Pixels whose gray values are high enough are given the binary value 1.
Pixels whose gray values are not high enough are given the binary value 0.(Thresholding是在灰階圖上的一種操作, 主要是將一張圖片的像素一分為二, 設定一個數值作為依據, 若pixel值大於等於此數值則為1, 小於則為0。)
:::
### Q2. Please write down the steps of the iterative algorithm.. (必考)
:::success
Answer:
Step 1. Initialization of each pixel to a unique label.(將每個像素賦予不同的標籤)
Step 2. iteration of top-down followed by bottom-up passes until no change.(執行由上而下,再由下而上的迭代更新label值, 直到label值不再更動。)
:::
### Q3. Please write the 4 algorithms for connected component analysis and explain in detail.
:::success
- 迭代演算法(An Iterative Algorithm):先top-down傳播,再bottom-up傳播,直到沒有變化。
- 經典演算法(The Classical Algorithm):使⽤兩次⾃上⽽下的傳播,並⽤global table儲存標籤。
- 省空間演算法(A Space-Efficient Two-Pass Algorithm That Uses a Local Equivalence Table):使⽤local table儲存當前這⾏跟前⼀⾏的等價值。
- 省時間演算法(An Efficient Run-Length Implementation of the Local Table Method):使⽤變動長度的碼來取代連續重複出現的原始資料。
:::
### Q4. Background
:::success
影像中不太重要的區域。
:::
### Q5. Histogram
:::success
統計灰階影像的亮度, 其中#符號為取數量。
:::
### Q6. Histogram Equalization (直方均衡圖)
:::success
- 利用 histogram 算出各個灰階值的 probability density function
- 將 PDF 做累加求出 CDF,
- 將 CDF 的結果4捨5入後建構一組對照表
- 將 對照表結果 與 轉換公式 進行換算,求得各個灰階值的機率
```
global histogram equalization的目的是要把CDF的形狀排成整齊的直角三角形,
所以會將每條CDF放到合適的位置,使得對邊(CDF的值)與鄰邊(CDF * max value)是一個固定的比例,
這樣排出來的CDF會近似成一個漂亮的直角三角形。
```
:::
### Q7. Signature
:::success
- 經過遮罩 (mask)的圖片且結果為非0的pixel 所構成的直方圖(Histogram)。
:::
### Q8. Signature analysis
:::success
- 筆跡學,分析簽名圖像 :
1. 將影像⼆值化
2. 投影分割
3. 區域性值計算
4. 根據投影做出決策
:::
### Q9. Signature Segmentation
:::success
經過一次或多次投影的分段結果。
:::
## CH3
### Q1. Centroid & Area(必考)
:::success
Centroid
- 質心
- The centroid or geometric center of a plane figure is the arithmetic mean position of all the points in the shape.(以幾何的角度,質心就是所有位置點的算數平均位置)
Area
- 區域(region)的面積
:::
### Q2. Border Pixel (必考)
:::success
- 邊界像素: 像素的相鄰像素包含了非區塊內像素.我們稱為border pixel。
- P4:用8連通方式來決定邊界像素, 8個方位只要有一個是outside pixel就代表是border,有趣的是,產生出來的邊界像素彼此會是4連通。所以才叫P4,也可以寫做B4。
- P8:用4連通方式來決定邊界像素, 4個方位只要有一個是outside pixel就代表是border,同上述,產生出來的邊界像素彼此會是8連通。所以才叫P8,也可以寫做B8。
:::
### Q3. Perimeter Length of Border Pixel (必考)
:::success

:::
### Q4. Co-Occurrence matrix(共生矩陣) (兩個pixel之間的關係)
:::success
- 可應用於紋理分析於瑕疵檢測的應用
- E.g. 1.
Pixel的水平共生矩陣 :
- 上圖共生矩陣
- 下圖灰階值
- 兩個像素點距離為1 角度為0
- 水平方向之像素pair的集合
- 下圖範例為 : 在原始影像中有多少個組合是"相鄰兩個pixel的值為0",注意!左到右和右到左各算一組。
- 
- E.g. 2.
P~H~ P~V~ P~LD~ P~SD~ 共生矩陣範例
- 
:::
### Q5. Extremal points(邊界矩形極點)
:::success
- 角度規則

- 與一般的笛卡兒座標系不同,row的部分是越往下數字越大,所以計算時要成一個負號

- 長度的計算(注意!點距離算完後,還要加Q($\theta$))

:::
### Spatial Moments 和 Signature Properties(這個有興趣自己去研究,都是數學很難整理歸納XD,放一些重點就好)
:::success
1. Spatial Moments
- 
- 
2. Signature Properties
- 
-
- 
-
- 
:::
## CH4
### Q1. Unit
:::success
圖片的區域或是投影後的分段。
:::
### Q2. Economic Gain Matrix
:::success
Economic Gain Matrix 之間呈 線性, 則 decision rule 是不變的
(看不同的 economic gain matrix 對於 decision rule 的影響,
證明兩 economic gain matrix 若互為線性組合只差一個常數或正係數,
這樣 bayes decision rule求出最大經濟增長期望值的a類別會相同於最大增益值出現在a)

:::
:::warning
### Some notation
$P(g|g)$: 真實為g的情況下被指派g的事件發生機率
$P(g,g)$ 此determine rule將真實為g被指派為g的機率
- 
- 
- 
:::
### Q3. False-Alarm Rate (假警報率) : $P(b | g)$
:::success
- FN
- Type I Error (型I錯誤): 對的判斷是錯的。
:::
### Q4. Misdetection Rate (漏檢率) : $P(g | b)$
:::success
- FP
- Type II Error (型II錯誤): 錯的判斷是對的。
:::
### Q5. Table 1.1 gives the conditional probabilities for operating point (0.1, 0.2) (misdetection rate, false-alarm rate). Table 1.2 lists the economic consequence for each possible outcome. Given the prior probability of an object being good and bad is 0.95 and 0.05 respectively. Please calculate the expected profit per object manufactured.
:::success
### 上面是Table 1.1 下面是Table 1.2

Ans : $E = [0.8*2000 + 0.2* 100]*0.95 + [0.9*(-100) + 0.1*(-10000)]*0.05 = 1446.5$
:::
### Q6. Decision Rule Construction
:::success
- t : truth
- a : Assign()
- d : measurement
- 
:::
### Q7. Fair Game Assumption
:::success
- $P (a| t, d) = P (a|d)$
- 即便給予t, decision rule的行為機率也要和沒給t時相同
:::
### Q8. Bayes decision rule (必考)
:::success
- Bayes’rule 要把結果全部assign給機率最高的類別(相同d下, 判斷出哪個分類經濟效益最高, 就給把其機率設為1)
- 貝氏決策規則就是考慮所有觀測,將結果 assign 成可以獲得最大經濟增益值的類別。
:::
### Q9. Maximin decision rule (有機會考,要寫到"最小條件經濟增益值的數值中最大的那個")
:::success
在所有的決策規則中,選擇各自決策規則獲得最小條件經濟增益值的數值中最大的那個,即最大(的)最小決策規則。
:::
### Q10. Reserved Judgment (必考)
:::success
- Reserved judgment為decision rule提供了另一種選擇。
1. Reserved judgment可有效控制誤差率
2. 對於某些測量值,decision rule可能會抑制某些判定結果。
3. decision rule被對於那些它指定的測量值所抑制的判定結果和誤差率的時間比率所描述
:::
## CH5
### Q1. Hexagonal Grid(六邊形網格)
:::success
與鄰近座標距離一致
:::
### Q2. Mathematical Morphology
:::success
用 各種理論 分析與處理圖片中的幾何形狀
:::
### Q3. Dilation
:::success
- 用向量加法將兩個 set 的元素結合在一起
- 數學表示: $A⊕B=\{ c∈E^N|c=a+b,a∈ A \ and \ b∈B\}$
- **110 official answer:**
- 內容:
- 膨脹操作會把高亮(即值為255)的邊界膨脹開。
- 設定卷積核尺寸,卷積核沿著圖像滑動,與卷積核對應的原圖像的像素值中只要有一個是1,中心元素的像素值就是1。
- 形態學中基本的算子之一,combines two sets by vector addition of set elements。A⊕B={c∈E^N│a+b for some a∈A and b∈B}。
- 目的:如果以白色部分為前景,會使圖片中較亮的範圍變大
- 應用:可用於填補圖片中的小黑洞
- 給分標準:任何定義上的符號、公式等等給1分,目的只要寫到"填補黑洞"、"前景範圍擴大"等等,或是應用寫了任何實際畫圖舉例都算對,可得1分。直接英翻中而沒有其他敘述(eg:只寫了膨脹兩字,但沒寫膨脹什麼、對影像的什麼部分做膨脹處理)不給分。
:::
### Q4. Erosion
:::success
- 數學表示: $A ⊖ B=\{ x∈E^N|x+b \in A \ for\ every \ b \in B\}$
- **110 official answer:**
- 內容:
- 腐蝕操作會把高亮(即值為255)的邊界腐蝕掉。
- 設定卷積核尺寸,卷積核沿著圖像滑動,如果與卷積核對應的原圖像的所有像素值都是1,那麼中心元素就保持原來的像素值,否則就變為0。
- morphological dual of dilation
- A⊝B={x∈E^N│x+b∈A for every b∈B}
- 目的:如果以白色的部分為前景,會使圖片中較亮的部分縮小
- 應用:能消除部分雜訊
- 給分標準:任何定義上的符號、公式等等給1分,目的只要寫到"消雜訊"、"前景範圍縮小"等等,或是應用寫了任何實際畫圖舉例都算對,可得1分。直接英翻中而沒有其他敘述(eg:只寫了侵蝕兩字,但沒寫侵蝕什麼、對影像的什麼部分做侵蝕處理)不給分
:::
### Q5. Opening
:::success
- 對 set, 先 eroision 再 dilation
- 數學表示: $B \circ K = (B \ominus K) \oplus K$
:::
### Q6. Closing
:::success
- 對 set, 先 dilation 再 eroision (口訣: cde, c就是先d再e)
- 數學表示: $B \bullet K = (B \oplus K) \ominus K$
- **110 official answer:**
- 內容:在數學形態學中,閉運算被定義為先膨脹後腐蝕。
- 目的:能夠消除小型黑洞
- 應用:能夠消除小型黑洞
- closing of image B by kernel K: B∙K=(B⊕K)⊝K

- 給分標準:任何定義上的符號、公式、寫到"先膨脹後腐蝕"等等給1分,目的/應用只要寫到"填補黑洞"、"平滑銳角"及其他類似可替換之應用,或是直接舉例都算對,可再得1分。
:::
### Q7. Please design 3 kernels and steps by using the morphological operation to process Figure A to obtain the result as shown in Figure B. The size of one pepper and salt noise is 1 pixel. It is necessary to meet the following conditions:
1. Remove pepper and salt noises.
2. Eliminates small holes.
3. Smooth edge effect. You must write out the operation and kernels that you use. (For example Step 1: opening with a disk of radius 50.Sep 2: dilation with a disk of radius 50…)

:::success

:::
### Q8. Increasing
:::success
或說 preserve order保留大小順序
$A \subseteq B ⇒ A ⊕ K \subseteq B ⊕ K$
:::
### Q9. Hit-and-Miss Transform
:::success
- 定義: 輸出為 Erosion 的交集。其中, J: hit, K: miss(打到J, 不打到K), 且 J與K不能有交集
- 數學表達式: $A \otimes (J, K) = (A \ominus J) \cap (A^c \ominus K)$
:::
### Q10. Gray Scale Dilation
:::success

:::
### Q11. Gray Scale Erosion
:::success

:::
### Q12. Median root image
:::success
經過多輪的 median filter 操作, 不再改變的圖片稱之。
:::
### Q13. Medial Axis
:::success
- 目的: 用最少資料還原原始圖
- 骨架表示為: $\bigcup_{n=0}^N S_n$
- 令 $A = A \ominus_0 K$, 即 shape A 是 kernel K 對其做 0 次的 erosion
- $S_n = A \ominus_n K - (A \ominus_n K) \circ K$
:::
## CH6
### Q1. Domain type: symbolic (符號) and numeric (數字)
:::success
- symbolic (符號域)所支援的運算: AND, OR, NOT, …, etc
- **110 official answer:**
- symbolic domain
- 內容:domains containing symbolic (包含符號的域)
- 目的:classifying pixels, each pixel belongs to one category.
- 應用:domain type of neighborhood operator (鄰域算子的域類型)
- 給分標準:內容、目的、應用 寫出其2即拿到兩分,只寫出一項會-1
:::
### Q2. Noise-cleaning
:::success
使用neighbor operators來將雜訊去除。
:::
### Q3. Neighborhood operator
:::success
⼀種算法,利⽤ pixel 的值和此 pixel 的鄰居的值算出此 pixel 的 output。
- **110 official answer:**
- 內容:Define neighborhood and operation.
- 目的:Do calculations based on neighborhood and operation. Make the relationship between pixels local.
- 應用:dilation, erosion, or convolution等
- 給分標準:內容&目的寫到類似的意思就給分,應用的部分正確舉例任何一個或以上的運算子、實際畫圖等等都算對
:::
### Q4. Region-Growing Operator
:::success
通過將像素與其鄰域進行比較,將相似的像素合併成區域。

:::
### Q5. Nearest Neighbor Sets and Influence Zones
:::success
用於計算像素之間的相似性。

:::
### Q6. Region-Shrinking Operator
:::success
通過將像素與其鄰域進行比較,將不相似的像素分離開來。
可能會改變區域的連通性,甚至可以在重複應用時完全刪除區域
又名侵蝕

:::
### Q7. Approach Euclidean-distance
:::success

- 要會畫出下圖 Euclidean-distance 的圖:
- 劃法: 4連通 → 8連通 →4連通 → 8連通 → … (往外擴)
- 舉例:
- 以0來說, 用4連通連出去形成1
- 以1來說, 用8連通連出去形成2
- 以2來說, 用4連通連出去形成3
- … (往外擴張)

:::
### Q8. Mark-Interior/Border-Pixel Operator
:::success
用於標記圖像中的內部和邊界像素。

1. 前後相等 輸出該值
2. 前後不等 輸出b
3. 當前者是border時,無論如何輸出都是border。
4. 最後若不是border(b),就輸出interior(i)。

:::
### Q9. Connectivity Number Operator
:::success
其目的是對像素與其相似鄰居的連接方式進行"分類"。
:::
### Q10. Yokoi Connectivity Number (有機會考)
:::success

改分標準: 0~5 只要寫出英⽂單字 or 中⽂單字 or 解釋 or 能確定同學知道此
數字代表什麼,每個數字給 0.5 分,另外每個數字畫圖畫對給 0.5 分,最後無
條件進位。(若只有⼀個⼩失誤會算全對)
:::
### Q11 .Rutovitz Connectivity Number
:::success
各自標出相同&不同的pixel
.Rutovitz Connectivity Number 只是計算在圖元的 8 鄰域周圍移動時,從與中心圖元不同的符號到與中心圖元相同的符號的轉換次數。
Corner中只能有一個跟他一樣,才能標記成1;否則為0。

:::
### Q12. Connected Shrink Operator
:::success
刪除pixel後還是不會斷開
只有剛好一個a值結果是1的話(相當於Yokoi中計算q的個數),才把他變成background值;否則維持原樣。
Input是上一次的Output -> Recursive.

4-connectivity
因為中間pixel已經貼在image邊緣,因此需要padded外圍的background。
這邊做完一個pixel就刪掉,結果的output會變成下一個pixel計算時的input image。
由上到下左到右





$\dots...$ \
$\dots...$ \
$\dots...$ \

:::
### Q13. Pair Relationship Operator
:::success
用於計算圖像中像素之間的配對關係
排除內部與無關: 只要是跟interior有4-connect的標p(關注);剩下標q(不關注)。
周圍只要有一個是interior && 自己是border 就標成p;如果周圍都沒有interior 或 自己是interior(自己不是border) 就標成q。
-> 原本是interior的不動 寫q;部分原本是border(q)的會改成p。

:::
### Q14. Thinning Operator
:::success
重複做到output結果不變才停





$\dots$
$\dots$
$\dots$


:::
### Q15. Distance Transformation Operator
:::success
每個label的pixel距離其邊界的距離
從border往內累加數字,相當於對背景做region growing


i: 如果鄰居還沒有被標記
Min: a0=x0, 自己還沒被標記 鄰居已經有被標記的(找最小的+1)
a0: 已經被標記,其值不變

如果自己是0就直接output 0;否則找鄰域運算子中最小的值+1。



$\dots$
$\dots$
$\dots$



$\dots$
$\dots$
$\dots$

:::
### Q16. Radius of Fusion
:::success
Morphologically 形態上的
用一個半徑為p的圓盤disk去滾,就有可能把一些connected components 融合成一個大塊的connected component


:::
### Q17. Number of Shortest Paths
:::success
原本自己如果是0(空),就要把周圍加總;如果不是0就不用變。

可以走到P0(原始image)的shortest path 有幾條(總數)

:::
### Q18. Extremum-Related Neighborhood Operators
:::success
為何要找相對最大最小值呢? 這可以幫助我們去擷取重要/感興趣的資訊
:::
### Q19. Non-Minima-Maxima Operator
:::success
1 2要有相等的

:::
### Q20. Relative Extrema Operator
:::success
用於檢測圖像中的相對極大和相對極小點。 相對極大點是指在其鄰域中不存在比它更大的圖元值的點,而相對極小點是指在其鄰域中不存在比它更小的圖元值的點。









:::
### Q21. Reachability Operator
:::success
可以清楚看到整張圖相對的relative大小關係
可達性運算子:用於確定圖像中的圖元點是否可通過一系列鄰域操作到達其他圖元點。

g: 非相對極值
c: >=2個extremum可到達的共同區域

:::
### Q22. Cross-correlation
:::success

:::
### Q23.Convolution
:::success

:::
:::warning
What is the key difference between Convolution and Correlation ?
If F and G are filter Convolution is associative,
F * (G * I) = (F * G) * I.
:::
### Super Resolution (6%)
* Method :
:::success
Generate high-resolution images using traditional image processing method HsuSR.
:::
* Steps :
:::success
1. Input LR image and parameter
2. HsuSR
3. Generate reconstructed HR images
:::
* Results :
:::success
Make the reconstructed HR image as similar as possible to the original HR image.
:::
### Vehicle License Plate Image Restoration (6%)
* Method :
:::success
Using Real-ESRGAN to restore blur license plate
:::
* Steps :
:::success
1. Generate blur image
2. Training Real-ESRGAN model
3. Restore blur license plate successfully
:::
* Results :
:::success
Make the blur license plate number can be recognize.
:::
### Water Valve Defect Inspection (6%)
* Method :
:::success
Anomalib and YOLOv5
:::
* Steps :
:::success
1. Put Valve Core on Vibrating Plate
2. User Sets GUI
3. AI Decides if Reverse
4. First Side Decides if OK
5. Second Side Decides if OK
6. PLC Control
7. Push Them on Right Site
:::
* Results :
:::success
We could inspect 11 types of water valve core defects through one machine.
:::
### Toric IOL (IntraOcular Lens) Implant Digital Alignment (6%)
* Purpose :
:::success
To enhance the accuracy and stability of IOL alignment during cataract surgery.
:::
* Methods :
:::success
1. Eye center detection
2. Eye rotation tracking: ROI selection -> Inter-frame rotation tracking -> long-term error correction
:::
* Results :
:::success
Show eye center, limbus and alignment axis in every frame, target average position error <0.3mm, axis alignment error <1°.
:::
### Hand gesture recognition (6%)
* Method :
:::success
Mediapipe + TOF
:::
* Steps :
:::success
1. Camera
2. Mediapipe model
3. TOF information
4. Reconstruct hand in Unity
:::
* Results :
:::success
Finger curving is now functioning correctly, but rotation still needs to be fixed.
:::