You are on page 1of 66

Image Enhancement in the Spatial Domain

Raul Queiroz Feitosa Gilson A. O. P. Costa

Enhancement in the Spatial p Domain


Contents
Introduction Background Point Processing Histogram Processing Local L l Enhancement E h Spatial Filters

Smoothing Filters Sharpening Filters

9/4/2013 Enhancement in the Spatial Domain 2

Introduction
Two Groups of Enhancement Techniques:

In the Spatial Domain


Based on the direct manipulation of the pixels in an image.

In the Frequency q y Domain


Based on modifying the Fourier Transform of an image.
digital di it l image digital image

Acquisition

Enhancement

Segmentation

Postprocessing

Feature extraction

Recognition

9/4/2013

Enhancement in the Spatial Domain

Background g
Notation:

g(x,y y) =T [ f(x,y y) ]
y (x,y)

where: f(x,y) is the input image, g(x,y) is the output image, and T is an operator defined over a neighborhood of (x,y).

9/4/2013

Enhancement in the Spatial Domain

Background g
Two groups of approaches:

Point Processing: when the neighborhood is of size 11, it becomes a gray level (or intensity or mapping) transformation function of the form: s =T (r) where r and s denote the gray level at f(x,y) and g(x,y) at any y point p (x,y y) ). Mask-Based: uses small arrays y called mask, , whose coefficients determine the nature of the process.

9/4/2013

Enhancement in the Spatial Domain

Point Processing g
Image Negatives
Output g gray leve el - s

T(r)

Input gray level - r


9/4/2013 Enhancement in the Spatial Domain 6

Point Processing g
Contrast Stretching
(r2,s2)

Output g gray leve el - s

T(r)

(r1,s s1)

Input gray level - r


9/4/2013 Enhancement in the Spatial Domain 7

Point Processing g
Power Law Transformation (Gamma Correction)
Correo Gama
Output g gray leve el - s
=0.04 =0.1 =0.2 =0.4 =0.67 =1 1 =1.5 =2.5 =5.0 5.0 =10 =25

where

Input gray level - r


9/4/2013 Enhancement in the Spatial Domain 8

Point Processing g
Power Law Transformation (Gamma Correction)
=0.04 =0.1 =0.04 =0.2 =0.1

Correo Gama

where

Output g gray leve el - s

=0.2 =0.4 =0.4 =0.67 =0.67 =1 =1 1 =1.5 =1.5 =2.5 =2.5 =5.0 5.0 =5.0 5.0 =10 =10 =25 =25

Input gray level - r


9/4/2013 Enhancement in the Spatial Domain 9

Point Processing g
Brightness Adjustment
s = r b , subjected to 0 s 1

Output g gray leve el - s

I Input t gray level l l-r


9/4/2013 Enhancement in the Spatial Domain 10

Histogram g Processing g
Definition The histogram g of a digital g image g with g gray y levels in the range [0,L-1] is a discrete function where:

rk is the kth gray level, nk is the number of pixels having gray level rk

9/4/2013

Enhancement in the Spatial Domain

11

Histogram g Processing g
Example: dark image

9/4/2013

Enhancement in the Spatial Domain

12

Histogram g Processing g
Example: bright image

9/4/2013

Enhancement in the Spatial Domain

13

Histogram g Processing g
Example: image with low contrast

9/4/2013

Enhancement in the Spatial Domain

14

Histogram g Processing g
Example: image with high contrast

9/4/2013

Enhancement in the Spatial Domain

15

Histogram g Processing g
When the pixel counts are normalized and pixel intensity (gray value) is considered a random variable, histogram is analogous to a PDF

where h :

rk is the kth gray level, nk is i the h number b of f pixels i l having h i gray level l l rk, and d n is the number of pixels in the image.
Enhancement in the Spatial Domain 16

9/4/2013

Histogram g Processing g
Histogram Equalization

Problem formulation: design a function s =T (r) that transforms a given input image so that the output image has uniformly distributed gray levels.

