Transcript Document

Formation et Analyse d’Images Session 5 and 6

Daniela Hall 24 October 2005 1

Course Overview

• Session 1 (19/09/05) – Overview – Human vision – Homogenous coordinates – Camera models • Session 2 (26/09/05) – Tensor notation – Image transformations – Homography computation • Session 3 (3/10/05) – Camera calibration – Reflection models – Color spaces • Session 4 (10/10/05) – Pixel based image analysis • 17/10/05 course is replaced by Modelisation surfacique 2

Course overview

• • • • • • • Session 5 + 6 (24/10/05) 9:45 – 12:45 – Contrast description – Hough transform Session 7 (7/11/05) – Kalman filter Session 8 (14/11/05) – Tracking of regions, pixels, and lines Session 9 (21/11/05) – Gaussian filter operators Session 10 (5/12/05) – Scale Space Session 11 (12/12/05) – Stereo vision – Epipolar geometry Session 12 (16/01/06): exercises and questions 3

Exercise

• Your company asks you to build a cheap traffic light monitoring system. You have a camera that observes a traffic light and should emit events when the light changes the color. How would you proceed.

4

Session overview

1. Contrast description 2. Hough transform 5

Feature extraction in computer vision

• The goal of feature extraction is – Reduce the amount of information – Simplify the interpretation – Preserve the information necessary for further processing (task dependent) • The ideal feature extraction alogrithm is invariant – Invariance: the observation is the same independent of the view point and illumination.

• Contours are good candidates for invariant feature extraction 6

Contrast

• – Contrast can be caused by • Change in surface orientation (discontinuity in depth) useful for description of polyhedrical objects – • Limit of a shadow useful to recognize 3D object form – • Texture on a surface independent of surface, can be used to recover the texture – • Reflections depends on view point and illumination 7

Contrast detection process

image Image processing intermediate image representation Image analysis image description 8

Contrast detection methods

• Search for extremum in 1 st derivative • Search for zero crossing in 2 nd derivative 9

Step edge First derivative

Contrast detection

Smoothed step edge Second derivative (white pos, yellow negative) 10

Image processing tools

• Let s(i), f(i) be two real discrete signals • s(i) has Ns discrete values on the interval 0<=i<=Smax • f(i) has Nf discrete values on the interval 0<=i<=Fmax • Pmax=min{Smax,Fmax} • s(i)=0 for all i<0, Smax

p



s

(

i

),

f

(

i

) 

i

   

s

(

i

)

f

(

i

) 

P i

max   0  1

s

(

i

)

f

(

i

) 11

Correlation and convolution

• Correlation is a scalar product with an offset k over all values of k.

c

(

k

) 

s

(

i

) 

f

(

i

) 

s

(

i

k

),

f

(

i

)    

s

(

i

k

)

f

(

i

) 

S

max   1

s

(

i

k

)

f

(

i

) 

F

max  

k s

 1 (

i

)

f

(

i

k i

 

i

 0

i

k

• Convolution is a correlation where one of ) the signals is flipped (i-k)->(Fmax-1)-(i-k)

r

(

k

) 

s

(

i

) 

f

(

i

) 

s

(

i

k

),

f

((

F

max  1 ) 

i

)  

S

max

i

  0  1

s

(

i

k

)

f

(

F

max  1 

i

) 

F

max

i

 

k

 1 

s k

(

i

)

f

((

F

max  1 )  (

i

k

)) 12

Contrast detection

• Roberst contrast detector • Sobel contrast detector • Difference filters 13

Roberts contrast detector

• Consists of two masks 0 1 -1 0 0 -1 Compute correlation for n=1,2: Contrast magnitude Contrast direction

E n

(

i

,

j

) 

p

m n

k

1 1   0  0

L p

(

i

k

,

j

L

)

m n

(

k

,

L

)

E

(

i

,  (

i

,

j

) 

j

) 

E

1 (

i

,

j

) 2 tan  1 (

E

2 (

i

,

E

1 (

i

, 

E

2 (

i

,

j

) )

j

)   4

j

) 2 14

Roberst contrast detector

• The detector is very sensitive to high frequency noise.

• This sensitivity can be reduced by a low pass filtering. 15

Sobel detector

• very popular detector (Duda-Hart 1972) 1 2 0 -1 0 -2 1 0 -1 1 2 1 0 0 0 -1 -2 -1 • This filter can be seen as a convolution of two components: 1 -1 m0(i,j)= * m90(i,j)= * 1 1 1 2 1 16

Sobel detector

• As for Roberst the amplitude and orientation are computed by: Compute correlation for n=1,2:

E n

(

i

,

j

) 

p

m n

k

1 1   0  0

L p

(

i

k

,

j

L

)

m n

(

k

,

L

) Contrast magnitude Contrast direction

E

(

i

,  (

i

,

j

) 

j

) 

E

0 (

i

,

j

) 2 

E

