Transcript CV04

画像特徴(点、直線、領域)の検出
と識別-2
呉海元@和歌山大学
2007年5月14日
エッジの検出
空間フィルタと画像畳み込み
R  w(1,1) f ( x  1, y  1)  w(1,0) f ( x  1, y )  ...
 w(0,0) f ( x, y )  ...  w(1,0) f ( x  1, y )  w(1,1) f ( x  1, y  1)
f(x-1,y-1)
f(x-1,y)
w(-1,-1)
w(-1,0)
w(-1,1)
w(0,1)
w(0,0)
w(0,1)
w(1,-1)
w(1,0)
w(1,1)
f(x-1,y+1)
f(x,y-1)
f(x,y)
f(x,y+1)
f(x+1,y-1)
f(x+1,y)
f(x+1,y+1)
kernel
mn
image
R  w1 f1  w2 f 2  ...  wmn f mn   wi f i
i 1
注意:すべての空間フィルタ内の係数の合計=1
Low-pass filter
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
画像平滑化
High-Pass Filter
-1
-1
-1
-1
9
-1
-1
-1
-1
画像鮮鋭化
エッジ検出1
画像中に表示された物理の輪郭(エッジ:
edge)や線では、一般的に濃淡が急激に変化
エッジや線の検出処理は、画像理解や認識の
ための前処理として重要
•計算コストが低い
•強い視覚の手がかりを提供できる
•物体の輪郭
•認識できる特徴
•見え隠れ
•照明あるいは表面色の不連続性
Edge Types

Different edge models:
屋根
凹形
傾斜
階段
棒
Roof edge
Concave
roof edge
Ramp edge
Step edge
Bar edge
画像の勾配( Image gradient )

画像の勾配:

各方向の勾配

勾配(エッジ)の方向:

勾配(エッジ)の大きさ:
画像勾配の離散化
有名なGradient operators
(a): Roberts’ cross operator (b): 3x3 Prewitt operator
(c): Sobel operator (d) 4x4 Prewitt operator
Sobel operatorのエッジ検出例
-1
0
1
-1
-2
-1
-2
0
2
-0
0
0
-1
0
1
1
2
1
ノイズの影響( Effects of noise )

Consider a single row or column of the image
• Plotting intensity as a function of position gives a
signal
1D

Where is the edge?
微分するとノイズを強調される
エッジ抽出前、まずフィルタhより平滑化
1D
Gaussian

Where is the edge?

Look for peaks in
畳み込みの定理より
1D
Laplacian of Gaussian

Consider
1D
Laplacian of Gaussian
operator

Where is the edge?

Zero-crossings of bottom graph
2D エッジ検出フィルタ
Laplacian of Gaussian
Gaussian
h ( x, y ) 

1
e
2 
derivative of Gaussian
x y
2
2
2 2
ノイズを抑制しながらエッジを検出

is the Laplacian operator:
Laplacian operatorのエッジ検出例
0
1
0
0
-1
0
1
1
1
1
-4
1
-1
4
-1
1
-8
1
0
1
0
0
-1
0
1
1
1
エッジ検出2
様々なオペレータと異なるパラメータより2D空間
フィルタを構成し、エッジを検出
注意:エッジ検出の場合
すべてのフィルタ内の係数の合計=0
最適なエッジ検出器
Canny Edge Detector

良いエッジ検出器とは
• Good Detection: ノイズに強い
• Good Localization: 真のエッジの所を検出
• Single Response:各点に一本のエッジを検出
Canny Edge Detector の処理手順
1.
2.
3.
4.
5.
Gaussianフィルタで画像を平滑化
平滑化された画像の微分を計算
勾配の大きさと方向を求める
“Non-maximum Suppression”処理を行う
“Hysteresis Threshold”処理を行う
Canny Edge Detector
1.Gaussianフィルタで画像を平滑化
S  I  g ( x, y)  g ( x, y)  I
g ( x, y ) 

