Está en la página 1de 34

Advanced Digital Image Processing

Lecture #7

Dr. Md. Hasanuzzaman


Associate Professor
Department of Computer Science & Engineering
University of Dhaka

August 13, 2007

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 1


Contents

 Introductionto Image Enhancement


 Image Enhancement in the Spatial Domain

 Gray Level Image Transformation

 Image Enhancement in the Frequency Domain

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 2


Introduction to Image
Enhancement
 Enhancement is to process an image so that the
result is more suitable than the original image
for a specific application
 Two approaches use for image enhancement:
 Spatial domain: Refer to the image plane itself. Direct
manipulation of pixels in an image
 Frequency Domain: Based on modifying the Fourier
Transform of an image

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 3


Image Enhancement in the
Spatial Domain

 The term spatial domain refers to the image plane itself


 Approached in this category are based on direct modification
of pixels,
 Spatial domain process is denoted by the expression,
g (x, y) = T [f (x, y)]
Where, f (x, y) is the input image, g (x, y) is the processed image
T is an operator defined over some neighborhood of (x, y).

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 4


Gray Level Image Transformation

 The value of pixels before and after


processing are denoted by r and s,
s = T(r), Where T is Transformation
 Basic types of function used for image
enhancement:
 Linear: Negative and identity transformations
 Logarithm: Log and inverse log transformations
 Power-low: n-th power and n-th root transformations
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 5
Image Negative
The negative of image with gray levels in the range [0, L-1]
is obtain by,
s = (L–1) – r
Where, L -1 ( for 8 bit 255) is the upper limit of the gray
level, r = gray level of f(x, y), s = gray level of g(x, y)
Procedure:
for (int i=0;i< width; i++){
for (int j=0;j< height; j++){
pixels [i][j] = 255-pixels [i][j];
}
} Negative

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 6


Log and Power Transformations

 Log transformations:
s = clog(1+r) where, c is a constant, r>=0
 Power-low transformations:
s=crγ , where c and γ are positive
constants
 Gamma Corrections:
The exponent of the power law equation is referred to
as gamma. The process used to correct this power law
response phenomena is called gamma correction.

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 7


Image Enhancement in the Spatial Domain
(Contrast Stretching)
 Contrast stretching is piecewise-linear transformation
function.
 to increase the dynamic range of the gray levels in the
image being processed
L-1
output gray level, s

3L/4 (r2, s2)

L/2 T(r)

L/4 (r1, s1)


0 L/4 L/2 3L/4 L-1
Input gray level, r
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 8
Image Enhancement in the
Spatial Domain
(Histogram Processing)
 Intensity distribution in the image
 The histogram functions count the number
of elements within a range and display each
range as a rectangular bin. The height (or
length when using rose) of the bins
represents the number of values that fall
within each range.
for (int i=0;i<width;i++){
for (int j=0;j<height;j++){
int x = pixels[i][j];
histData[x] =histData[x]+1;
}
}

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 9


Histogram Processing

 The histogram of a digital image with gray levels in


the range [0, L-1] is a discrete function h(rk)=nk
where rk is the kth gray level and nk is the number of
pixels in the image having gray level rk.
 Normalization: to normalize a histogram by dividing
each of its values by the total number of pixels in the
image, denoted by n.
 Normalized histogram P(rk)=nk/n

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 10


Image With Histogram

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 11


Histogram Equalization
k k nj
sk =T ( rk ) =∑ Pr ( r j ) =∑
j=0 j=0 n

 The probability of occurrence of gray


level rk in an image is approximated by,

n
Pr
( )
k = k
 Where k =0,1,2,---L-1;n
n is the total
number of pixels, nk is the number of
pixels that have gray level rk.
 A plot pr(rk) vs. rk is called histogram
 The transformation (mapping) sk is
called histogram equalization

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 12


Histogram Equalization Algorithm

 1. Calculate Histogram  3. Transform input image to


loop over i ROWS of input image output image
loop over j COLS of input image area = area of image (ROWS x COLS)
k = input_image[i][j] Dm = number of gray levels in output
hist[k] = hist[k] + 1 image
end loop over j loop over i ROWS
end loop over i loop over j COLS
k = input_image[i][j]
 2. calculate the sum of hist
out_image[i][j] = (Dm/area) x sum_of_hist[k]
loop over i gray levels
end loop over j
sum = sum + hist[i]
end loop over i
sum_of_hist[i] = sum
end loop over i

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 13


Comparison of Image:
Before and After Histogram Equalization
Make low bright region
to higher bright
Reduce the number of
gray level

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 14


Image Enhancement in the
Spatial Domain:

Local Enhancement:
Enhancement of image in a particular area to reduce
noise.

Image Arithmatic
Image subtraction, addition, multiplication, division
g (x, y) = f (x, y) – h (x, y)
g (x, y) = f (x, y) + h (x, y)

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 15


Basics of Spatial Filtering
 Some neighborhood operations work with the values of the
image pixels in the neighborhood and the corresponding
values of a sub-image that has a same dimensions as the
neighborhood.
 This sub-image is called filter, mask, kernel, template or
window.
 The values in a filter sub-image are referred to as
coefficients, rather than pixels
 Filtering operations that are performed directly on the
