0% found this document useful (0 votes)
11 views

Chapter 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Chapter 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 129

Digital Image Processing, 2nd ed. www.imageprocessingbook.

com

Objectives of Enhancement

r Process an image so that the result will be


more suitable than the original image for a
specific application.
r The suitableness is up to each application.
r A method which is quite useful for enhancing
an image may not necessarily be the best
approach for enhancing another images

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Background Infomation

r Spatial Domain : Techniques are based on direct manipulation of


pixels in an image
r Frequency Domain : Techniques are based on modifying the
Fourier transform of an image
r Good Images
Ø For human visual
ü The visual evaluation of image quality is a highly subjective process.
ü It is hard to standardize the definition of a good image.
Ø For machine perception
ü The evaluation task is easier.
ü A good image is one which gives the best machine recognition results.
r A certain amount of trial and error usually is required before a
particular image enhancement approach is selected.
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 3
Image Enhancement in the
Spatial Domain

Ø Procedures that operate directly on


pixels.
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 on f defined over
some neighborhood of ( x, y)
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Point Processing

§ Neighborhood = 1x1 pixel


§ g =depends on only the value of f at ( x, y)
§ T = gray level (or intensity or mapping)
transformation function

s = T (r )
§ Where
§ r =gray level of f ( x, y )
§ s=gray level of g ( x, y)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Contrast Stretching
and
Thresholding

ü (a) Produce higher contrast than the original by


ü darkening the levels below m in the original image
ü Brightening the levels above m in the orginal image
ü (b) Produce a two-level (binary) image

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

3 basic gray-level
transformation functions

Ø Linear function
Ø Negative and identity
transformation

Ø Logarithm function
Ø Log and inverse-log
transformation

Ø Power-low function
Additional Source:
Ø nth power and nth root https://www.tutorialspoint.com/dip/gray_lev
transformation el_transformations.htm
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Identity function

Ø Output intensities are


identical to input
intensities.
Ø Is included in the graph
only for completeness

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Negatives

Ø An image with gray level


in the range [0, L - 1]
where L = 2n ; n=1,2,…
Ø Negative transformation :
s = L -1- r
Ø Reversing the intensity
levels of an image.
Ø Suitable for enhancing
white or gray detail
embedded in dark regions
of an image, especially
when the black area
dominant in size.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example of Negative Image (1/2)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example of Negative Image (2/2)

Input Image Negative Image

Fig. : Negative transformation


© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Log Transformations

s = c log(1 + r )
Ø c is a contrast and r≥0
Ø Log curve maps a narrow
range of low gray-level
values in the input image
into a wider range of
output levels.
Ø Used to expand the values
of dark pixels in an image
while compressing the
Additional source: higher-level values.
https://www.geeksforgeeks.org/log-
transformation-of-an-image-using- If any pixel value is ‘0’ then its log value will
python-and-opencv/ become infinite. That’s 1 is added
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Examples of Logarithm Image (1/2)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Examples of Logarithm Image (2/2)

Input Image Logarithmic Image

Fig. : Negative transformation


© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Power-Law
Transformations/Gamma correction
γ < 1, nth root
γ > 1, nth power

s = cr g
Ø c and g are positive constants
Ø Power-low curves with fractional
values of r map a narrow range of
dark input values with the opposite
being true for higher values of input
levels.
Ø c= g =1 → Identity function

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Gamma correction

g =2.5

ü Gamma correction is
done by preprocessing
the image before
inputting it to the
1/ g
monitor with s = cr

g =1/2.5=4
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Another example : MRI

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Another example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Another example

Gamma (γ) = 10 Gamma (γ) = 8 Gamma (γ) = 6

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Piecewise-Linear
Transformation Functions

Ø Advantage :
Ø The form of piecewise function can be arbitrarily
complex
Ø Disadvantage:
Ø Their specification requires considerably more user
input

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

