# 影像處理概論
###### tags: `資工系課程`
## CH1
### What is Digital Image Processing
{%hackmd BJrTq20hE %}
Three types of function f(t)
* Continuous function
* Discrete-time function
* Digital function
Continuous function因為有無限多個點很難用電腦表示,所以要把他透過sampling(取樣)切成週期性的切出數值,會出現f(10)、f(20)...、f(T)、f(2T),變成Discrete-time function,但要把這些值量化(quantization),變成Digital function
tone:灰暗度,從最暗到最亮有幾種表示的種類
filtering最常見的功能:
(1) noise
(2) interpolation(內插)舉例來說把1000x1000穿插成2000x2000
(3) prediction(extrapolation外插)舉例來說氣象預測
## CH3

identity為參考用
### Image Negatives
the negative transformation is: $s = L - 1 - r$

### Log Transformations
使得圖片黑白分明
$s = clog( 1 + r )$ where c is a constant and it is assumed that r>=0

### Power-Law Transformations


### Gamma Correction
使得亮度分布顯示更均勻

### Histogram Processing

nk為gray level為k的數量
### Histogram Equalization
r=0表暗 r=1表亮且0<=r<=1,$s=T(r)$
$T(r)$一定是single-valued不會有交錯(一個值只對應一個),且為monotonically increasing也就是如果r1<=r2,s1<=s2,且為越來越大。
inverse transform: $r=T^-1(s)$


之所以積分是從0開始,是因為r沒有負的值,第一個算式因為兩個從負無限積分到無限都是1,所以微分後會相等。
第二個算式當成定義看就好

最後s會=1 P~s~(s)為uniformly distribution
discrete版本:

