Try   HackMD

數位影像處理(成大)

1.Introduction

1.1 數位影像處理 Digital image processing

類比影像 → 量化(quantization)是數位化amplitude、採樣(sampling)是數位化座標 → 數位影像
也就是將影像離散化(discrete)的過程,讓電腦能夠處理。
取樣率(切割影像的精度),其數位影像的大小與空間的解析度(resolution)直接相關,

數位影像分為 Color image 跟 gray image

每一格叫 Pixal,其值成為 gray-level 或 RGB三張影像通道 稱作 影像平面(image plane)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

空間的座標系

影像簡單的概念就是 空間位置+數值 的 Array
原點在左上角 y→ x↓

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

影像處理 Image processing

對大小、數值的 Transformation
包含變形、噪點等變化

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

影像分析 Image analysis

對影像的描述與識別等

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

電腦視覺 Computer Vision

包括多張影像動作、參照、移動等分析

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

1.3 數位影像處理的領域

影像由波而來
構成紅外線、X光、可見光等等的影像

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

1.3.1 Gamma-Ray Imaging

高能輻射,會直接穿透肌肉與水,硬組織穿透力差,光線被吸收後再透過底片以負片成像。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

1.3.2 X ray

與 1.3.1 同理,但能量較低(穿透力較弱)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

1.3.3 Ultraviolet Band 紫外線

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

1.3.4 可見光 Visible 與 紅外線 Infrared

Visible Infrared
如光學顯微鏡 如夜間拍攝
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

1.3.6 核磁共振(無線電) Radio band

Magnetic Resonance Imaging(MRI)
如髖關節影像

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Ultrasound 超音波

超音波由接收回波來成像
比如腹部(油、脂肪)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

2.Digital Image Fundamentals 不重要

人的視覺

  • 人的眼睛用視桿細胞、視錐細胞,分別感知光線明暗與動作、色彩細節。並透過水晶體調整焦距與範圍
  • 人眼看到的並不是事實,有Optical illusions視錯覺
  • Weber ratio 韋伯-費希納定理 心理量與物理量之間的定律,感覺量的大小與刺激強度的對數成正比

照相

成像是由光的能量構成,透過曝光將光線記錄到底片跟膠帶上。
分為:

  • Single sensor
  • Sensor stripes(Line sensor)
  • Sensor arrays (Array sensor) 如X光

Image interpolation 圖像插值法

利用已知數據推論未知圖像的方法,如放大、縮小等:

  • nearest neighbor interpolation 最近鄰域法:放入原始圖中最接近的點
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
  • Bilinear interpolation 線性內插法:參考周圍最接近的四點,按距離的權重決定填入多少
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
  • Bicubic interpolation
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

Basic relationships between pixels: pixel之間的基本關係

Neighbors of a pixel

  • N4(p)
    : 4-neighbors of p(x,y) 十字
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
  • ND(p)
    : diagonal neighbors of p(x,y) 對角線
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
  • N8(p)
    =
    N4(p)ND(p)
    : 8-neighbors of p(x,y) 周圍
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

Adjacency and Connectivity

  • 4-Adjacency in the set
    N4(p)
    p的上下左右皆為 Adjacency
  • 8-Adjacency in the set
    N8(p)
    p的上下左右斜線皆為 Adjacency
  • m-Adjacency(mixed adjacency)
    • q is in
      N4(p)
      or
    • q is in
      ND(p)
      and the set
      N4(p)ND(p)
      has no pixels
      image
      注意相鄰的線

Connected components

image

Regions: 指一個連通的區域

Adjacent: 兩個區域形成連接
Disjoint: 不相鄰,如DSU。

Boundaries

  • Boundary: border or contour. In the region
    當使用8-鄰接性時,圓圈中的點才會被視為1值像素區域的邊界
    image
  • Outer border: in the background
    image

Edge: 則是邊緣不存在的資料

內部 Boundary 與 外部的中間

Distance measure

  • Euclidean distance
    image
  • D4
    distance city-block
    image
  • D8
    distance
    image
  • Dm
    distance m-path: 找包含兩者的最短路徑
    image

An Introduction to the Mathematical Tools Used in Digital Image Processing

Array versus Matrix Operation

  • array product of these two image
    image
  • matrix product
    image

Linear versus Nonlinear Operation

image

Addition (averaging) of noisy images for noise reduction 去除雜訊

  • 圖像由原圖與雜訊構成:
    image
  • 如何將圖像去除雜訊
    image
    • 方法:同一個視角拍很多次,加起來k次取平均,降低noise的影響。
      image

      image
    • 推導過程:
      image

      假設其
      η(x,y)
      為常態分佈時,平均值為0,標準差為標準差noise或1。推出期望值為0。
      根據大數理論,當k越大時,
      g(x,y)
      效果越接近
      f(x,y)