a b
Contrast Stretching (1/6) c d
ü Increase the dynamic range of
the gray levels in the image
ü (b) a low-contrast image: result
from poor illumination, lack of
dynamic range in the imaging
sensor, or even wrong setting of a
lens aperture of image acquisition
ü (c) result of contrast stretching
ü (d) result of thresholding

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Contrast Stretching (2/6)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Contrast Stretching (3/6)

r
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Contrast Stretching (4/6)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Contrast Stretching (6/6)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Gray-level slicing

ü Highlighting a specific range


of gray levels in an image

ü Display a high value of all


gray levels in the range of
interest and a low value of all
other gray levels

ü (a) transformation highlights


range [A,B] of gray level and
reduces all others to a contrast
level
ü (b) transformation highlights
range [A,B] but preserves all
other levels
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Bit-plane slicing

Ø Highlighting the contribution made to total image appearance by


specific bits
Ø Suppose each pixel is represented by 8bits
Ø Higher-order bits contain the majority of the visually significant data
Ø Useful for analyzing the relative important played by each bit of the
image

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

ü The(binary) image for


bit-plane 7 can be obtained
by processing the input
image with a thresholding
gray-level transformations.
ü Map all levels between 0
and 127 to 0
ü Map all levels between
129 and 255 to 255

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

8 bit planes

Bit-plane 7 Bit-plane 6

Bit- Bit- Bit-


plane 5 plane 4 plane 3
Bit- Bit- Bit-
plane 2 plane 1 plane 0

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Processing (1/3)


Ø Histogram of a digital image with gray levels in the
range [0, L-1] is a discrete function

h(rk ) = nk
Ø Where
Ø rk : the kth gray level
Ø nk : the number of pixels in the image having gray level rk
Øh(rk ) : histogram of digital image with gray levels

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Processing (2/3)

Fig: A gray image patch

Fig: Probability of each intensity level


© 2002 R. C. Gonzalez & R. E. Woods
Fig: The corresponding histogram
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Normalized Histogram

Ø Dividing each of histogram at gray level rk by the


total number of pixels in the image, n
p(rk ) = nk / n
for k=0,1,…,L-1
Ø p(rk ) gives an estimate of the probability of
occurrence of gray level rk

Ø The sum of all components of a normalized


histogram is equal to 1

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Processing (3/3)

Fig: A gray image patch

Fig: probability of each intensity level


© 2002 R. C. Gonzalez & R. E. Woods
Fig: The histogram probability
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Processing

Ø Basic for numerous spatial domain


processing techniques
Ø Used effectively for image enhancement
Ø Information inherent in histograms also is
useful in image compression and
segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com
h(rk )orp(rk )

Example
rk

ü Dark image
components of histogram
are concentrated on the low
side of the gray scale

ü Bright image
components of histogram
are concentrated on the high
side of the gray scale

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

ü Low-contrast image
histogram is narrow and
centered toward the middle of
the gray scale

ü High-contrast image
histogram covers broad
range of the gray scale and the
distribution of pixels is not too
far from uniform

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Transformation

s = T (r )
Ø Where 0 ≤ r ≤ 1
Ø T(r) satisfies
Ø T(r) is single-valued and
monotonically increasing in the
interval 0 ≤ r ≤ 1
Ø 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Conditions for T(r)

r Single-valued (one-to-one relationship) guarantees that


the inverse transformation will exist
r Monotonicity condition preserves the increasing order
from black to white in the output image thus it won’t
cause a negative image
r 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1 guarantees that the output gray
levels will be in the same range as the input levels.
r The inverse transformation from s back to r is
r = T -1(s) ; 0 ≤s ≤1

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Discrete Transformation
Function
r The probability of occurrence of gray level in an image is
approximated by

, where k = 0, 1, …, L-1

r The discrete version of transformation

, where k = 0, …, L-1

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Equalization
Ø As the low-contrast image’s histogram is narrow and
centered toward the middle of the gray scale, if we
distribute the histogram to a wider range, the quality
of the image will be improved.
Ø We can do it by adjusting the probability density
function of the original histogram of the image so that
the probability spread equality
Ø Equalization can be achieved by the following
transformation function

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example-Transformation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example-Result

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