9/4/2013

Enhancement in the Spatial Domain

17

Histogram g Processing g
Histogram Equalization

Let pr(r) and ps(s) be the histogram respectively of the input and of the output images Assume that r and s represent the continuous gray levels in the interval [0,1]. [0 1] Search for the transformation function T (r) satisfying the following conditions:
a)
b) c)

T(r) is a single-valued and monotonically increasing in [0,1] 0 T(r) 1 for 0 r 1 the inverse function T-1(s) must also meet the above conditions

9/4/2013

Enhancement in the Spatial Domain

18

Histogram g Processing g
Histogram Equalization

From basic probability theory, if pr(r) and T(r) are known and T(r) is continuous and differentiable:

Considering C id i the h Cumulative C l i Distribution Di ib i (CDF) as the h transformation function:

9/4/2013

Enhancement in the Spatial Domain

19

Histogram g Processing g
Histogram Equalization

From basic probability theory, if pr(r) and T(r) are known and T(r) is continuous and differentiable:

Scaling S li up the h transformation f i function f i to the h actual l gray levels we have:

9/4/2013

Enhancement in the Spatial Domain

20

Histogram g Processing g
Histogram Equalization

9/4/2013

Enhancement in the Spatial Domain

21

Histogram g Processing g
Histogram Equalization

In the continuous case

In the discrete case

for k = 0,1,,L-1 where n is the total number of pixels

9/4/2013

Enhancement in the Spatial Domain

22

Histogram g Processing g
rk r0 = 0 r1 = 1 r2 = 2 r3 = 3 r4 = 4 r5 = 5 r6 = 6 r7 = 7 nk 790 1023 850 656 329 245 122 81 p(rk) = nk/n 0.19 0 25 0.25 0.21 0.16 0.08 0.06 0.03 0.02

L=8, 8 n=64x64=4096 64 64 4096

9/4/2013

Enhancement in the Spatial Domain

23

Histogram g Processing g

s0 = 1.33 1 s1 = 3.08 3 s2 = 4.55 4 55 5 s3 = 5.67 6

s4 = 6.23 6 s5 = 6.65 7 s6 = 6.86 6 86 7 s7 = 7.00 7

9/4/2013

Enhancement in the Spatial Domain

24

Histogram g Processing g
Histogram Equalization

A histogram is and approximation of a PDF and no new gray values are created: perfectly flat equalized equalized histograms are rare. Cannot be proved (in general) that discrete histogram equalization results in uniform histogram. Intensity levels of equalized image have a wider dynamic range. Net result is contrast enhancement. enhancement

9/4/2013

Enhancement in the Spatial Domain

25

Histogram g Processing g
T(r)

Equalization

9/4/2013

Enhancement in the Spatial Domain

26

Histogram g Processing g
Histogram Matching

Problem formulation: design a transformation function s =T T (r) that transforms a given input image so that the output image has a specified histogram.

9/4/2013

Enhancement in the Spatial Domain

27

Histogram g Processing g
Histogram Matching

Let pr(r) and ps(s) be the histogram of the input image and the desired (reference) histogram histogram.
input pr(r) H(r) G-1(z) pr(r) s = T(r) = G-1[H(r)] ps(s) uniform if G(s) reference ps(s)

9/4/2013

Enhancement in the Spatial Domain

28

Histogram g Processing g
Histogram Matching
image 1999 image 1999 with i ith th the histogram of image 2001 i image 2001

9/4/2013

Enhancement in the Spatial Domain

29

Local Enhancement

The parameters of most functions presented so far are computed based on the whole image. To enhance details in small image areas (example):
1. Select a neighborhood, whose center moves from pixel to pixel over the th image. i 2. At each position find the transformation function based on the pixel neighborhood. neighborhood 3. Apply the function to the pixel at the center of the neighborhood. pixel and repeat p steps p 2 and 3 till all 4. Move the center to the next p image is covered.