image
Var(X)=Var(1ni=1nXi)=1n2i=1nVar(Xi)Var(X)=1n2nσ2=σ2nVar(X)=σ2n

Image subtraction for enhancing differences 增強差異

image

  • 概念:
    只拍照物體但不要背景 = 拍一張背景 - 有物體的照片
    有物體照片b - 背景a = c 物體的照片並抓出黑的背景
    有物體照片b - c 黑背景= 物體照片
  • 應用:
    image

    (a)
    原始圖像
    (b)
    最低bit被設置為0
    (c)
    a-b,並縮放到[0,255]

image
(a)
先拍一張原圖(背景)
(b)
再拍一張顯影劑的圖(有物體的圖)
(c)
然後a-b 就會剩下左下心導管的影像
(d)
再強化影像到右下圖

Using image multiplication and division for shading(陰影) correction 陰影校正

  • 工業檢測:乘以背景的倒數 = 原來影像
    image
  • 醫療影像:乘以背景的倒數,更清楚。
    image
  • 牙齒:拍全口 x 牙齒區塊是1其他0的mask = 就剩下單一牙齒
    image

Full range of an arithmetic operation 改變範圍至[0,K]

改變 gray level 的 range 至

[0,K]

image
減掉最小,使
[0,max(f)]

image

除最大值
[0,1]
,乘以k倍
[0,K]

gray level 的 range 拉大到

[0,K]的range

Set operations involving image intensities 圖像強度

正負片影像

An=Ac=(x,y,255z)|(x,y,z)εA
image

image

Single-pixel operations 單點運算(強度值)

(x,y)
原始 gray level
f(x,y)=z

Transformation
f(x,y)=s

s=T(z)

相同位置的轉換 → 單點運算(跟其他點無關)
只會改變影像中gray level上的值
image

Neighborhood operation 鄰域操作(強度值)

image

n×m的鄰域操作
該影像是透過n×m(41x41)的local框框中的gray level加起來做平均填回去
會讓影像模糊化(平滑) smoothness

Geometric spatial transformations and image registration 空間轉換

  • 幾何上空間的轉換,要做到 image registration 影像對位(對齊)
    image
  • 概念:不同大小的兩圖,上面的單一點如何對應到另一張圖的點,去做到T的spatial transformations 轉換。

image
affine transform 就是 linear transform
可以做到 scale, rotate, translate, or sheer 變形
都可經由這些矩陣達成
image

Image registration

  • 影像對齊就是要找到 transform 的矩陣
  • 兩圖分為
    (b)
    moving image 跟
    (a)
    reference image
    moving image 找到對應的參考點tie points (control points):如四個角落的點,點的數量跟變數相關,才能找到對應方程式的解,貼到reference image上,得到結果
    (c)

    image

    但在做 interpolation 時還是會造成
    (d)
    影像失真

Vector and Matrix Operations

image

  • Euclidean distance (vector norm1)
    image
  • linear transformations
    image

    image
  • 標準的影像模型
    拍出來的影像
    g=fH+noise

    要得到
    =gnoise
    H
    反矩陣運算
  • 問題:無法得知
    H
    noise

    但假設
    n
    是常態分布 再假設
    H
    是旋轉等 找到反矩陣就能得到真實的
    f

Image Transforms

image

  • 傅立葉轉換後,再做反傅立葉轉換可以變回原圖
    用這個方法可以對影像做處理,如下圖的恢復
    image
    • 有規則性的
      noise
      (a)
      在傅立葉的圖
      (b)
      上也會顯示規律性雜訊,用mask
      (c)
      得到圖
      (d)
      ,就能去除掉雜訊,又稱為濾波器。

3.Intensity transformation and spatial filtering

3.1 Background

intensity transformations

  1. Spatial domain:空間(特定點)
  2. Frequency domain:頻率域(Fourier)
Spatial domain
  • 分單點 Single-pixel 跟鄰域 Larger neighborhood

  • 單點 Single-pixel operations 就是 point processing

    image
    s=T( r )
    image

    • 跟gray level有關 跟位置無關
      但會掃描所有影像的點 把該亮度改成上圖新的亮度做調整。
    • 左圖是亮度拉長,右圖是閥值變二元圖
      所以有很多不一樣的應用方式,依照找哪種亮度的位置,強化我想找到的東西。
  • Larger neighborhood

    • 該區域稱為 masks (filters, kernels, templates, windows).
      處理稱作 mask processing or filtering
      image