ü Image is dominated by
large, dark areas,
resulting in a histogram
characterized by a large
concentration of pixels in
pixels in the dark end of
the gray scale

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Equalization

ü The histogram equalization doesn’t make the


result image look better than the original image.
Consider the histogram of the result image, the net
effect of this method is to map a very narrow interval
of dark pixels into the upper end of the gray scale of
the input image. As a consequence, the output image
is light and has a washed-out appearance.
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Specification

r Histogram equalization has a disadvantage which is


that it can generate only one type of output image.
r With Histogram Specification, we can specify the
shape of the histogram that we wish the output image
to have.
r It doesn’t have to be a uniform histogram

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Specification : Example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Equalization of Input Image

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Equalization of Target Image

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Mapping

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Note
§ Histogram specification is s trial-and-error
process
§ There are no rules for specifying histograms, and
one must resort to analysis on a case-by-case basis
for any given enhancement task.
§ Histograms processing methods are global
processing, in the sense that pixels are modified by
a transformation function based in the gray-level
content of an entire image.
§ Sometimes, we may need to enhance details over
small areas in an image, which in called a local
enhancement.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Local Enhancement

Ø define a square or rectangular neighborhood and move the center of this area
from pixel to pixel.
Ø at each location, the histogram of the points in the neighborhood is computed
and either histogram equalization or histogram specification transformation
function is obtained.
Ø another approach used to reduce computation is to utilize nonoverlapping
regions, but it usually produces an undesirable checkerboard effect.
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Specification
Histogram Equalization
Histogram Equalization
using Desired Histogram of
of input image, S.
output image, Z.

vk

zk
1 4 6 13 15 20 24 25 1 8 13 18 20 23 25 25
Accumulative distribution of input Accumulative distribution of output

- S à R’ mapping RßZ
- In continuous space, the two
-Construct LUT as follows: equalize images (R and R’)
+ Map rk to sk using T(r) should be the same.

+ Find vk , which is closest to sk


+ Compute zk using G-1(vk).
+ Repeat for all rk

LUT 0 0 1 2 2 4 5 6

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Histogram Specification
(1) the transformation
function G(z) obtained
from
k
G ( z k ) = å p z ( zi ) = s k
i =0

k = 0,1, 2,...L - 1
(2) the inverse
transformation G -1 ( s)

ü Notice that the output histogram’s


low end has shifted right toward the
lighter region of the gray scale as
desired.
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Enhancement using
Arithmetic/Logic Operations

Ø Arithmetic/Logic operations perform on pixel by


pixel basis between two or more images

Ø except NOT operation which perform only on a


single image

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Note
§ We may have to adjust the gray-scale of the
subtracted image to be [0,255] (if 8-bit is used)
§ first, find the minimum gray value of the subtracted
image
§ second, find the maximum gray value of the subtracted
image
§ Set the minimum value to be zero and the maximum to
be 255
§ We may also adjust the image as:
§ While the rest are adjusted according to the interval
[0,255], by timing each value with 255/max
§ Subtraction is used in segmentation of moving
pictures to track the changes
§ After subtract the sequenced images, what is left should
be the moving elements in the image, plus noise
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Addition
§ Useful for combining information between
two image

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Subtraction (1/5)

§ Useful for change detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Subtraction (2/5)

§ Useful for change detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Subtraction (3/5)

a b

Enhancement by
image subtraction.
(a) Mask image.
(b) An image with
mask subtracted
out.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Subtraction (5/5)

a b
c d

(a) original fractal


image. (b) Result of
setting the four lower-
order bit planes to zero.
(c)Difference between
(a) and (b). (d)
Histogram equalized
difference image.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Subtraction (4/4)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Multiplication/ Division (1/2)

§ Use to adjust brightness of the iamge

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Multiplication/ Division (2/2)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Logic Operations

Ø Logic operation performs on gray-level images, the


pixel values are processed as binary numbers

Ø light represents a binary 1, and dark represents a


binary 0