1
e
2 
x2  y2
2 2
2.平滑化された画像の微分を計算
S  g  I   g  I
S x   g x 
gx  I 
S        I  

S
g
 y  y
g y  I 
 g 
 x   g x 
g   g    
  g y 
 y 
Canny Edge Detector
Derivative of Gaussian
g x ( x, y)
g ( x, y ) 

1
e
2 
x2  y2
2
2
g y ( x, y)
Canny Edge Detector
ステップ1と2処理後の結果例
Sx
入力画像 I
Sy
Canny Edge Detector
ステップ3処理後の結果例
( S x , S y ) 勾配ベクトル
3.勾配の大きさと方向を求める 大きさ
 S x2  S y2
方向    t an
1
入力画像
勾配の大きさ
Sy
Sx
Canny Edge Detector
4.“Non-maximum Suppression”処理を行う
x, y
x, y 
x, y

勾配(エッジ)方向に沿って、画素はローカル最大か否
かをチェック(非最大エッジ抑制)
 S x, y  if S x, y   S x, y

& S x, y   S x, y
M x, y   

otherw ise
0
Canny Edge Detector
4.“Non-maximum Suppression”処理を行う

勾配(エッジ)方向に沿って、画素qはローカル最大か
否かをチェック(非最大エッジ抑制)するとき
• 内挿画素pとrをチェックすることになる
Canny Edge Detector
勾配方向の量子化
内挿画素の問題を解決するため
tanθ 
Sy
3
1
Sx
角度を量子化(Quantizations) :
0 : -0.4142 tanθ  0.4142
1:
2
0.4142 tanθ  2.4142
2 : | tanθ | 2.4142
3 : - 2.4142 tanθ  0.4142
0
次のエッジ点を予測
(Forsyth & Ponce)
Assume the
marked point is an
edge point. Then
we construct the
tangent to the edge
curve (which is
normal to the
gradient at that
point) and use this
to predict the next
points (here either
r or s).
Canny Edge Detector
Non-Maximum Suppressionの処理結果
S  S x2  S y2
Step 3
M(細線化)
2値化処理
Step 4
For visualization
M  Threshold  25
Canny Edge Detector
5. “Hysteresis Threshold”処理を行う

Scan the image from left to right, top-bottom.

If the gradient at a pixel is
• above “High”, declare it an ‘edge pixel’
• below “Low”, declare it a “non-edge-pixel”
‘edge pixel’
High
Gradient
magnitude
•“non-edge-pixel”
ヒステリシス閾処理
low
Canny Edge Detector
5. “Hysteresis Threshold”処理を行う

If the gradient at a pixel is
• between “low” and “high”
• Consider its neighbors iteratively then declare it an “edge
pixel” if it is connected to an ‘edge pixel’ directly or via
pixels between “low” and “high”.
‘edge pixel’
High
Gradient
magnitude
•“non-edge-pixel”
ヒステリシス閾処理
low
Canny Edge Detector
“Hysteresis Threshold”処理を行う

Connectedness
x
x
x
4 connected
8 connected
6 connected
Canny Edge Detector
Hysteresis Threshold処理結果例
M(細線化)
regular M  25
Hysteresis
High  35
Low  15
Step 5
Effect of  (Gaussian kernel size)
original

Canny with
The choice of
• large
• small
Canny with
depends on desired behavior
detects large scale edges
detects fine features
Canny Edge Detector
gx(x,y)
Gradient
magnitude
Non-maximum
suppression
Image
gy(x,y)
Gradient
direction
Hysteresis
thresholding
出席チェック3
Canny Edge Detectorの処理流れを述べてください。
レポート
OpenCVではサンプルプログラムがあります。
関連パラメータを調整しながら、好きな一枚の画像の
エッジを検出してください。
レポートには元画像、使ったパラメータと処理後の画
像をそれぞれ記述してください。
提出期限:
3週間以内(講義の時 OR 私の部屋(A612))
Gaussian - image filter
Gaussian
delta function
Laplacian of Gaussian