Smoothing, Sharpening, Edges - Department of Computer Science

67 downloads 0 Views 10MB Size Report
A simple option for image smoothing. Removes outliers ... Often sufficient to use just a 3 × 3 or 5 × 5 filter kernel ... Example: 4 is median of {4,7,3,1,8,7,4,5,2,3,8}.
Smoothing

Sharpening

Edge Detectors

Smoothing, Sharpening, Edges1 Lecture 05

See Section 2.3 in Reinhard Klette: Concise Computer Vision Springer-Verlag, London, 2014 ccv.wordpress.fos.auckland.ac.nz

1

See last slide for copyright information. 1 / 25

Smoothing

Sharpening

Edge Detectors

Agenda

1

Smoothing

2

Sharpening

3

Basic Edge Detectors

2 / 25

Smoothing

Sharpening

Edge Detectors

Box Filter and Median Operator Image smoothing aims at eliminating “outliers” in image values considered to be noise in a given context Box Filter (Mean Operator) Local mean in a (2k + 1) × (2k + 1) window (as discussed before) A simple option for image smoothing Removes outliers but also reduces significantly the contrast Often sufficient to use just a 3 × 3 or 5 × 5 filter kernel Median Operator Median of a (2k + 1) × (2k + 1) window to reference pixel p Median of 2n + 1 values = value at position n + 1 in sorted order Example: 4 is median of {4, 7, 3, 1, 8, 7, 4, 5, 2, 3, 8} Removes outliers with only insignificant changes in image contrast 3 / 25

Smoothing

Sharpening

Edge Detectors

Example: Box Filter and Median Operator

Bottom, left: 11 × 11 box filter. Bottom, right: 11 × 11 median operator 4 / 25

Smoothing

Sharpening

Edge Detectors

Gauss Filter Local convolution with a filter kernel of samples of the 2D Gauss function 2D Gauss function is the product of two 1D Gauss functions

Gσ,µx ,µy (x, y ) =

  (x − µx )2 + (y − µy )2 1 exp − 2πσ 2 2σ 2 2

=

2

(y −µy ) (x−µx ) 1 · e − 2σ2 · e − 2σ2 2 2πσ

µx and µy are expected values for x- and y -components σ is the standard deviation, also called the radius of the function e = exp(1) is the Euler number. 5 / 25

Smoothing

Sharpening

Edge Detectors

2D Gauss Function

Left: For expected values µx = µy = 0 Right: Four examples of 1D Gauss functions

6 / 25

Smoothing

Sharpening

Edge Detectors

Centered Gauss Function

Zero means µx = µy = 0, thus  2  y2 x2 1 x + y2 1 − 2 − 2σ · e 2σ 2 Gσ (x, y ) = exp − = · e 2πσ 2 2σ 2 πs Sampled at (2k + 1) × (2k + 1) locations Defines the convolution kernel of the Gauss filter Parametrized by σ > 0 and k ≥ 1

7 / 25

Smoothing

Sharpening

Edge Detectors

Filter Kernel for Gauss Filter for k = 2 and σ = 1 Three-sigma rule in statistics: Sample Gσ by a kernel of size 6σ − 1 1

4

7

4

1

4

16

26

16

4

7

26

41

26

7

4

16

26

16

4

1

4

7

4

1

/273

Gauss Filter Input image I ; calculate local convolution L(x, y , σ) = [I ∗ Gσ ](x, y ) by using a sampled kernel 8 / 25

Smoothing

Sharpening

Edge Detectors

Comparison of Noise Removal

9 / 25

Smoothing

Sharpening

Edge Detectors

Caption to Figure on Page Before

Top, left: 128×128 input image with added uniform noise (±15) Top, right: 3 × 3 box filter Bottom, left: 3 × 3 sigma-filter with σ = 30 Bottom, middle: 3 × 3 median filter Bottom, right: Gauss filter for σ = 1 (as discussed above)

10 / 25

Smoothing

Sharpening

Edge Detectors

Sigma-Filter Often useful local operator for noise removal Assume a (2k + 1) × (2k + 1) window Wp 1

Calculate the histogram of window Wp

2

Calculate the mean µ of all values in the interval [I (p) − σ, I (p) + σ]

3

Let J(p) = µ

Example: σ = 50 for Gmax = 255 Note: 1 µ= · S

I (p)+σ

X

u · H(u)

u=I (p)−σ

H(u) histogram value for Wp and S = H (I (p) − σ) + . . . + H (I (p) + σ) 11 / 25

Smoothing

Sharpening

Edge Detectors

Agenda

1

Smoothing

2

Sharpening

3

Basic Edge Detectors