9/4/2013

Enhancement in the Spatial Domain

30

Local Enhancement
Example: local histogram equalization
Original Image After Global Equalization After Local Equalization

9/4/2013

Enhancement in the Spatial Domain

31

Region g of Interest Processing g (ROI)


Logical matrices called masks can be used to define regions in an image (roi) where an operator is to be applied. Example: blurring uninteresting regions
input image mask (roi) output image

9/4/2013

Enhancement in the Spatial Domain

32

Local Enhancement
Histogram Statistics for Enhancement

Global statistics: the nth moment about the mean


n (r ) =

(r
i=0

L 1

m ) p (ri )
n

where

m =

L 1 i=0

ri p (ri )

9/4/2013

Enhancement in the Spatial Domain

33

Local Enhancement
Histogram Statistics for Enhancement

neighborhood g with a given g size around (x,y ,y) ). mS xy =


2 S =
xy

Local statistics: let (x,y) be the pixel coordinates and Sxy a


r p(r ) ( )
s ,t S xy s ,t s ,t ( s ,t )S xy

average gray level around Sxy

(r

s ,t

mS xy

) p(r )
2 s ,t

contrast around Sxy

9/4/2013

Enhancement in the Spatial Domain

34

Local Enhancement
Histogram Statistics for Enhancement

Example: enhance SEM image (tungsten filament wrapped around a support) Enhance only dark areas Enhance low contrast areas, but not constant/uniform areas

9/4/2013

Enhancement in the Spatial Domain

35

Local Enhancement
Histogram Statistics for Enhancement

Example: enhance SEM image (tungsten filament wrapped around a support) Enhance only dark areas:

mS xy k0 M G
MG is the global mean mS xy is the local mean k0 is positive, less than one Sxy is 3x3

9/4/2013

Enhancement in the Spatial Domain

36

Local Enhancement
Histogram Statistics for Enhancement

Example: enhance SEM image (tungsten filament wrapped around a support) Enhance low contrast areas:

S k 2 DG
xy

DG is the global standard dev S is the local standard dev k2 is positive, less than one Sxy is 3x3
xy

9/4/2013

Enhancement in the Spatial Domain

37

Local Enhancement
Histogram Statistics for Enhancement

Example: enhance SEM image (tungsten filament wrapped around a support) Enhance non uniform areas:

k1 DG S xy
DG is the global standard dev S is the local standard dev k1 is positive, less than k2 Sxy is 3x3
xy

9/4/2013

Enhancement in the Spatial Domain

38

Local Enhancement
Histogram Statistics for Enhancement

Example: enhance SEM image (tungsten filament wrapped around a support) Enhance only dark areas Enhance low contrast areas, but not constant/uniform areas

9/4/2013

Enhancement in the Spatial Domain

39

Local Enhancement
Histogram Statistics for Enhancement

Example: enhance SEM image (tungsten filament wrapped around a support) Enhance only dark areas Enhance low contrast areas, but not constant/uniform areas

E=4;k0=0.4;k1=0.02;k2=0.4}
9/4/2013 Enhancement in the Spatial Domain 40

Spatial p Filters

Operation:
ww w w 1 1w 11 2w 11 3 2 w1 4 w1 5 w2 4 2 6 5 4 1 3 w1 7 w4 4 8 w5 7 1 5 9 8 7 1 6 w1 7 w7 8 w8 9

g(x,y)=T [ f(x,y)],
w1 3 w2 2 3 w3 w3 6 w5 5 4 6 w6 . . . w6 9 w8 8 7 9 w9 a b g ( x , y ) = w (s , t ) f ( x + w9 s= at=b

s, y + t )

Response of a linear spatial filter R=w1z1+ w2z2+ . . .+ w9z9 Image


9/4/2013 Enhancement in the Spatial Domain 41

Smoothing g Filters

Aplications: p

Removal of small details prior to large object extraction. Noise reduction. It blurs the image. All elements are non-negative, and sum up to 1.

