Sie sind auf Seite 1von 100

Image Enhancement in the Spatial Domain

(Chapter 3)
Prepared by:
Mohammed Ali Abbaker
Fakher Aldin Yahia Omer
Waleed Ahmed Hussein


Diploma/M. Sc. On Computer Architecture and Networking
Third Term, 2011/12
Digital Image Processing (DIP) SC614
Seminar

Supervised by:
Dr. Abdelrahim Elobeid Ahmed
outline
Image enhancement
Image transformation
pixel point processing
Intensity transformation with unknown image information
Intensity transformation with histogram information.
spatial filtering

Image enhancement
The principal objective is to process an image so that the
result is more suitable than the original image for a specific
application

specific is important, because it establishes at the outset
that the techniques discussed in this seminar are very much
problem oriented

The best approach for enhancing X-ray images may not
necessarily be the best for enhancing pictures of Mars
transmitted by a space probe too

Evaluation of image enhancement method
There is no general theory of image enhancement. When an image is
processed:
for visual interpretation:
The algorithm performance evaluation depends ultimately on the
viewers judgment.
subjective process, different form person to person & from situation
to another.
for machine perception:
The evaluation task is somewhat easier.
objective process with specific object to achieve. For example, at
the recognition application: the object could as specific computational
requirements. The best image processing method would be the one
yielding the best machine recognition results.
However, even in situations when a clear-cut criterion of performance can
be imposed on the problem, a certain amount of trial and error usually is
required before a particular image enhancement approach is selected.

Image enhancement approaches
two broad categories:-
1. spatial domain methods:
based on direct manipulation of pixels in an image
image plane.
2. frequency domain methods:
based on modifying the Fourier transform of an image.

Enhancement techniques like most of the other image
processing applications based on various combinations of
methods from these categories.

Background
value f(x,y) at each x, y is called intensity
level or gray level
Digital image representation
Image Transformation - Definition
Is a process of changing the color or grayscale
values of an image pixel by operations like
adjusting the contrast or brightness, sharpening
lines, modifying colors, or smoothing edges, etc
This discussion divides image transforms into two
types:
pixel point processing
Intensity transformation with unknown image information
Intensity transformation with histogram information.
spatial filtering
Intensity Transformations and Filters
spatial domain :the aggregate of
pixels composing an image.
Spatial process expression:
g(x,y)=T[f(x,y)]

f(x,y) input image,
g(x,y) output image

T is an operator on f
defined over a neighborhood of
point (x,y)





Spatial Domain Methods
f(x,y)
g(x,y)
g(x,y)
f(x,y)
Point pixel
Processing
Area/Mask
Processing
Intensity Transformation
1 x 1 is the smallest possible neighborhood.
In this case g depends only on value of f at a single point
(x,y)
and we call T an intensity (gray-level or mapping)
transformation and write
s = T(r)
where r and s denotes respectively the intensity of g and f at
any point (x, y).

Transform Functions and Curves (2)
Transforms can be applied to pixel values in a variety of
color modes
If the pixels are grayscale, then p
1
and p
2
are values
between 0 and 255
If the color mode is RGB or some other three-component
model
f(p) implies three components, and the transform may be
applied either to each of the components separately or to the
three as a composite
For simplicity, we look at transforms as they apply to
grayscale images first
Transform Functions and Curves (3)
An easy way to understand a transform function is to look
at its graph
A graph of transform function T for a grayscale image has
p
1
on the horizontal axis and p
2
on the vertical axis, with
the values on both axes going from 0 to 255, i.e., from
black to white (see figure 1)
Transform Functions and Curves (4)
The transform in Figure 1.a doesnt change the
pixel values. The output equals the input.
The transform in Figure 1.b lightens all the
pixels in the image by a constant amount.
The transform in Figure 1.c darkens all the
pixels in the image by a constant amount.
The transform in Figure 1.d inverts the image,
reversing dark pixels for light ones.
The transform in Figure 1.e is a threshold
function, which makes all the pixels either black
or white. A pixel with a value below 128
becomes black, and all the rest become white.
The transform in Figure 1.f increases contrast.
Darks become darker and lights become lighter.
Figure 1 Curves for adjusting
contrast
Transform Functions and Curves (5)
In Figure 2, weve applied the functions shown in Figure 1
so you can see for yourself what effect they have
Figure 2 Adjusting
contrast and brightness
with curves function
Point Processing Transformations
Convert a given pixel value to a new pixel value based on some
predefined function.
Image transformation
Image enhancement
Image transformation
pixel point processing
Intensity transformation with unknown image information
Intensity transformation with histogram information.
spatial filtering