3.2 Some basic gray level transformations

常用

image

  • Image negatives
  • Log transformation
  • Power-Law transformation
  • Piecewise-linear transformations

Image negatives

黑轉白 白轉黑
為正負片(反轉)的差異
range [o,L-1]

image
image

image

Log transformation

image
image

image

more details
noise 更明顯

Power-Law transformation

image
image

image

gamma correction
  • 調整 gamma 值 or 有不同效果
    image

    image
  • gamma<1暗強化
    image
  • gamma>1亮強化
    image

Piecewise-linear transformations

Contrast stretching

對比度強化
r1→r2小 < s1→s2大

image
image

Gray-level slicing

image
(b)二元值影像, (
c
)經驗設置
image

Bit-plane slicing

bit-slicing image

image
越上層越重要,越下層越不重要
可用來影像壓縮
image

3.3 Histogram Processing

  • 明亮度的統計圖
    range: [0, L-1]
    h(rk)=nk
  • normalized histogram
    p(rk)=nk/MN

image

Histogram Equalization(必考)

直方圖等化:改為均勻分佈,減少環境帶來的差異。

image
image

找出a到b的uniform probability density function

1308671
證明以下公式:
s=T(r),0<=r<=L1

T(r)
為 strictly monotonically increasing 嚴格單調遞增
inverse transformation:
r=T1(s),0<=s<=L1
不是函數(多r對映單一個s)
ps(s)=pr(r)|drds|
其中
pr(r)Histogram

image

image

  • 連續型:
    ps(s)=pr(r)|drds|
    推導
    =1L1,0<=s<=L1

    image

    變成 uniform distribution
  • 離散型:
    image

    image
Example

image
image

小數做四捨五入(有誤差)
但0,2,4皆是空的

Histogram Matching (Specification)

(a)原始影像的 Histogram
(b)希望轉換後特定的 Histogram
(

c) b轉換成uniform,生成對照表
image

image
3沒有,所以填入嚴格遞增3<x<5,x填入最小的4

Local Histogram processing

對其中一塊的 neighborhood 鄰近區域做 Histogram equalization
然後 shift 到下一格持續做區域內的 processing
稱為 Local Histogram processing

image

Using histogram statistics for image enhancement

  • n th moment n階動量:
    image
  • m is the mean value:
    image
  • μ2,n=2
    :
    image
  • the sample mean and sample variance:
    image

    image
    • example
      image
  • 以(x,y)為中心的區域算mean
    image
  • 以(x,y)為中心的區域算variance
    image
  • Local enhancement
    image
    • example
      image

3.4 Fundamentals of Spatial Filtering

  • neighborhood operation
    image

Filtering

  • Correlation → 內積
    image
  • convolution → 將mask旋轉
    image
Smoothing mask

lowpass filtering:模糊化,低頻的背景被留下。

image
image

加起來為1

  • Gaussian Filter
    距離越遠,權重越小
    • kernel
      image

3.5 Smoothing Spatial Filters

image

Order-Statistics Filters

ordering (ranking)
比如 median filter

image

3.6 Sharpening Spatial Filters

highpass filtering:邊緣、雜訊
一階微分與二階微分

一階微分:

f(x+1)f(x) 後面減掉前一項,絕對值最大可能為edge
二階微分:
f(x+1)+f(x1)2f(x)
前後項相加減兩倍項,產生一亮一暗的邊中間為反曲點(zero crossing)是edge
image

The Laplacian(二階)

image
image

image

image

|上下左右四點相加-四倍原點|

  • 左上角的mask:
    image
  • 亮暗邊
    image
  • 加到原圖
    image

Unsharp masking and high-boost filtering

  • 原圖 - 低頻(模糊) = 高頻(銳利化)
    image
  • 原圖 + 高頻 = 強化邊界
    image
  • 結果
    image

    image

The gradient(一階)

image
image

sobel operation

image
使用步驟:

  1. 先使用
    Gx
    Gy
    的mask
  2. |Gx(x0,y0)|+|Gy(x0,y0)|
    Gx(x0,y0)2+Gy(x0,y0)2
    > 閥值 就是 edge 的位置
    邊界會隨著閥值而有差別

4.Image Enhancement in the Frequency Domain

Preliminary Concept

一個函數可以用sin, cos函數在不同週期情況下相加而成。