Side Effect

Smoothing masks

Masks

1 1 1 1/9 1 1 1 1 1 1
averaging filter 33

1 7 1 1/88 7 54 7 1 7 1
gaussian filter 33
42

9/4/2013

Enhancement in the Spatial Domain

Smoothing g Filters
Examples of applying an averaging filter:

original

33

55

77
9/4/2013

1515
Enhancement in the Spatial Domain

2525
43

Smoothing g Filters

Order Statistic Filters are non-linear spatial p filters whose response p is based on ordering (ranking) the pixels contained in the image area encompassed by the mask, mask and then replacing the value of the center pixel with the value determined by the ranking result. result

9/4/2013

Enhancement in the Spatial Domain

44

Smoothing g Filters

Order Statistic Filters:

Median Filter replaces the value of a pixel by the median of the gray levels in its neighborhood g A median of a set of values is such that half of the values in the set is lower than and half f of f the values in the set is greater than or equal to . Percentile Filter replaces the value of a pixel by n-th percentile of the gray g y levels in its neighborhood. g
Enhancement in the Spatial Domain 45

9/4/2013

Smoothing g Filters

Examples :

Original image

Image with salt-and-pepper noise

After average 5x5 filtering


9/4/2013

After median filtering


46

Enhancement in the Spatial Domain

Adaptive p Filter
The output p g(x,y ,y) of a adaptive p filter depends p on the statistical characteristics of the input image f(x,y) inside a m mn n rectangular window Sxy centered at (x,y). variance of the noise (?)
2 g ( x, y ) = f ( x, y ) 2 [ f ( x, y ) mL ] L

variance in Sxy
9/4/2013 Enhancement in the Spatial Domain

mean in Sxy
47

Adaptive p Filter
2 is zero: no noise, nothing should change 2 2 is high relative to : no change, probably an edge L 2 2 is similar to : reduce noise by averaging L 2 2 L is less than : must avoid/treat negative output

variance of the noise (?)


2 g ( x, y ) = f ( x, y ) 2 [ f ( x, y ) mL ] L

variance in Sxy
9/4/2013 Enhancement in the Spatial Domain

mean in Sxy
48

Adaptive p Filter
Example p

image corrupted by additive Gaussian noise of zero mean and variance 1000
9/4/2013

result of an arithmetic mean filter

result of an adaptive noise reduction filter

Enhancement in the Spatial Domain

49

Sharpening p g Filters

Applications pp

Highlight of fine details. Enhance details that have been blurred due to the acquisition method.

Side Effect

Emphasizes the noise.

9/4/2013

Enhancement in the Spatial Domain

50

Sharpening p g Filters
Accomplished by spatial differentiation:

Approximation for the 1 derivative


f (x ) = x

lim

x o

f (x + x ) f (x ) f (x + 1 ) f (x ) x

Approximation for the 2 2 derivative


2 f (x ) [ f (x + x ) f ( x )] [ f (x ) f ( x x )] = lim x 2 x2 x o f (x + 1 ) 2 f (x ) + f (x 1 )

9/4/2013

Enhancement in the Spatial Domain

51

Sharpening p g Filters

9/4/2013

Enhancement in the Spatial Domain

52

Edge g Detection
-1 0 -1 0 -1 0 1 1 1 4 3 2 1 0 4 3 2 1 0 -1 -2 -3 -4 4 3 2 1 0 -1 -2 -3 -4

Prewitt mask

pixel values of horizontal line

first derivative

second derivative

9/4/2013

Image Segmentation

53

Sharpening p g Filters

1.

From the previous slide we may conclude:


First-order derivatives g generally y produce thicker edges in the image, Second-order derivatives have a stronger g response p at the fine details, First-order derivatives g generally y have a stronger g response to a gray-level step, and Second-order derivatives have a double-response p at step changes in gray level.

2.

3.

4.

9/4/2013

Enhancement in the Spatial Domain

54

