You are on page 1of 84

Image Enhancement

 Intensity transformation functions:


Negative, log, Power law, linear transformation
 Basic Kernel operations
Image smoothening
Image Filtering, Sharpening
Edge Detection
 Histogram processing

1
Image Enhancement Examples

2
Spatial Processing
• Spatial domain refers to the image plane itself.
• Based on direct manipulation of pixels

• Intensity Transformation
Operates on single pixel of an image, principally for the
purpose of contrast manipulation and image
thresholding.

• Spatial Filtering
Deals with performing operations such as image
sharpening by working in a neighborhood of every pixel
in an image
3
Intensity Transformation
Spatial Filtering: Neighborhood Operation.
g(x,y)=T[f(x,y)]

Intensity Transformation: Neighborhood size is 1*1.


s= T(r)

4
Intensity Transformation Functions

 Image Negation
 Log Transformations
 Power Law Transformations
 Contrast stretching
 Slicing
 Thresholding

5
Continued--
Basic Intensity Transformation
There are many different kinds of grey level transformations.
Three of the most
common are shown here:
• Linear
Negative/Identity
• Logarithmic
Log/Inverse log
• Power law
nth power/nth root

6
Image Negation

 Useful in medical images


 A negative image is obtained
by reversing gray levels
according to the transformation
v= L–u

L u

7
8
Log Transformations
Dynamic Range Compression

9
 Log transformation maps a narrow
range of low intensity value in the
input into a wider range of output
levels.
 We use this type of transformation
to expand the value of dark pixel in
an image while compressing the
higher-level values.
 The opposite is true of the inverse
log transformation

10
Log Transformations(Continued…)

InvLog Log

11
Power Law(Gamma) Transformations
 

• varying gamma () obtains family


of possible transformation curves
• >1
 Compresses dark values
 Expands bright values
• <1
 Expands dark values
 Compresses bright values

12
Continued…
T ran sfo rm ed In ten sities

γ = 5.0
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Original Intensities

13
Continued …
• An aerial
photo
of a runway is
s = r 3.0

shown
• This time
s=

s = r 4.0
power law r 5.0

transforms are

used to darken

the image
• Different
curves 14
Intensity-level Slicing

Purpose: Highlight a specific range of gray values


Two approaches:
1. Display high value for range of interest, low value
else (‘discard background’)

2. Display high value for range of interest, original


value else (‘preserve background’)

15
Intensity-level Slicing(Continued…)

16
Bit-plane Slicing

Often by isolating particular


bits of the pixel values in an
image we can highlight
interesting aspects of that
image
• Higher-order bits usually
contain most of the
significant visual
information
• Lower-order bits contain Extracts the information of a
subtle details single bit-plane
17
Original [10000000] [01000000]
Image

[00100000] [00001000]

[00000100] [00000001]
18
Bit-plane Slicing(Continued….)

19
Bit-plane Slicing(Continued…)

Reconstructed image
using only bit planes
8 and 7

Reconstructed image
using only bit planes
8, 7 and 6

Reconstructed image
using only bit planes
7, 6 and 5
20
Spatial Filtering
 The concept of filtering has its roots in the use of the
Fourier transform for signal processing in the so-
called frequency domain.
 Spatial filtering term is the filtering operations that
are performed directly on the pixels of an image.

21
Spatial Filtering
 ‘Filter’ term in Digital image processing is referred to
the subimage
 There are others term to call subimage such as mask,
kernel, template, or window
 The value in a filter subimage are referred as
coefficients, rather than pixels.

22
Mechanics of spatial filtering
 The process consists simply of moving the
filter mask from point to point in an image.
 At each point (x,y) the response of the filter at
that point is calculated using a predefined
relationship

23
Linear spatial filtering
Pixels of image The result is the sum of
products of the mask
coefficients with the
w(-1,-1) w(-1,0) w(-1,1)
f(x-1,y-1) f(x-1,y) f(x-1,y+1) corresponding pixels
w(0,-1) w(0,0) w(0,1) directly under the mask
f(x,y-1) f(x,y) f(x,y+1)
w(1,-1) w(1,0) w(1,1) Mask coefficients
f(x+1,y-1) f(x+1,y) f(x+1,y+1)
w(-1,-1) w(-1,0) w(-1,1)

w(0,-1) w(0,0) w(0,1)


f(
x,y
)w
(

1,
1
)f
(x
1
,
y1
)
w
(
1
,
0
)f(
x
1
,y
)
w
(
1
,
1
)f(
x
1
,y
1
)