Ø NOT operation=negative transformation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example of AND/OR operation (1/2)

. =

+ =

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example of AND/OR operation (2/2)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Averaging

Image Averaging : consider an uncorrelated noise with zero


average value then:
K
1
g ( x, y ) =
K
å g ( x, y )
i =1
i

E{g ( x, y )} = f ( x, y )
1 2
s 2
g ( x, y ) = s h ( x, y )
K
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Averaging

Original K=1

K=8 K=16

K=64 K=128

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Image Averaging

K=8

K=16

K=64

K=128

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Spatial Filtering

Ø use filter (can also be called


as mask/kernel/template or
window)
Ø the values in a filter sub-
image are referred to as
coefficients, rather than pixel
Ø our focus will be on masks of
odd sizes, e.g. 3x3, 5x5,…
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Spatial Filtering Process


Ø Simply move 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.

R = w1 z1 + w2 z2 + ... + wmn zmn w1 w2 w3


mn w4 w5 w6
= å wi zi w7 w8 w9
i =1

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution

a b
g( x, y ) = å å ω( s,t ) f ( x - s, y - t )
s =- a t =- b

g = ω* f

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution

Convolution kernel, ω Input Image, f

1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
Rotate 180o 1 3 2 2
1 1 1
-1 2 1
-1 -1 1
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2
-1 4 2 2 3 5
Output
2 1
-1 -2 3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
-2
2 4
2 2 3 5 4
Output
2 -1
-2 1 3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 -2
2 4
2 3 5 4 4
Output
2 -1
1 -3
3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 2 -2
2 36 1 5 4 4 -2
Output
2 1 3 -3
-3 3 1 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2

1 2 2 2 3 5 4 4 -2
Output
-1 4
2 1 3 3 9 Image, g
-1 -2
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2

2 2 2 3 5 4 4 -2
Output
-2
2 2
1 3 3 9 6 Image, g

-2
2 -2
2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Convolution

5 4 4 -2
9 6 14 5
11 7 6 5
9 12 8 5
Final output Image, g

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation

a b
g( x, y ) = å å ω( s,t ) f ( x + s, y + t )
s =- a t =- b

g = ω f

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation

correlation kernel, ω

1 -1 -1
Input Image f
1 2 -1
2 2 2 3
1 1 1
2 1 3 3
Don’t rotate use it directly
2 2 1 2
1 3 2 2

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2

1 -1 -1 1 3 2 2

1 2 -2
4 2 2 3 5
1 2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 -2
4 2 3 5 10
2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 2 -3
4 3 5 10 10
2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 2 3
6 -1 5 10 10 15
2 1 3 3 1 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2

1 -2
2 -2
2 2 3 5 10 10 15
1 4
2 -1
1 3 3 3 output
Image, g
1 2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2

2 -2
2 -2
2 3 5 10 10 15
2 2
1 -3
3 3 3 4 output
Image, g
2 2 1 2
1 3 2 2

Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Correlation

5 10 10 15
3 4 6 11
7 11 4 9
-5 4 4 5
Final output Image, g

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Linear Filtering
Ø Linear Filtering of an image f of size M x N filter
mask of size m x n is defined as
$ &

𝑔 𝑥, 𝑦 = & & 𝑤 𝑠, 𝑡 𝑓(𝑥 + 𝑠, 𝑦 + 𝑡)


!"#$ %"#&

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Smoothing Spatial Filters


Ø 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
Ø bridging of small gaps in lines or curves
Ø Noise reduction can be accomplished by blurring
with a linear filter and also by a nonlinear filter

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Smoothing Linear Filters


Ø Output is simply the average of the pixels
contained in the neighborhood of the filter mask.
à called averaging filters or low-pass filters.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

3x3 Smoothing Linear Filters

Box filter Weighted Average Filter


The center pixel The center is the most
and neighbor important and other pixels
pixels are equally are inversely weighted as a
important function of their distance
from the center of the mask

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

General form : smoothing mask

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example: Smoothing Linear Filters