j=1

  • Euler’s formula

    ejθ=cosθ+jsinθ
    ejθ1ejθ2=ej(θ1+θ2)

  • Fourier series

    f(t)=n=n=Cnej2πntT
    image

  • Fourier transform in continuous domain

    image
    f(t)
    作傅立葉轉換

  • Fourier transform may be written for convenience as

    image
    與上者相同

  • Inverse Fourier transform

    image
    可逆的

  • Using Euler’s formula

    image

  • 舉例

    image
    tμ

    代入
    w/2w/2
    的範圍
    image

  • Fourier spectrum(energy)

    (r,θ)以下為r長度的統計圖,另外還有
    θ
    的Fourier phase angle
    image

    image

Convolution

image
image

image

兩個函數作Convolution的結果作Fourier = 各別作Fourier的乘積。

Sampling and the Fourier Transform of Sampled Functions

Sampling

image
第一、二張圖作乘積變為採樣後的第四張圖
image

  • 第一張為Fourier的圖
  • 第二三四張為不同的採樣頻率:
    • 第二張太大
    • 中間剛好,週期相同
      image
    • 第三張太小
      image

image

將離散的值作積分:

image
也就能直接推導成
image

Discrete Fourier Transform (DFT) of One Variable

  • Discrete Fourier transform (DFT)
    image
  • Inverse discrete Fourier transform (IDFT)
    image
  • DFT計算範例:
    image

    ejθ=cosθ+jsinθ

    ejθ=cosθjsinθ

    image

    image

    image
  • IDFT計算範例

The 2-D Discrete Fourier Transform and Its Inverse 必考

  • 2-D discrete Fourier transform (DFT)
    image
  • Inverse discrete Fourier transform (IDFT)
    image
  • 觀念
    image
  • 計算範例
    image
  • 圖片示例
    image

    原圖→Fourier→原圖先經由以下公式轉換後再Fourier
    image

    會將亮點移到中間,方便處理
    image

    image

Fourier Spectrum and Phase Angle

image

zero padding

5x5 3x3 -> 9x9 padding zero
nxn mxm
n+m+1

The 2-D convolution Theorem

image
image

image

image

Frequency Domain Filtering Foundamentals

image
為什麼轉到 Frequency Domain ,因為在空間域做convolution需要花很多時間。
左:低頻,均值被拉高,模糊化
中右:高頻,背景消失,邊緣強化

Summary of Steps for Filtering in the Frequency Domain

  1. MxN -> PxQ, P = 2M and Q = 2N.
  2. padded
  3. f
    p(x,y)
    by
    (1)x+y
  4. DFT
  5. 位置相乘 array multiplication
  6. IDFT
    image
  7. MxN 挖出來

image

Extension to Functions of Two Variables

5. Image Restoration

A model of the image degradation/restoration process

image
意外加入了雜訊,如何去做還原。

Noise Models

Gaussian (normal) noise model

image
image

Rayleigh noise model

超音波雜訊

image
PDF:
image

Mean and Variance:
image

image

Other

  • Erlang (gamma) noise model
    image
  • Exponential noise model
    image
  • Uniform noise model
    image
  • Impulse (salt-and-pepper) noise model
    image

image
image

Restoration in the presence of noise only-spatial filtering

image
無法完全去除雜訊的影響,只能盡可能減少

Mean Filters 考試

f(x,y)^皆是估計出來的,而非原圖
f(x,y)

  • Arithmetic mean filter
    image

    算出mask的算術平均值:mxn的mask,mask內相加除以mxn。
    畫面:越大越模糊,越小存在更多雜訊
    計算:越大越久,越小越快
  • Geometric mean filter
    image

    算出mask的幾何平均值:mask內相乘開mxn的根號
  • Harmonic mean filter
    image

    算出mask的調和平均值
  • Contraharmonic mean filter
    image
  • 還原效果
    image

    image

Order-Statistics Filters

  • Median filter
    image
    1. 取出排序
    2. 填入中位數
  • Max and min filters
    image

    image
  • Midpoint filter
    image

    取最大跟最小除二
  • Alpha-trimmed mean filters
    image

    砍掉頭尾d個算中間的平均
  • 還原效果
    image

    image

    image

Adaptive Filters

Faster-RCNN: Anchor Base

  1. RPN(Region Proposal Network)
    Anchor 瞄框
    GT 真實框
    去產生提議框(Proposal box) -> 正提議框(I.O.U≧0.7), 負提議框(I.O.U≦0.3)
  2. 提取提議框在特徵圖內的區域(部分)的特徵圖,再以提議框與真實框來提取bounding box(結果)
    R.O.I Pooling, R.O.I Aligment 提議框大小一致
  3. NMS(non-maximun supression)來去除多餘框
    非最大值壓抑

TWO-stage methon