w
(
0
,
1
)f
(x
,y
1
)
w
(0
,
0)
f(
x,
y)
w(
0,
1
)f(
x
,y  1)
w(1,-1) 
w(1,0) w(1,1)
w
(
1
,
1
)f
(x
1
,
y1
)
w
(1
,
0)
f(
x1
,
y)
w(
1,
1
)f (x  1
, y  1)
24
Linear filtering

 The process of linear filtering similar to a


frequency domain concept called
“convolution”
Simplify expression mn
R  w1 z1  w2 z2  ...  wmn z mn   wi zi w1 w2 w3
9
i 1
w4 w5 w6
R  w1 z1  w2 z 2  ...  w9 z9   wi zi w7 w8 w9
i 1
Where the w’s are mask coefficients, the z’s are the value of the image gray
levels corresponding to those coefficients

25
Smoothing Spatial Filters

 Smoothing filters are used for blurring and for


noise reduction.
 Blurring is used in preprocessing steps, such as
removal of small details from an image prior to object
extraction, and bridging of small gaps in lines or
curves
 Noise reduction can be accomplished by blurring
26
Type of smoothing filtering

 There are 2 way of smoothing spatial filters


 Smoothing Linear Filters
▪ Averaging
▪ Gaussian
▪ Bilateral
 Order-Statistics Filters

27
Smoothing Linear Filters
 Linear spatial filter is simply the average of the
pixels contained in the neighborhood of the
filter mask.
 Sometimes called “averaging filters”.

 The idea is replacing the value of every pixel in


an image by the average of the gray levels in
the neighborhood defined by the filter mask.

28
Two 3x3 Smoothing Linear Filters

1 1 1 1 2 1
1 1
 1 1 1  2 4 2
9 16
1 1 1 1 2 1

Standard average Weighted average

29
Smoothing Linear Filters

 The general implementation for filtering an


MxN image with a weighted averaging filter
of size mxn is given by the expression

a b

  w(s, t ) f ( x  s, y  t )
g ( x, y )  s   at   b
a b

  w(s, t )
s   at   b

30
Order-Statistics Filters

 Order-statistics filters are nonlinear spatial filters


whose response is based on ordering (ranking) the
pixels contained in the image area encompassed by
the filter, and then replacing the value of the center
pixel with the value determined by the ranking result.
 Best-known “median filter”

31
Process of Median filter

 Corp region of
10 15 20
neighborhood
 Sort the values of
20 100 20 the pixel in our
region
20 20 25

10, 15, 20, 20, 20, 20, 20, 25, 100

5th
32
Result of Smoothing Linear Filters

Original Image

[3x3] [5x5] [7x7]

33
34
Sharpening Spatial Filters

 The principal objective of sharpening is to


highlight fine detail in an image or to enhance
detail that has been blurred, either in error or
as an natural effect of a particular method of
image acquisition.

35
Continued--

 The image blurring is accomplished in the


spatial domain by pixel averaging in a
neighborhood.
 Since averaging is analogous to integration.
 Sharpening could be accomplished by spatial
differentiation.
36
 We are interested in the behavior of these
derivatives in areas of constant gray level(flat
segments), at the onset and end of
discontinuities(step and ramp discontinuities), and
along gray-level ramps.
 These types of discontinuities can be noise points,
lines, and edges.
37
Definition for a first derivative
 Must be zero in flat segments
 Must be nonzero at the onset of a gray-level
step or ramp; and
 Must be nonzero along ramps.

38
Definition for a second derivative

 Must be zero in flat areas;


 Must be nonzero at the onset and end of a
gray-level step or ramp;
 Must be zero along ramps of constant slope

39
The Gradient (1 order derivative)
st

 FirstDerivatives in image processing are


implemented using the magnitude of the
gradient.
 The gradient of function f(x,y) is

 f 
Gx   x 
f      f 
G y   
 y 

40
Definition of the 1st-order derivative

 A basic definition of the first-order


derivative of a one-dimensional function
f(x) is

f
 f ( x  1)  f ( x)
x

41
Definition of the 2nd-order derivative

 We define a second-order derivative as the


difference

2 f
2
 f ( x  1)  f ( x  1)  2 f ( x).
x

42
43
First and second order derivative

1. 1st order generally produces thicker edges


2. 2nd order shows stronger response to detail
3. 1st order generally response stronger to gray level step
4. 2nd order produce double (pos/neg) response at step change

44
First and second order derivative

1. 1st order generally produces thicker edges