Original 3x3
Note:
ü Big mask is used to
eliminate small objects
from an image
5x5 9x9
ü The size of the mask
establishes that relative
size of the objects that
will be blended with the
background.
15x15 35x35

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example: Smoothing Linear Filters

original blurred thresholded

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Order-Statistics Filters
(Nonlinear Filters)
Ø The response is based on ordering (ranking) the
pixels contained in the image area encompassed by
the filter
Ø example
Ø median filter : R=median{Zk | k=1,2,…,nxn}
Ø max filter : R=max{Zk | k=1,2,…,nxn}
Ø min filter : R=min{Zk | k=1,2,…,nxn}
Ø note : nxn is the size of the mask

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Median Filters
Ø Replaces the value of a pixel by the median of the
gray levels in the neighborhood of that pixel ( the
original value of the pixel is included in the
computation of the median)
Ø Quite popular because for certain types of random
noise such as impulse noise(or salt and pepper
noise), they provide excellent noise-reduction
capabilities, with considering less blurring than linear
smoothing filters of similar size.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Median Filters
r Forces the points with distinct gray levels to be
more like their neighbors.
r Isolated clusters of pixels that are light or dark
with respect to their neighbors, and whose area
is less than one-half the filter area, are
eliminated by an n x n median filter.
r Forced to have the value equal the median
intensity of the neighbors.
r Larger clusters are affected considerably less
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example : Median Filters

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Sharpening Spatial Filters


Ø Sharpening: Highlight fine detail in an image and
enhance detail that has been blurred, either in error
or as a natural effect of a particular method of image
acquisition.
Ø Blurring vs. Sharpening: Blurring can be done in
spatial domain by pixel averaging in a neighbors.
Since averaging is analogous to integration, we can
guess that the sharpening must be accomplished by
spatial differentiation.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Derivative operator
Ø 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 (noise)
Ø deemphasizes area with slowly varying gray-level
values.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

First and second order derivative


Ø The first order derivative of an one-dimensional
function

Ø The second order derivative of an one-dimensional


function

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

First and Second-order


derivative of f(x,y)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Discrete Form of Laplacian

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Laplacian masks

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Effect of Laplacian Operator

Ø As a derivative operator,
§ it highlights gray-level discontinuities in an image
§ it deemphasizes regions with slowly varying gray levels
Ø Tends to produce images that have
§ grayish edge lines and other discontinuities,
§ all superimposed on a dark,
§ featureless background

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

If the center coefficient of


the L mask is negative

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Mask of Laplacian + addition


Ø To simply the computation, we can create a mask
which do both operations, Laplacian Filter and
Addition on the original image.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Sharpening

f s ( x, y) = f ( x, y) - f ( x, y)
High-pass image = original image – blurred image

Ø to subtract a blurred version of an image


produces sharpening output image.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

High-boost filtering

Ø High-pass filter at A=1


Ø High-boost filter at A ≥ 1,

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

High-boost filtering

Ø We use Laplacian filter to create sharpen


image fs(x,y) with addition of original image.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

High-boost Masks

• if A=1, becomes “standard” Laplacian


sharpening

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Gradient Operator

Ø First derivatives are implemented using the


magnitude of the gradient.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Gradient Mask

Ø simplest approximation, 2x2

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Gradient Mask

Ø Roberts cross-gradient operators, 2x2

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Gradient Mask
Ø Sobel operators, 3x3

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Note
§ The summation of coefficients in all
masks equals 0, which means that
they would give a response of 0 in an
area of constant gray level.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Edge Masks

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example of Combining Spatial


Enhancement Methods

Ø Want to sharpen the


original image and bring
out more skeletal detail.
Ø Problems : narrow
dynamic range of gray
level and high noise
content makes the
image difficult to
enhance

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Example of Combining Spatial


Enhancement Methods

Ø solution :
1. Laplacian to highlight fine detail
2. gradient to enhance prominent edges
3. gray-level transformation to increase the dynamic
range of gray levels

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Thank You

© 2002 R. C. Gonzalez & R. E. Woods

You might also like