[參考文章:数字图像处理:直方图均衡(Histogram Equalization)的原理及处理介绍](https://blog.csdn.net/LaoYuanPython/article/details/119857829)
### Histogram Matching(Specification)
P~z~(z)為specified pdf of desired output image

[參考文章:数字图像直方图匹配或规定化Histogram Matching (Specification)处理](https://blog.csdn.net/LaoYuanPython/article/details/120231590)
### Using Histogram statistics for Image Enhancement



簡單來講就是增強低於某個值的部分,使得一部分的影像對比更明顯。
### Image Subtraction


兩張圖即使差距很小,但透過相減並enhance之後就會知道差異部分
### Image Averaging


雜訊值有zero mean的性質,當取得k張圖之後並取得平均值,其期望值會趨近於原先無雜訊的值。當k值越大,則在消除雜訊上效果越好
### Basis of Spatial Filtering

就是乘上對應的加權數

### Smoothing Spatial Filters
保留圖片輪廓,忽略細節,計算會比較快,可用於軍事的追蹤系統,也會削減雜訊
### Smoothing Linear Filters
又可稱為averaging filter 或是 low-pass filter
simply the average of the pixels contained in the neighborhood of the filter mask

也有乘權重的


n越大越模糊,因為是要取得輪廓並非細節

### Order-Statistics Filters
為nonlinear filters
將subimage的幾個點照大小排列順序,如果為median filter則取中位數,e.g.如果subimage f(x)為$3*3$則g(x,y)就為f~5~
Median filters對impulse noise(又稱pepper-and-salt noise就像黑斑白斑)非常有效
若為max and min filters則為
### Sharpening Spatial Filters
與smoothing filters(留low-frequency輪廓刪high-frequency細節)相反,把細節留下(high-frequency),拿出與旁邊的差距並放大強化
是採用一階的微分或是二階微分,
若是採用一階微分:
1. 如果為大家數值都一樣為平的,則會變0
2. 如果是像階梯一樣的就會是非0
3. 如果是斜坡的也為非0
若是二階微分:
1. 數值為水平的為0
2. 如果是階梯一樣的為非0
3. 如果是斜坡的為constant slope(斜率一樣),二次微分後為0

二次微分就是取差值的差值,一次微分是取差值
first-order derivatives對於gray level step(就是突然上升的階梯)會有stronger response就是impulse
Second-order derivatives會對fine detail(像是thin lines and isolated points就是一微的gray level step處)有stronger response,另外在step changes in gray level會產生double response

### The Laplacian Operator


左邊上下兩張是算四個差值,但是兩個算的方向不同;右邊上下兩張是算8個差值,一樣是相減方向不同
最後將強化後的細節$▽^2f(x,y)$加上原本的圖$f(x,y)$,最後變成$g(x,y)$

### Unsharp Masking and High-boost Filtering
原圖減掉blurred version(經過low-pass filter之後產生的,保留輪廓的那個),就會強化細節

最後還要加上到original中
#### high-boost filtering

如果A=2,則跟上面的加到Original一樣,也可以像Lapacian operator一樣(3.7-11)
### First Derivatives for Enhancement-The-Gradient

Roberts的方式,比較不好

Sobel operators,好一點


## CH4
### 1-D Fourier Transform and Its Inverse
continuous function:

discrete function:

也可以透過尤拉公式改成這樣




轉換就是從x-domain到u-domain
### 2-D DFT and Its Inverse




步驟:

第六點為還原
### Some Basic Filters and Their Properties

函數是將原來的(0,0)移到(M/2,N/2)所以如果還原就是把原本的平均值拿掉
### Correspondence Between Filtering in the Spatial and Frequency Domains

圖示兩個方形脈衝波的捲積

convolution:捲積,表示f函數與經過翻轉後的h函數平移之後交叉重疊所形成的面積,此為直接計算的公式
也可以透過傅立葉轉換計算
由於兩個離散訊號在時域(time domain)做卷積相當於這兩個訊號的離散傅立葉轉換在頻域(frequency domain)做相乘


信號在x~0~跟y~0~的地方才有值
### Gaussian Filters

是smoothing filter的一種,就是留下輪廓去除細節。
因為σ的緣故,如果σ大H(u)比較寬,h(x)比較窄,如果σ趨近於無限大H(u)就會像常數函數一樣為一橫線,但h(x)會呈現impulse
### <font color=orange><font size=4>Smoothing Frequency-Domain Filters</font></font>


當大於D~0~的部分就全部清除
D(u,v)的範圍剛好是以(M/2,N/2)為中心的圓,因此超過這個圓的範圍都為0
#### <font color=orange><font size=4>Butterworth Lowpass Filters</font></font>

BLPFs of order 2 are a good compromise between effective
lowpass filtering and acceptable ringing characteristics
通常n選擇2
#### <font color=orange><font size=4>Gaussian Lowpass Filters</font></font>

### <font color=orange><font size=4>Frequency Domain Sharpening Filters</font></font>
也可稱為highpass filtering process

#### <font color=orange><font size=4>Ideal Highpass Filters</font></font>

D~0~越少代表去除的越少,舉例來說D~0~=30代表30以下的被去除
#### <font color=orange><font size=4>Butterworth Highpass Filters (BHPF)</font></font>

與前面的差別在D~0~跟D(u,v)位置互相調換
#### <font color=orange><font size=4>Gaussian Highpass Filters (GHPF)</font></font>

### The Laplacian in the Frequency Domain

j應該是√-1?


加上處理過後的

### Unsharp Masking, High-Boost Filtering, and High-Frequency Emphasis Filtering



### Homomorphic Filtering



ln的inverse是exponential,i(x,y)變化比較小,r(x,y)比較複雜,且兩者為獨立的
流程:


### Some Additional Properties of 2-D Fourier Transform
<font color=orange><font size=4>Translation</font></font>

乘上(-1)^x+y^就好
<font color=orange><font size=4>Distributivity and Scaling</font></font>

<font color=orange><font size=4>Rotation</font></font>

<font color=orange><font size=4>Periodicity and conjugate symmetry</font></font>

週期性:x跟y無限延伸,一塊一塊的
conjugate:變位
<font color=orange><font size=4>Separability</font></font>

二維的可以拆成兩個一維的做
### Computing Inverse Fourier Transform Using Forward Transform Algorithm

只要在指數上加負號達成complex conjugate以及除以M或是N yields就好
### Padding for Periodicity


Padding:若一個週期是A 一個是B 至少要拉長到A+B-1
二維:


找尋圖片中有沒有你有興趣的小區塊(region of interest)
兩個都需要做padding(先拉到2M-1)
### The Fast Fourier Transform (FFT)


## CH5
### Model of Image Degradation/Restoration Process

對function H只有部分的了解,希望能將加了雜訊的degraded image g(x,y)透過restoration將f^(x,y)盡量還原成f(x,y)

### Noise Models



bipolar:黑斑白斑都有,unipolar:只有黑或是只有白

### Mean filters
如果不知道雜訊其他參數的話可以用


第一個算式是subimage算平均值,變成f^(x,y)
第二個算式是幾何平均,n個點相乘之後開n次方
第三個算式是先將g(s,t)求倒數相加後再倒數
第四個算式舉例來說如果是5X5的圖:Σg(s,t)^5^/Σg(s,t)^4^,針對黑斑或是白斑(對於一個Q來說只能擇一,Q正治黑斑;Q負治白斑)通用型的filter
### Order-statistics filters

alpha-trimmed對於黑斑白斑都有的都可以處理
### Adaptive Filters


### Adaptive median filter
變數部分:

流程:

目標:
1. 去除黑斑及白斑
2. 即使不是impulsive也能移除noise
3. 減少圖片失真,例如圖片中的東西變細或變粗
4. Level A的目標是檢查output Z~med~是否為impulse(black or white)
### Periodic Noise Reduction by Frequency Domain Filtering

中間0為把圈圈挖掉,圈圈見講義p34

#### notch filter rejects (or passes) frequencies



### Optimum Notch Filtering

G(u,v)是g(x,y)經過DFT的去除雜訊信號,乘上H(u,v)希望為雜訊的信號
w(x, y)的選擇方法希望讓variance越小越好,使得圖像越smooth


為了前面難算的,所以假設5.4-17,
就是w(x+s,y+t)只要在s跟t的範圍內,都由w(x,y)取代,所以平均起來是一樣的,不用像前面一樣相乘完再求平均
總之就是先濾出雜訊,乘上權重,再移除
### Linear, Position-Invariant Degradations

H[]代表f(x,y)受到扭曲,g(x,y)表示受到扭曲的圖又再加上雜訊

如果沒有雜訊只剩下degradation的話

再加上雜訊
### Estimation by modeling


H(u,v)為重複曝光的效應

### Inverse Filtering

### Minimum Mean Square Error (Wiener) Filtering



### Constrained Least Squares Filtering

g是一個vector 但把整張圖都放進來,把所有的值串起來




### Geometric Mean Filters

#### Geometric Transformations

將鏡頭造成畫面邊邊的扭曲拉直,以及調整gray-level

g(x',y')幾何扭曲圖

Usually, integer coordinates (x, y) are used to yield the restored image f^(x,y) . ==However, Eqs. (5.11-5) and (5.11-6) can yield noninteger (x', y'), due to the coefficients c~i~.==

## CH6
### RGB轉換




### Converting colors from RGB to HSI

### Converting colors from HSI to RGB


### Color Transformations


### Color slicing


落在hypercube中的顏色保留,其他的用別的顏色代替
### Tone and color corrections



### Color image smoothing

分別對RGB做average
### Color image sharpening

### Segmentation in RGB vector space


### Color edge detection


## CH10
### Detection of Discontinuities

### Point detection


### Line detection

### Edge detector



### Gradient operators


又是上次的東西



### The Laplacian

1. 作為二階導數,Laplacian通常是對noise非常敏感。
2. Laplacian的大小會產生雙邊緣,這是一種不良影響,因為它使分割複雜化。
3. Laplacian無法檢測邊緣方向

### Edge Linking and Boundary Detection local processing
分析圖像中每個點 (x, y) 的小鄰域中像素的特徵。
建立邊緣相似性的兩個主要性質:
(1) the strength of the response of the gradient operator
used to produce the edge pixel;
(2) the direction of the gradient vector.


### Global edge linking via Hough transform

考慮⼀個點(x~i~, y~i~) 和斜截式直線的⼀般⽅程式y~i~ = ax~i~ + b。有無數條線通過(x~i~ , y~i~ ),但對於不同的a和b值,它們都滿⾜⽅程式yi = ax~i~ + b 。
將此⽅程式寫為b = ‒x~i~a + y~i~並考慮ab 平⾯(也稱為參數空間)得出固
定對 (x~i~ , y~i~) 的單線⽅程式

1. 最初,這些單元格設置為零。
2. 如果選擇a~p~得到解b~q~ ,則A(p, q) = A(p, q) + 1。在此過程結束時, A(i, j)中的Q值對應於位於y = a~i~x + b~j~線上的xy平⾯。
3. ab平⾯中的細分數量決定了這些點的共線性精度

步驟:

### Global edge linking via graph-theoretic techniques
一些小小定義+廢話




**<font size=5><font color=yellow>P40-61自己看 忘記上課ㄌ</font></font>**
### Boundary characteristics for histogram improvement and local thresholding



### Region-Based Segmentation

區域增⾧是根據預定義的標準將像素或⼦區域分組為更⼤區域的過程。基本⽅法是從⼀組種⼦點開始,然後通過將具有與種⼦相似屬性的相鄰像素附加到每個種⼦來從這些⽣⾧區域開始。
### Spatial Motion Segmentation Techniques


考慮一系列圖像幀 f(x, y, t1), f(x, y, t2), ..., f(x, y, tn) 並設 f(x, y, t1) 為參考圖像。 通過將此參考圖像與序列中的每個後續圖像進行比較來形成累積差異圖像 (ADI)。 每次在參考和序列中的圖像之間的像素位置出現差異時,累積圖像中每個像素位置的計數器都會遞增

### Spectral Motion Segmentation Techniques



### Canny Edge Detector
Single response constraint: the detector must return one point only for each edge point.(單⼀響應約束:檢測器必須只為每個邊緣點返回⼀個點。)
四個步驟:
1. 應⽤ 2D ⾼斯濾波去除圖像中的噪聲
2. 計算⾼斯濾波圖像的強度梯度
3. 應⽤⾮極⼤值抑制去除邊緣檢測的虛假響應
4. 應用雙閾值來確定潛在邊緣
5. 通過滯後跟踪邊緣:通過抑制所有其他弱且未連接到強邊緣的邊緣來最終確定檢測到的邊緣。



### Local Binary Pattern (LBP)



### Rotation Invariant Texture Description


### Optimal Global Thresholding Using Otsuʼs Method



### Region Segmentation Using Clustering

mi為重心


### Region Segmentation Using Superixels




跟上一個很像,差異是這個是數量比較多的
## CH11