2. 2nd order shows stronger response to detail
3. 1st order generally response stronger to gray level
step
4. 2nd order produce double (pos/neg) response at 45
Analyze

 The 1st-order derivative is nonzero along the


entire ramp, while the 2nd-order derivative is
nonzero only at the onset and end of the ramp.

 The response at and around the point is much


stronger for the 2nd- than for the 1st-order
derivative

1st make thick edge and 2nd make thin edge

46
Gradient

 The magnitude of this vector is given by

mag(f )  Gx2  G y2  Gx  G y

Gx This mask is simple, and no isotropic. Its


-1 1
result only horizontal and vertical.

Gy 1

-1
This is an approximation of HPF
47
First Order Derivative Filter

Robert’s Method
 The simplest approximations to a first-order
derivative that satisfy the conditions stated in
previous are section are using cross differentiation
referred as cross gradient operator
z1 z2 z3 Gx = (z9-z5) and Gy = (z8-z6)

z4 z5 z6 f  ( z9  z5 ) 2  ( z8  z6 ) 2

z7 z8 z9
f  z9  z5  z8  z6

48
Robert’s Method

• The simplest approximations to a first-order


derivative that satisfy the conditions stated in
previous

-1 0 0 -1

0 1 1 0

49
Prewitt and Sobel’s Method
 Mask of even size are awkward to apply.
 The smallest filter mask should be 3x3.
 The difference between the third and first
rows of the 3x3 mage region approximate
derivative in x-direction, and the difference
between the third and first column
approximate derivative in y-direction.

50
Prewitt Operator

 With different mask coefficients:

 1  1  1  1 0 1
y   0 0 0  x   1 0 1
 1 1 1   1 0 1

51
Sobel’s Method

 Using this equation


f  ( z7  2 z8  z9 )  ( z1  2 z2  z3 )  ( z3  2 z6  z9 )  ( z1  2 z4  z7 )

-1 -2 -1 -1 0 1

0 0 0 -2 0 2

1 2 1 -1 0 1

52
The Laplacian (2 order derivative)
nd

 Shown by Rosenfeld and Kak[1982] that the


simplest isotropic derivative operator is the
Laplacian is defined as

2 2
2  f  f
 f  2  2
x y

53
The 2nd order derivative is the derivative of the 1st order
derivative…
F(x-1) F(x) F(x+1)

F(x)-F(x-1) F(x+1)-F(x) F(x+2)-F(x+1)

F(x+1)-F(x) – (F(x)-F(x-1))

F(x+1)-F(x) – (F(x)-F(x-1))= F(x+1) -2F(x)+F(x-1)


54
Discrete form of derivative

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


2
 f ( x  1, y )  f ( x  1, y )  2 f ( x, y )
x

f(x,y-1)

f(x,y) 2 f
2
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y )
y

f(x,y+1)
55
One dimensional
F(x+1)-F(x) 2 derivative in xF(x+1)
–nd(F(x)-F(x-1))= direction:
-2F(x) +F(x-1)

1 -2 1

One dimensional 2nd derivative, direction y:


1
-2
1

56
TWO dimensional 2nd derivative (derivatives are linear !):

0 0 0 0 1 0 0 1 0

1 -2 1 + 0 -2 0 = 1 -4 1

0 0 0 0 1 0 0 1 0

This mask is called the ‘LAPLACIAN’

57
Laplacian

0 1 0 1 1 1

1 -4 1 1 -8 1

0 1 0 1 1 1

1 0 1

0 -4 0

1 0 1

58
Laplacian

0 -1 0 -1 -1 -1

-1 4 -1 -1 8 -1

0 -1 0 -1 -1 -1

-1 0 -1

0 4 0

-1 0 -1

59
Implementation

 f ( x, y )   2 f ( x, y ) If the center coefficient is negative


g ( x, y )   2
 f ( x , y )   f ( x, y ) If the center coefficient is positive

Where f(x,y) is the original image


 2 f ( x, y ) is Laplacian filtered image
g(x,y) is the sharpen image

60
Implementation

61
Implementation

Filtered = Conv(image,mask)
62
Image Enhancement:
Histogram Based Methods
What is the histogram of a digital image?

· The histogram of a digital image with gray values r0, r1,…rL-1

is the discrete function


nk
p(rk)
n
nk: Number of pixels with gray value rk

n: total Number of pixels in the image

· The function p(rk) represents the fraction of the total number of pixels with
gray value rk.