12 / 25

Smoothing

Sharpening

Edge Detectors

Sharpening Sharpening aims at producing an enhanced image J by increasing the contrast of the given image I along edges, without adding too much noise within homogeneous regions in the image Unsharp Masking 1

Residual R(p) = I (p) − S(p) for smoothed version S(p) of I (p)

2

Add this residual to the given image I : J(p) = I (p) + λ [I (p) − S(p)] = [1 + λ]I (p) − λS(p) where λ > 0 is a scaling factor

Any smoothing operator may be tried to produce S(p) Parameter k controls the spatial distribution of the smoothing effect Parameter λ controls the influence of the correction signal [I (p) − S(p)] 13 / 25

Smoothing

Sharpening

Edge Detectors

Examples of Sharpening

14 / 25

Smoothing

Sharpening

Edge Detectors

Caption to Figure on Page Before

Illustration of unsharp masking for k = 3 and λ = 1.5 Upper left: 512×512 blurred input image Upper right: Use of a median operator Lower left: Use of a Gauss filter with σ = 1 Lower right: Use of a sigma filter with σ = 25

15 / 25

Smoothing

Sharpening

Edge Detectors

Agenda

1

Smoothing

2

Sharpening

3

Basic Edge Detectors

16 / 25

Smoothing

Sharpening

Edge Detectors

Step-edge Model Step-edge model: Defined by local maxima or minima of first-order derivatives or zero-crossings of second order derivatives

Intensity profile of an input image

After noise removal

First-order derivative

Second-order derivative 17 / 25

Smoothing

Sharpening

Edge Detectors

Image Profiles: Step Edges, a Line, and a Slope Change

18 / 25

Smoothing

Sharpening

Edge Detectors

Derivatives The derivative of a unary function f in the continuous case df f (x + ε) − f (x) (x) = f 0 (x) = lim ε→0 dx ε Partial derivatives for function with two arguments, e.g. ∂f f (x, y + ε) − f (x, y ) (x, y ) = fy (x, y ) = lim ε→0 ∂y ε But In Ω we have the smallest distance ε = 1 between pixel locations No ε → 0 possible in the image grid 19 / 25

Smoothing

Sharpening

Edge Detectors

Discrete Derivatives Option 1: Reduce the derivative to a difference quotient for ε = 1 Option 2: Use a symmetric representation for ε = 1 Iy (x, y ) =

I (x, y + 1) − I (x, y − 1) 2

Thus no asymmetric bias, but very noise-sensitive Option 3: Larger filter masks For example, the Sobel operator uses the following kernels

20 / 25

Smoothing

Sharpening

Edge Detectors

Derivatives Define Gradient and Normal Gradient [Ix (p), Iy (p)]> = [a, b]> Defined by partial derivatives Ix (p) in x-, and Iy (p) in y -direction u

n

a

x

x γ

b

(x,y)

y

y

Normal n(p) = [Ix (p), Iy (p), +1]> = [a, b, +1]> Orthogonal to tangential plane 21 / 25

Smoothing

Sharpening

Edge Detectors

Gradient and Sobel Operator Gradient vector [Ix (p), Iy (p)]> at pixel location p ∈ Ω Magnitude of gradient q Ix (p)2 + Iy (p)2 = ||grad I (p)||2 identifies local maxima or minima in Ix (p) or Iy (p) (i.e. edges) Sobel Operator 1

Convolution with the two masks shown on page before

2

Produces at pixel p two values, Sx (p) and Sy (p)

3

Sum |Sx (p)| + |Sy (p)| is the result of the Sobel operator

This result approximates the magnitude of the gradient at p 22 / 25

Smoothing

Sharpening

Edge Detectors

Laplacian Following the step-edge model, edges are also identified with zero-crossings of second-order derivatives The Laplacian of a function I in two variables x and y : 4 I = ∇2 I =

∂2I ∂2I + 2 2 ∂x ∂y

Discrete Laplacian Simple discrete approximation defined by a filter kernel such as /

/

/

Edges now at zero-crossings of obtained positive or negative values 23 / 25

Smoothing

Sharpening

Edge Detectors

Value Profile of Row in Laplacian of an Image Typically first Gauss filter for noise removal, then Laplacian Known as Laplacian of Gaussian (LoG)

24 / 25

Smoothing

Sharpening

Edge Detectors

Copyright Information

This slide show was prepared by Reinhard Klette with kind permission from Springer Science+Business Media B.V. The slide show can be used freely for presentations. However, all the material is copyrighted. R. Klette. Concise Computer Vision. c

Springer-Verlag, London, 2014. In case of citation: just cite the book, that’s fine.

25 / 25