pixels of an image is called spatial Filtering.
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 16
Basics of Spatial Filtering
W(-1,-1) W(-1,0) W(-1,1)

W(0,-1) W(0,0) W(0,1)

(0,0) y
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)


Mask
f(x,y-1) f(x,y) f(x,y+1)

x f(x+1,y-1) f(x+1,y)
Image f(x,y) f(x+1,y+1)

Pixels of image
section under mask
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 17
Basics of Spatial Filtering
 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
 The response is given by a sum of products of the filter
coefficients and the corresponding image pixels in the area
spanned by the filter mask.
 Limitation near boundary:
 to limit the excursions of the center of the mask to be at a
distance no less than (n-1)/2
 padding by 0 or constant gray level, then stripped

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 18


Smoothing Spatial Filters

Smoothing Linear Filter:


The output (response) of a smoothing, linear spatial filter is simply the average
of the pixels contained in the neighborhood of the filter mask. These filters
sometimes are called averaging filters or low pass filters.

1 1 1 1 1 1 2 1
× 1 1 1 × 2 4 2
9 1 1 1 16 1 2 1
3x3 smoothing filter masks
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 19
Smoothing Spatial Filters

Non-Linear Spatial Filter:


The nonlinear spatial filter whose response is based on ordering 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. The
best known filter is median filters.

Max Filters: use to find the brightest point


Min Filters:use to find the darkest point

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 20


Sharpening Spatial Filters
 Sharpening is to highlight fine detail in an image
 First-order derivative: of an one dimensional function, f(x)
∂f
= f ( x + 1) − f ( x)
∂x
 Second-Order derivative
∂2 f
= f ( x + 1) + f ( x − 1) − 2 f ( x)
∂x 2

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 21


Example of First and Second Order
Derivatives
f(x-1) f(x) f(x+1)

5 5 4 3 2 1 0 0 0 6 0 0 0 7 7 . .

1st derivative -1, -1, -1, -1, -1, 0, 0, 6, -6, 0

2nd derivative -1, 0, 0, 0, 0, 1, 0, 6, -12, 6


First order derivative produce thick edge
2nd order derivative produce much finer one and strong response at
isolated point
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 22
Image Enhancement in the
Frequency Domain
Any continuous function f(x) can be expressed as an integral over
sine and cosine waves.
Any signal that is non-zero over a finite range can also be
represented by an infinite number of sine waves.
Sum of four functions

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 23


Spatial Vs. Frequency Domain

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 24


Spatial Vs Frequency Domain

Sine wave

Square wave

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 25


Fourier Transform (1 of 3)
Fourier Transform (in one dimension)

M −1
1
F (u ) =
M
∑ f ( x)[ cos2πux / M − j sin 2πux / M ]
x= 0

Where, for u = 0,1,2,………, M


Each term of the Fourier transform is composed of the sum of
all values of the function f(x).
The values of f(x) are multiplied by sine and cosines of various
frequencies
 Each of the M term of F(u) is called the frequency component
of the transform
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 26
Fourier Transform (2 of 3)

 Fourier Transform (in two dimension)

1 M − 1 N −1
F (u, v) = ∑ ∑
MN x = 0 y = 0
f ( x, y )e − j 2π ( ux / M + vy / N )

 It is common practice to multiply the input image function


by (-1)x+y prior to computing Fourier transform. This shifted
the origin of the transform to u=M/2 and v=N/2

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 27


Fourier Transform (3 of 3)

 The value of the transform at (u,v) =(0,0) is


M −1 N −1
i
F (u , v ) =
MN
∑∑f ( x, y )
x =0 y =0

Which we see is the average of f(x, y).


 In other words if f(x,y) is an image the value of the Fourier transform at
the origin is equal to the average gray level of the image.

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 28


An Image and its Fourier Spectrum

Rate of change in frequency in FT is equal to the pattern of intensity variation.


Away from origin higher the frequency and faster gray level change.

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 29


Image Filtering in the
Frequency Domain

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 30


Filtering in the
Frequency Domain
Notch Filter (lowering the average gray level)

0 if (u , v ) = ( M / 2, N / 2)
H (u , v ) = 
1 otherwise
G(u,v) = H(u,v) F(u,v)

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 31


Filtering in the Frequency Domain

• Low pass filtering

1 ifD (u , v ) ≤ D0
H (u , v ) = 
0 ifD (u , v ) > D0

[
D(u, v) = (u − M / 2) + (v − N / 2) 2
]
2 1/ 2

• Cuts off all high frequency over


D0
November 27, 2009 Advanced Digital Image Processing, Lecturer #7 32
Filtering in the
Frequency Domain
High Pass Filter

0 ifD (u , v ) ≤D0
H (u , v ) =
1 ifD (u , v ) >D0

Cuts off all frequency below D0

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 33


List of Reference Books

 Rafael C. Gonzalez, “Digital Image Processing”.


 Anil K. Jain, “Fundamental of Digital Image
Processing”.
 Dana H. Ballard, “Computer Vision”
 David H. Hubel, “Eye, Brain, and Vision”
 Dwayne Phillips, “Image Processing in C”

November 27, 2009 Advanced Digital Image Processing, Lecturer #7 34

También podría gustarte