63
Histogram provides a global description of
the appearance of the image.
If we consider the gray values in the image as
realizations of a random variable R, with some
probability density, histogram provides an
approximation to this probability density. In
otherwords,
Pr( R  rk )  p(rk )

64
Some Typical Histograms

· The shape of a histogram provides useful information for


contrast enhancement.

Dark image

65
Bright image

Low contrast image

66
High contrast image

67
Histogram Equalization
· What is the histogram equalization?

· The histogram equalization is an approach to enhance a given image. The


approach is to design a transformation T(.) such that the gray values in the
output is uniformly distributed in [0, 1].

· Let us assume for the moment that the input image to be


enhanced has continuous gray values, with r = 0 representing
black and r = 1 representing white.

· We need to design a gray value transformation s = T(r), based


on the histogram of the input image, which will enhance the
image.

68
· As before, we assume that:
(1) T(r) is a monotonically increasing function for 0£r£1
(preserves order from black to white).
(2) T(r) maps [0,1] into [0,1] (preserves the range of allowed
Gray values).

69
· Let us denote the inverse transformation by r = T -1(s) . We
assume that the inverse transformation also satisfies the above
two conditions.

· We consider the gray values in the input image and output


image as random variables in the interval [0, 1].

· Let pin(r) and pout(s) denote the probability density of the


Gray values in the input and output images.

70
· If pin(r) and T(r) are known, and r = T -1(s) satisfies condition 1, we can
write (result from probability theory):

 dr 
pout ( s)   pin (r ) 
 ds  r T 1 ( s )
· One way to enhance the image is to design a transformation
T(.) such that the gray values in the output is uniformly
distributed in [0, 1], i.e. pout (s) = 1, 0 £ s £1

· In terms of histograms, the output image will have all


gray values in “equal proportion” .

· This technique is called histogram equalization.

71
Next we derive the gray values in the output is uniformly distributed in
[0, 1]. Where “r” is normalized value.

·Consider the transformation

r
s
T
(
r)
p(
w
)
in ,0
dw
r
1
0

· Note that this is the cumulative distribution function (CDF) of pin (r) and
satisfies the previous two conditions.

· From the previous equation and using the fundamental


theorem of calculus,

ds
pin(r)
dr

72
· Therefore, the output histogram is given by

 1 
p
(s
)
p

out (
r
)
in  1
r

T1

()1
s , 0

s
1
 p (
r
)
in
r

T
1
(s
)

· The output probability density function is uniform, regardless of the


input.

· Thus, using a transformation function equal to the CDF of input gray


values r, we can obtain an image with uniform gray values.

· This usually results in an enhanced image, with an increase in the


dynamic range of pixel values.

73
How to implement histogram equalization?

Step 1:For images with discrete gray values, compute:


nk
pin(rk) 0r
k1 0
L
k
1
n
L: Total number of gray levels

nk: Number of pixels with gray value rk

n: Total number of pixels in the image

Step 2: Based on CDF, compute the discrete version of the previous


transformation :

k
s
kT
(r
k 
) p(
r
inj)
j
0
0
L
k
1
   
74
Example:

· Consider an 8-level 64 x 64 image with gray values (0, 1, …,


7). The normalized gray values are (0, 1/7, 2/7, …, 1). The
normalized histogram is given below:

NB: The gray values in output are also (0, 1/7, 2/7, …, 1).

75
Fraction
# pixels of #
pixels

Normalized gray value


Gray
value 76
k
· Applying the transformation, s
kT
(r
k 
) p(
r
inj)
j
0
we have

77
· Notice that there are only five distinct gray levels --- (1/7, 3/7,
5/7, 6/7, 1) in the output image. We will relabel them as (s0,
s1, …, s4 ).

· With this transformation, the output image will have histogram


Old grey nk New New nk Modifie
value grey lvl d grey
lvl

0 790 1 790 0=0


1 1023 3 1023 1=790
2 850 5 850 2=0
3 656 6 656+329 3=1023
=985
4 329 6 4=0
5 245 7 245+122 5=850
+81=448
6 122 7 6=985
7 81 7 7=448

78
79
Histogram of output
image

# pixels

Gray values

· Note that the histogram of output image is only approximately, and not exactly,
uniform. This should not be surprising, since there is no result that claims
uniformity in the discrete case.

80
Example Original image and its histogram

81
Histogram equalized image and its histogram

82
· Comments:
Histogram equalization may not always produce desirable
results, particularly if the given histogram is very narrow. It
can produce false edges and regions. It can also increase
image “graininess” and “patchiness.”

83
84

You might also like