1- Identity Transformation
Some Basic Intensity Transformation Functions
2- Negative Image
Negative of an image with intensity levels in the range [0,
L-1] is obtained using the expression
s = L 1 r
Suited for enhancing white or gray detail embedded in dark
regions of an image specially when the black areas are
dominant in size
3- Contrast Stretching or Compression

Stretch gray-level ranges where
we desire more information
(slope > 1).

Compress gray-level ranges that
are of little interest
(0 < slope < 1).
Thresholding
Special case of contrast compression
3- Contrast-Stretching Transformations
E
r m
r T s
) ( 1
1
) (
+
= =
where r represents the intensities of the input image, s
the corresponding intensity values in the output image,
and E controls the slope of the function.
Fig. 3.2(a): Produce an image of higher contrast than the original in the
middle by:
by darkening the levels below m & compressing values of r into a narrow
range of s toward black
By brightening the levels above m in the original image through &
compressing values of r into a narrow range of s toward white.
Fig. 3.2(b): special compressing techniques T(r) produces a two-level
(binary) image. A mapping of this form is called a thresholding function.
Thresholding:
29
i. Contrast Stretching: expands the range of intensity levels in an
image so that it spans the full intensity range
Points: (r
1
, s
1
) , (r
2
, s
2
)
if: r
1
= s
1
and r
2
= s
2
linear transformation that produces no
changes in the intensity levels
if: r
1
= r
2
and s
1
= 0 and s
2
= L -1

the transformation becomes a
thresholding function that creates a binary image
intermediate values of (r
1
, s
1
) , (r
2
, s
2
) produces various degrees of
spread in the intensity levels of the output image, thus affecting its
contrast
Use: (r
1
, s
1
) = (r
min
, 0) and (r
2
, s
2
) = (r
max
, L - 1)
Piecewise-Linear Transformation Functions
Contrast stretching
Low-contrast images can result from:
poor illumination.
lack of dynamic range in the imaging sensor.
or even wrong setting of a lens aperture during image
acquisition.
The idea behind contrast stretching is to increase the
dynamic range of the gray levels in the image being
processed.
The implementation through wisely slices the linear
transformation line into different slopes

Piecewise-Linear Transformation Functions
ii. Gray level slicing:
Highlight specific ranges of gray-levels only.
Same as double
thresholding!
33
Piecewise-Linear Transformation Functions

iii. Bit-Plane Slicing : pixels are digital numbers composed of bits
In the 256-level gray-scale image is composed of 8 bits
each pixel is represented by 8 bits
each 8bit would distributed to 8-planes
Highlighting the contribution made by a specific bit.
Each bit-plane is a binary image

Useful for image compression
Storing planes: 5, 6, 7, and 8 requires 50% less storage


4- Logarithmic transformation
Enhance expand details in the darker regions of an image at
the expense of detail in brighter regions.
( ) ( ) r c r T s + = = 1 log
The dynamic range of the Fourier coefficients (i.e. the intensity values in the Fourier image)
Exponential transformation
Log inverse transformation

Reverse effect of that obtained using logarithmic mapping.
Log transformation
41
5- Power-Law (Gamma) Transformations
Basic form is s = c r


where c and : positive constants
Transformation maps a narrow range of dark input values into a
wider ranger of output values, with the opposite being true for
higher value of input levels
Family of possible transformation curves obtained simply by
varying
Identity transformation when: c = = 1
Gamma correction: for displaying an image accurately on a
computer screen
Too dark
Washed out
Image transformation
Image enhancement
Image transformation
pixel point processing
Intensity transformation with unknown image information
Intensity transformation with histogram information.
spatial filtering

Histogram Equalization
A fully automatic gray-level stretching technique.







Need to talk about image histograms first ...

Image Histograms
An image histogram is a plot of the gray-level frequencies (i.e.,
the number of pixels in the image that have that gray level).

Image Histograms (contd)
Divide frequencies by total number of pixels to represent
as probabilities.

N n p
k k
/ =
Image Histograms (contd)
Properties of Image Histograms
Histograms clustered at the low end correspond to dark images.
Histograms clustered at the high end correspond to bright
images.
Properties of Image Histograms (contd)
Histograms with small spread correspond to low contrast
images (i.e., mostly dark, mostly bright, or mostly gray).
Histograms with wide spread correspond to high contrast
images.
Properties of Image Histograms (contd)
Low contrast High contrast
Histogram Equalization
The main idea is to redistribute the gray-level values uniformly.







Histogram Equalization (contd)
In practice, the equalized histogram might not be completely
flat.







Probability - Definitions
Random experiment: an experiment whose result is not
certain in advance (e.g., throwing a die)

Outcome: the result of a random experiment

Sample space: the set of all possible outcomes (e.g.,
{1,2,3,4,5,6})

Event: a subset of the sample space (e.g., obtain an odd
number in the experiment of throwing a die = {1,3,5})
Random Variables - Review
A function that assigns a real number to random experiment
outcomes (i.e., helps to reduce space of possible outcomes)
X(j)
X: # of heads
Random Variables - Example
Consider the experiment of throwing a pair of dice
Define the r.v. X=sum of dice
X=x corresponds to the event
Probability density function
The probability density function (pdf) is a real-valued function
f
X
(x) describing the density of probability at each point in the
sample space.






In the discrete case, this is just a histogram!






Gaussian
Probability distribution function
The integral of f
X
(x) defines the probability distribution function
F
X
(x) (i.e., cumulative probability)





In the discrete case, simply take the sum:
f
X
(x) F
X
(x)
Gaussian
f
X
(a)da

non-decreasing
Probability distribution function (contd)
Uniform Distribution
f
X
(x)
F
X
(x)
Random Variable Transformations
Suppose Y=T(X)
e.g., Y=X+1

If we know f
X
(x), can we find f
Y
(y)?

Yes; it can be shown that:

Transformations of r.v. - Example
=0, =1
=1, =1
0
Special transformation!
1 1
( ) ( )
1
( ) [ ( ) ] [ ( ) ] 1
( )
Y X X
x T y x T y
X
dX
f y f x f x
dY f x

= =
= = =
Proof:
Histogram Equalization (contd)
for PGM images, L=256, k=0,1,2, , 255, r
k
=k/(L-1)=k/255
Histogram Equalization (contd)
then, de-normalize:
s
k
x (L-1)
Histogram Equalization Example
3 bit
64 x 64 image
input histogram
equalized histogram
Histogram Equalization Examples
equalized images and histograms original images and histograms
Histogram matching
The desired shape of histogram is specified (not
necessarily uniform)
Derivation of histogram matching function:

s
uniform
r
input
z
desired
s=T(r)
histogram
equalization
s=G(z)
z=G
-1
(s)
z=G
-1
(T(r))
histogram
equalization
Histogram Matching

To generate a processed image that has a specified
histogram. (pz(z) is the specified probability density
function)

Implementation
Inverse
function
of G
Histogram Specification Example
3 bit
64 x 64 image
specified histogram
actual histogram
input histogram
Histogram Statistics
1
0
( ) ( ) ( )
L
n
n i i
i
r r m p r

=
=

1
0
( )
L
i i
i
m r p r

=
=

1 1
0 0
1
( , )
M N
x y
f x y
MN

= =
=

1
2 2
2
0
( ) ( ) ( )
L
i i
i
r r m p r o

=
= =

| |
1 1
2
0 0
1
( , )
M N
x y
f x y m
MN

= =
=

n-th moment
around mean
Variance
(2
nd
moment)
Useful for estimating image contrast!
Mean
(average intensity)
Example: Comparison of Standard Deviation
Values
31.6 o = 49.2 o =
14.3 o =
Local Histogram Statistics
1
2 2
0
Local variance
( ) ( )
xy xy xy
L
s i s s i
i
r m p r o

=
=

1
0
Local average intensity
( )
denotes a neighborhood
xy xy
L
s i s i
i
xy
m r p r
s

=
=

Using Histogram Statistics


for Image Enhancement
Useful when parts of the image might contain hidden
features.

Task: enhance dark
areas without changing
bright areas.

Idea: Find dark, low contrast
areas using local statistics.
Using Histogram Statistics
for Image Enhancement: Example
0 1 2
0 1 2
( , ), if and
( , )
( , ), otherwise
: global mean; : global standard deviation
0.4; 0.02; 0.4; 4
xy xy
s G G s G
G G
E f x y m k m k k
g x y
f x y
m
k k k E
o o o
o
s s s

= = = =
Image transformation
Image enhancement
Image transformation
pixel point processing
Intensity transformation with unknown image information
Intensity transformation with histogram information.
spatial filtering

Chapter 3
Image Enhancement in the
Spatial Domain

Enhancement Using
Arithmetic/Logic Operations
1. Arithmetic/logic operations involving images
are performed on a pixel-by-pixel basis
between two or more images (this excludes the
logic operation NOT, which is performed on a
single image).
2. The AND and OR operations are used for
masking: that is for selecting subimages in an
image.
3. Image multiplication finds use in enhancement
primarily as a masking operation that is more
general than the logical masks, since it can
implement gray-level rather than binary masks.



Chapter 3
Image Enhancement in the
Spatial Domain

Chapter 3
Image Enhancement in the
Spatial Domain
Image Subtraction
1. The difference between two images f(x, y) and h(x,y) is expressed as
g(x. y) = f(x. y) - h(x,y) .
2. The key usefulness of subtraction is the enhancement of differences
between images.
3. higher-order bit planes of an image carry a significant amount of visually relevant detail,
while the lower planes contribute more to fine (often imperceptible) details. If these lower
planes are extracted out , by subtracting the higher-order bit planes image form the original
image . Then we can enhance these fine details of the image.
4. we note also that change detection via image subtraction
finds another major application in the area of segmentation. Basically, segmentation
techniques attempt to subdivide an image into regions based on a specified criterion. Image
subtraction for segmentation is used when the criterion is "changes." For instance, in tracking
(segmenting) moving vehicles in a sequence of images, subtraction is used to remove
all stationary components in an image. What is left should be the moving elements
in the image, plus noise.

Chapter 3
Image Enhancement in the
Spatial Domain
Chapter 3
Image Enhancement in the
Spatial Domain
Image Averaging
1- Consider a noisy image g(x, y ) formed by the addition of noise (x, y) to an
original image f(x, y); that is,
g(x,y) = f(x,y) + (x,y)
2- The assumption is that at every pair of coordinates (x, y) the noise is uncorrelated,and
has zero average value.
E((x,y,t)* (x,y,t+))=0 ; for 0; = for =0.
E((x,y,t))=0.
3- The objective of the Averaging procedure is to reduce the noise content by adding a set
of noisy images, {gi( x, y)}. If the noise satisfies the constraints just stated, if an image
(x, y) is formed by averaging K different noisy images,then






Chapter 3
Image Enhancement in the
Spatial Domain
Then it follows that
E{ (x, y)} = f(x, y)
And





As K increases, indicates that the variability (noise) of the
pixel values at each location (x, y) decreases, and hence E{g(x,
y)} f(x, y). This means that (x, y) approaches f(x, y) as the
number of noisy images used in the averaging process
increases.



Chapter 3
Image Enhancement in the
Spatial Domain

Chapter 3
Image Enhancement in the
Spatial Domain
Spatial Filtering
1- Filtering is neighborhood operations work with the values of the image pixels in the neighborhood
and the corresponding values of a subimage that has the same dimensions as the neighborhood.
2- The subimage is called a filter, mask,kernel, template, or window, the first three terms being the
most prevalent terminology. The values in a filter subimage are referred to as coefficients, rather
than pixels.
3- The process consists simply of moving the filter mask from point to point in an image.
4- Spatial filters categorized in to two groups linear spatial filtering and non linear spatial filtering .
5- For linear spatial 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.
6- In general, linear filtering of an image f of size M X N with a filter wmask of size m X n is given by
the expression:


a = (m - 1)/2 and b = (n -1 )/2.
To generate a complete filtered image this equation must be applied for x = 0,1,2,.. , M - 1 and y = 0, 1,2,
.... N - 1.From the above equation m &n are odd numbers.
Chapter 3
Image Enhancement in the
Spatial Domain
With the previous approach, there will be bands of pixels
near the border that will have been processed with a partial
filter mask.
Other approaches include "padding" the image by adding
rows and columns of O's (or other constant gray level), or
padding by replicating rows and columns,or Mirroring .
The padding is then stripped off at the end of the process.
This keeps the size of the filtered image the same as the
original. but the values of the padding will have an effect
near the edges that becomes more prevalentas the size of
the mask increases.
Chapter 3
Image Enhancement in the
Spatial Domain
Chapter 3
Image Enhancement in the
Spatial Domain
Smoothing Spatial Filters
1- 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 (large) object extraction.And bridging of small gaps in lines or curves.
Noise reduction can be accomplished by blurring with a linear filter and also
by nonlinear filtering.
2- 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.
3- This process results in an image with reduced "sharp" transitions in gray levels. Because
random noise typically consists of sharp transitions in gray levels. the most obvious
application of smoothing is noise reduction. However edges (which almost always are
desirable features of an image) also are characterized by sharp transitions in gray levels.
So averaging filters have the undesirable side effect that they blur edges.
Chapter 3
Image Enhancement in the
Spatial Domain
1- Another application of this type of process includes the smoothing of false contours that
result from using an insufficient number of gray levels

2- A major use of averaging filters is in the reduction of "irrelevant" detail in an image. By
"irrelevant" we mean pixel regions that are small with respect to the size of the filter mask.

3- The averaging scheme deployed here can be the conventional one (summing and divide by
the number of entities) or using a weight to each individual pixel targeted by the MASK .
4- The general implementation for filtering an Mx N image with a weighted averaging filter of
size mX n (m and nodd) is given by the expression:





5- From the expression smoothing filters are linear spatial filters.

Chapter 3
Image Enhancement in the
Spatial Domain
As mentioned earlier, an important application of spatial averaging is to blure the image for
the purpose getting a gross representation of objects of interest, such that the intensity of
smaller objects blends with the background and larger objects become "bloblike" and easy to
detect. The size of the mask establishes the relative size of the objects that will be blended
with the
Background.
Chapter 3
Image Enhancement in the
Spatial Domain
Non Linear Spatial Filter
1- Nonlinear spatial filters also operate on neighborhoods, and the mechanics of sliding a mask
past an image are the same as was just outlined. In general, however, the filtering operation is
based conditionally on the values of the pixels in the neighborhood under consideration, and
they do not explicitly use coefficients in the sum-of-products manner described.
2- 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. Then replacing
the value of the center pixel with the value determined by the ranking result.
3- Median filters are Order-statistics filters replaces the value of the centre pixel value with
the Median of the gray levels in the neighborhood of that pixel and the pixel. Median filters
are quite popular because for certain types of random noise. They proivde excellent
noise-reduction capabilities, with considerably less blurring than linear smoothing filters of
similar size. Median filters arce particularlv effective in the presence of impulse noise also
called salt-And-pepper Noise because of its appearance as white and black dots superimposed
on an image.
4- In fact, isolated clusters of pixels that are light or dark with respect to their neighbors, and
whose area is less than n^2/2 (one-half the filter area), are eliminated by an n X n median
filter.


Chapter 3
Image Enhancement in the
Spatial Domain

Chapter 3
Image Enhancement in the
Spatial Domain
Sharpening Spatial Filters
1- 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
a natural effect of a particular method of image acquisition.
2- Sharpening could be accomplished by spatial differentiation.
Fundamentally, the strength of the response of a derivative operator
is proportional to the degree of discontinuity of the image at the
point at which the operator is applied. Thus, image differentiation
enhances edges and other discontinuities (such as noise) and
deemphasizes areas with slowly varying gray-level values
Chapter 3
Image Enhancement in the
Spatial Domain
The derivatives of a digital function are defined in terms of
differences. There are various ways to define these differences.
However, we require that and definition we use for a first derivative
(1) must be zero in flat segments (areas of constant gray-level
values); (2) must be nonzero at the onset of a gray-level step or
ramp; and (3) must be nonzero along ramps. Similarly, any
definition of a second derivative (1) must be zero in flat areas; (2)
must be nonzero at the
onset and end of a gray-level step or ramp; and (3) must be zero
along ramps of constant slope. Since we are dealing with digital
quantities whose values are finite, the maximum possible gray-level
change also is finite, and the shortest distance over which that
change can occur is between adjacent pixels.
Chapter 3
Image Enhancement in the
Spatial Domain
1- A basic definition of the first-order derivative of a one-dimensional function
f(x) is the difference:



Similarly, we define a second-order derivative as the difference:



2- It is easily verified that these two definitions satisfy the conditions stated previously
regarding derivatives of the first and second order.
3- In summary. comparing the response between first- and second-order derivatives. we arrive
at the following conclusions. (l) First -order derivatives generally produce thicker edges in an
image. (2) Second-order derivatives have a stronger response to fine detail , such as thin lines
and isolated points. (3) First-order derivatives generally have a stronger response to a gray-
level step. (4) Second-order derivatives produce a double response at step changes in gray
level. We also note of second-order derivatives that for similar changes in gray-level values in
an image. Their response is stronger to a line than to a step. and to a point than to a line.

Chapter 3
Image Enhancement in the
Spatial Domain
Chapter 3
Image Enhancement in the
Spatial Domain
The Laplacian
1- The simplest isotropic derivative operator is the Laplacian, which, for a function
(image)f(x,y)of two variables, is defined as:


2- The digital implementation of the two-dimensional Laplacian with recalling the previous
definition of the second derivatitor, and obtained by summing these two components:

Which gives an isotropic result for rotations in increments of 90 deg.
3- The diagonal directions can be incorporated in the definition of the digital Laplacian by adding
two more terms , one for each of the two diagonal directions . The total subtracted from the
difference terms now would be -8f(x, y).
4- Because the Laplacian is a derivative operator. Its use highlights gray-level discontinuities in
an image and deemphasizes regions with slowly varying gray levels. This will tend to produce
images that have grayish edge lines and other discontinuities all superimposed on a dark.
featureless background.




Chapter 3
Image Enhancement in the
Spatial Domain
Chapter 3
Image Enhancement in the
Spatial Domain
The basic way in which we use the Laplacian for image enhancement is as follows:
g(x,y)= if the center coefficient of the Laplacian mask is negative.
g(x,y)= if the center coefficient of the Laplacian mask is positive.





Chapter 3
Image Enhancement in the
Spatial Domain
1- Other way of generating a sharpened Immage as laplacian is
to subtract a blurred image version from the original .
)
2- A slight further generalization of sharpping is called high-
boost filtering. A high-boost filtered image is defined at any
point (x, y) as:
g(x,y)=A if the center coefficient of the Laplacian
mask is negative.
g(x,y)= A if the center coefficient of the Laplacian
mask is positive.
If A is large enough, the high-boost image will be
approximately equal to the original image multiplied by a
constant.









Chapter 3
Image Enhancement in the
Spatial Domain
Questions???!
References
R.C.Gonzalez, R.E.Woods. 2002. Digital Image Processing. 2nd
Edition. s.l. : Prentice Hall, 2002.
http://www.imageprocessingplace.com/downloads_V3/dip3e_downl
oads/dip3e_classroom_presentations/DIP3E_CH03_Art_PowerPoint
.zip
http://www.cse.unr.edu/~bebis/CS474/Lectures/IntensityTransforma
tions.ppt
www.kau.edu.sa/GetFile.aspx?id=94771&fn=CS482_3.ppt
ebookbrowse.com/3-digital-image-processing-ppt-d178445572
moodle.ncnu.edu.tw/mod/resource/view.php?id=88282
http://www.cs.bgu.ac.il/~klara/ATCS111/Intensity%20Transformati
on%20and%20Spatial%20Filtering%20-
Gonzales%20Chapter%203.1-3.3.ppt

Das könnte Ihnen auch gefallen