90 (

i

, tan  1 (

E

90 (

i

,

E

0 (

i

,

j

) )

j

)   4

j

) 2 17

Original image Sobel detector Difference filter -1 0 1

Examples

Roberts detector Smoothing by binomial filters7 Difference filter -1 1 18

Contrast detection by derivatives

• Steps: – Smoothing: suppression of noise – Computation of gradient magnitude and orientation – Local extremum detection by hysteresis thresholding – Edge segment extraction 19

Smoothing by binomial filters

• Binomial filters are the best approximation of a discrete Gaussian with integer values.

• Binomial filters are generated by n convolutions of [1 1] • Binomial series: The binomial series is composed of the coefficients of the polynom

n

/ 2 (

x

y

)

n

m

  

n

/

b m

2 ,

n x n

m y m b m

,

n

   

n m

   

n

!

(

n

m

)!

m

!

20

The binomial series

• The coefficients of the binomial series can be generated by Pascal’s triangle 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 29 56 70 56 29 8 1 4 5 6 7 8 Level(n) 0 1 2 3 Sum 1 2 4 8 16 32 64 128 256 Variance 0 ¼ ½ ¾ 1 5/4 6/4 7/4 2 21

Binomial filters

• n convolutions of [1 1] • Gain: 2 n • Variance: var{b n (m)}=n var{b 1 (m)} = n/4 • discrete Gaussian with sigma = 1: 1 4 6 4 1 • sigma= 2: 1 8 29 56 70 56 29 8 1 • sigma=0.5: 1 2 1 22

Discrete Gaussian filter

Example of sampling a 1D Gaussian (sigma=1, R=3) session 4 G(x,1.0) |0.004|0.054|0.242|0.399|0.242|0.054|0.004| • discrete Gaussian with sigma = 1: 1 4 6 4 1 • Gain: 2 4 =16 16 G(x,1.0) |0.064|0.864|3.872|6.384|3.872|0.864|0.064| 23

Contrast detection by derivatives

• Steps: – Smoothing: suppression of noise – Computation of gradient magnitude and orientation – Local extremum detection by hysteresis thresholding – Edge segment extraction 24

Difference filters

ds

(

t

)  lim

dt

  0 {

s

(

t

) 

s

(

t

dt

) }

dn

 2 :

ds

(

n

) 

s

(

n

) 

s

(

n

 2 ) 2 session 4)

dn

 1 :

ds

(

dn n

) 

s

(

n

) 

s