Sharpening p g Filters

Laplacian Filter
2 f 2 f f = + 2 x y 2
2

Starting from

2 f f ( x + 1, y ) 2 f (x, y ) + f (x 1, y ) 2 x
2 f f ( x , y + 1) 2 f ( x , y ) + f ( x , y 1) 2 y

we obtain b i
2 f = [ f ( x + 1, y ) + f (x 1, y ) + f ( x, y + 1) + f ( x, y 1) 4 f (x, y )
9/4/2013 Enhancement in the Spatial Domain

]
55

Sharpening p g Filters

Laplacian Filter: example of masks

0 0

1 1

0 0

1 1

1 1

1 1

1 1

4 4

1 1

1 -4 1

1 -8 1

4 -20 4

9/4/2013

Enhancement in the Spatial Domain

56

Sharpening p g Filters
Laplacian based filter : an example f ( x, y ) C 2 f ( x, y ) if center coefficient <0 f s ( x, y ) = 2 ( ) f x y C f ( x, y ) if center coefficient >0 , + The Th sharpening h i effect ff t i in 1-D 1D

f ( x)
2 f (x) f ( x) 2 f ( x)

shaper transition

9/4/2013

Enhancement in the Spatial Domain

57

Sharpening p g Filters

Laplacian based filter: a mask example

0 0 0

0 1 0

0 0 0 -C

0 1 0

1 -4 1

0 1 0

-C

- C 4C+1 - C 0 -C 0

9/4/2013

Enhancement in the Spatial Domain

58

Sharpening p g Filters

Laplacian Filter: application example


Imagem Original C=2 C=4

C=6

C=8

C=10

9/4/2013

Enhancement in the Spatial Domain

59

Sharpening p g Filters

Unsharp masking
Subtracts a blurred version of an image g from the image g itself
f um ( x, y ) = f ( x, y ) f ( x, y )

Example of a mask
0 0 0 0 1 0 0 0 0 1

output of a smoothing filter 1 1 1 1 1 1 =


-1/9 -1/9 -1/9 -1/9 8/9 -1/9

1/9 1
1

-1/9 -1/9 -1/9

9/4/2013

Enhancement in the Spatial Domain

60

Sharpening p g Filters

Filter High-Boost
It is a generalization of unsharp masking, given by

f hb ( x, y ) = Af ( x, y ) f ( x, y ) for A 1

f hb ( x, y ) = ( A 1) f ( x, y ) + f s ( x, y ) for A 1
output of a sharpening filter

If we elect to use the Laplacian filter for sharpening

Af ( x, y ) 2 f ( x, y ) if center coefficient <0 f hb ( x, y ) = 2 ( ) Af x y f ( x, y ) if center coefficient >0 , +


9/4/2013 Enhancement in the Spatial Domain 61

Sharpening p g Filters

Filter High-Boost: example


original i i l image

laplacian

high-boost with A=1

high-boost with A=1.7

9/4/2013

Enhancement in the Spatial Domain

62

Sharpening p g Filters

The Gradient
f x f = f y
f f f = mag (f ) = + x y
2 2 1/ 2

9/4/2013

Enhancement in the Spatial Domain

63

Sharpening p g Filters

Masks for the Gradient


-1 1 0 0 -1 1 0 1 -1 -1 1 -1 -1 0 1
Prewitt

-1 0 1 1 1 1

-1 0 1 -1 -2 2 -1

-2 0 2
Sobel

-1 0 1 1 2 1
64

Roberts 0 1

0 0 0

0 0 0

-1 1

9/4/2013

Enhancement in the Spatial Domain

Sharpening p g Filters

Gradient: example

original image

|Gx| (sobel)

|Gy| (sobel)

|Gx|+|Gy| (sobel)
9/4/2013 Enhancement in the Spatial Domain 65

Next Topic p

Image g Enhancement in the Frequency Domain


9/4/2013 Enhancement in the Spatial Domain 66

You might also like