1 (

n

 1 ) • To compute derivatives of a discrete signal, do convolution with the Gaussian derivative kernel (more details in 25

Difference filters

• Alternative method to convolution with Gaussian derivative kernel are the difference filters.

-1 0 1 -1 0 1 • Smoothing followed by a difference filter is equivalent to the Sobel operator.

26

Original image Sobel detector Difference filter -1 0 1

Examples

Roberts detector Smoothing by binomial filters Difference filter -1 1 27

Original image Sobel detector Difference filter -1 0 1

Examples

Roberts detector Smoothing by binomial filters7 Difference filter -1 1 28

Contrast detection by derivatives

• Steps: – Smoothing: suppression of noise – Computation of gradient magnitude E(i,j) and direction theta – Local extremum detection and hysteresis thresholding – Edge segment extraction 29

Local extremum detection

• Find direction of maximum gradient. Without loss of generality, let the direction be (1, 0) T • Check if E(i,j) is a maximum in this direction • This means: – Find contrast points C(i,j) that fulfill

C

(

i

,

j

)    1 0

E

(

i

,

j

) 

E

(

i

 

i

, 0 and

j

 

j

) 

E

(

i

, else

j

) 

E

(

i

 

i

,

j

 

j

) 30

Hysteresis thresholding

• Problem: some detectors produce weak edges which should be eliminated.

• Solution: hysteresis thresholding • Properties: eliminates weak edges below a low threshold, but not if they are connected to an edge above a high threshold.

weak edge C(i,j) C(i,j) after chaining strong edge 31

Hysteresis thresholding

• Uses a high and a low threshold – low threshold th0: sensitive to noise, but produces contour candidates – high threshold th1: indicates strong edges 1. Compute map F(i,j) with two thresholds th0, th1

F

(

i

,

j

)   2   1 0 if th1  | E(i, if th0  E(i, j) j) |  th1 else 32

Hysteresis filtering

2. Computing connected components of edge elements An edge is selected when it contains at least one strong edge element (with label 2).

Edges consisting of only weak edge elements are discarded.

33

Hysteresis filtering

• The thresholding and chaining can be computed in one step.

• Start with the high threshold image.

• For each strong edge continue adding (8 or 4) connected pixels with E(i,j)>=th0.

34

original image Low threshold image

Example

Contour image High threshold image 35

Contrast detection methods

• Search for extremum in 1 st derivative: ok • Search for zero crossing in 2 nd derivative 36

Contrast detection by 2

nd

derivatives

• The Laplacien is a isotropic filter that is used for the contrast detection.

– Lap(i,j)= Lxx(i,j) + Lyy(i,j) – with Lxx(i,j)= I(i,j) * Gxx(sigma) • As for Gaussians there exists a integer approximation of the Laplacian.

– Lxx(i,j) : [ 1 -1] * [1 -1] = [-1 2 -1] – Lxx(i,j)+Lyy(i,j): 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 -1 -1 0 -1 0 -1 4 -1 0 -1 0 37

Gradient norm and Laplacian

38

image Difference image Lx

Example

Lap Difference image Ly 39

Example

Difference image Lx Laplacian 40

image Difference image Lx

Example

Lap Difference image Ly 41

Contour detection by 2

nd

derivatives

• In theorie: – Contours can be detected more precisely using zero-crossing of 2nd derivative. – Sub-pixel precision is possible by interpolation.

– zero crossing of 2 nd contours.

derivatives produce closed • In real life: – The zero crossing of the 2 nd derivative detect also many small unstable regions.

42

Detection of zero crossing

• The extrema of the 1 st derivative correspond to zero crossing of the 2 nd derivative. • To generate a contour image C(i,j) proceed as follows: – consider 4-connected neighbors (N,S,W,E)

C

(

i

,

j

)    1 0

sign

(

W

) 

sign

(

E

)  | WE |  0 or

sign

(

N

) 

sign

(

S

)  |

NS

|  0 else 43

Detection of zero crossing

• For a stabler detection add a term that is related to the strength of the edge.

C

(

i

,

j

)    1

sign

or (

W sign

( )

N

 )

sign

 (

E sign

( ) 

S

| )  WE | |

NS

 0 |   0 |  W | N E S |  |  thres thres closed contour. The contours are no longer closed.

44

Session overview

1. Contrast description 2. Hough transform 45

Hough transform

• The Hough transform is a standard tool in image analysis that allows recognition of global patterns in an image space by recognition of local patterns in a transformed parameter space. • It is particularly useful when the patterns one is looking for are sparsely digitized, have ``holes'' and/or the pictures are noisy. • The basic idea of this technique is to find curves that can be parameterized like straight lines, polynomials, circles, etc., in a suitable parameter space.

Hough59

P.V.C. Hough, Machine Analysis of Bubble Chamber Pictures, International Conference on High Energy Accelerators and Instrumentation, CERN, 1959. 46

Hough transform

• Although the transform can be used in higher dimensions the main use is in two dimensions to find, e.g. straight lines, centres of circles with a fixed radius, parabolas

y

=

ax

2 +

bx

+

c

with constant values for m and c.

c

, etc. • As an example consider the detection of straight lines in an image. We assume them parameterized in the form: y=mx+c • Each image point (x,y) gives rise to a certain number of possible • This set of values forms a line c=-mx+y in the Hough space (m,c) • When the contour points are aligned, the corresponding lines in the Hough space have the same intersection point (m0,c0). • A point in hough space indicates a line in the image space.

source: http://rkb.home.cern.ch/rkb/AN16pp/node122.html

47

Hough transform

• Computation: – Initialise histogram h(m,c) (this represents the Hough space) – for each image point (i,j) • if C(i,j)=1, then compute all possible couples (m,c) that pass through the point (i,j). • increment all corresponding cells by 1.

– A local maximum (m0,c0) in h(m,c) indicates that the image points are aligned to the line y=m0 x+c0 48

Hough transform

• Problems: – Care has to be taken when one quantizes the parameter space. • When the bins table are chosen too fine, the local maximum can be dispersed over several bins. • When the quantization is not fine enough, on the other hand, nearly parallel lines which are close together will lie in the same bin. – The coefficients m,c are not uniform in orientation • Solution: use a different parameterization (p,theta): x sin(theta)-y cos(theta) + p =0 49

Hough transform

– Use a different parameterization (p,theta): x sin(theta)-y cos(theta) + p =0 – p is the distance from the origin and theta the angle with the normal – Here each point in the image space corresponds to a sinusoidal curve in the Hough space. The intersection of the sinusoidal curves in the Hough space correspond to a line in the image space.

50

Hough transform

• Computation: – Initialise histogram h(p,theta) (this represents the Hough space) – for each image point (i,j) • if C(i,j)=1, then – for all 0

Generalised Hough transform

• You can compute the hough transform for any pattern that can be parameterized, such as circles, lines, parabolas. • For circles: (x-a) 2 + (y-b) 2 = r 2 • We use a hough space h(a,b,r).

• Each image point corresponds to a cone in space (a,b,r) • For a fixed r, each image point corresponds to a circle in hough space.

• Algorithm: – for each image point and each radius r>0 compute the corresponding circle in hough space. Increment all cells. – After filling the histogram, locate the local maximum (a0,b0,r0). This maximum corresponds to the circle in the image with center (a0, b0) and radius r0. 52