Digital Image Processing_Unit 2_ASRao
Digital Image Processing_Unit 2_ASRao
Frequency Domain :
Techniques are based on modifying the Fourier transform of
an image
Combination Methods:
There are some enhancement techniques based on various
combinations of methods from the first two categories.
Enhancement Techniques
x x
where g(x,y) is the output digital image, f(x,y) is the input digital
image, and M is the mapping function.
The value of pixels, before and after processing, will be denoted by r and
s, respectively. These values are related by the expression of the form:
s = T(r)
where T is a transformation that maps a pixel value
r into a pixel value s.
Figure: Some basic gray-level transformation functions used for Image
Enhancement
The three basic types of functions used frequently for image
enhancement:
Linear Functions:
Negative Transformation (s=L-1-r)
Identity Transformation (s=r)
Logarithmic Functions: (we can compress or expand the gray levels)
Log Transformation (s=C log(1+r) C= Constant (scaling factor)
Inverse-log Transformation
Power-Law Functions:
nth power Transformation
nth root Transformation
Linear Functions
Identity Function
Its expression: s = r
Image Negatives (Negative Transformation)
The negative of an image with gray level in the range [0, L-1], where L is
the largest value in an image, is obtained by using the negative
transformation’s expression:
s = L-1-r
Application: To enhance the visibility for images with more dark portion.
L o g a r i t h m i c Tr a n s f o r m a t i o n s
Log Transformation
The general form of the log transformation:
s = c log (1+r)
Log curve maps a narrow range of low gray-level values in the input
image into a wider range of the output levels.
Applications
This transformation is suitable for the case when the dynamic
range of a processed image far exceeds the capability of the
display device (e.g. display of the Fourier spectrum of an
image.
ASRao 27
FIGURE 3.7 (a) Intensity ramp image. (b) Image as viewed on a simulated
monitor with a gamma of 2.5. (c) Gamma corrected image. (d) Corrected
image as viewed on the same monitor.
In addition to gamma
correction, power-law
transformations are useful
for general purpose contrast
manipulation.
FIGURE 3.8
(a) Magnetic resonance
image (MRI) of a fractured
human spine (the region of
the fracture is enclosed by
the circle).
- Contrast Stretching
- Gray-level Slicing
- Bit-plane Slicing
Contrast Stretching
One of the simplest piecewise linear functions is a contrast-stretching
transformation, which is used to enhance the low contrast images.
ASRao 34
FIGURE 3.10
Contrast stretching.
(a) Piecewise linear
transformation
function.
(b) A low contrast
Electron microscope
image of pollen,
magnified 700 times.
(c) Result of contrast
stretching.
(d) Result of
thresholding.
ASRao 35
Figure 3.10 (a) shows a typical transformation used for contrast
stretching. The locations of points (r1, s1) and (r2, s2) control the shape
of the transformation function.
Intermediate values of (r1, s1) and (r2, s2) produce various degrees of
spread gray levels of the output image, thus affecting its contrast.
ASRao 36
Figure 3.10 (c) shows the result of contrast stretching, obtained by
setting (r1, s1) = (rmin, 0) and (r2, s2 = (rmax, L-1) where rmin and rmax
denote the minimum and maximum gray levels in the image,
respectively. Thus, the transformation function stretched the levels
linearly from their original range to the full range [0, L-1]
Finally Figure 3.10 (d) shows the result of using the thresholding
function defined previously, with r1 = r2= m, the mean gray level in the
image.
ASRao 37
Gray-Level Slicing (or) Intensity -Level Slicing
It can be implemented in several ways, but the two basic themes are:
One approach is to display a high value for all gray levels in the
range of interest and a low value for all other gray levels.
The second approach, based on the transformation brightens the
desired range of gray levels but preserves gray levels unchanged.
ASRao 38
Highlighting a specific range of intensities in an image.
ASRao 39
FIGURE (a) This
transformation
function
highlights range
[A,B] and reduces
all other intensities
to a lower level.
(b) This function
highlights range
[A,B] and leaves
other intensities
unchanged.
(c) An image
(d) Result of using the
transformation in (a)
ASRao 40
Gray-level Slicing: approach 1
ASRao 41
Gray-level Slicing: approach 2
Example: apply intensity level slicing in Matlab to read cameraman image ,
then If the pixel intensity in the old image is between (100 200) convert
it in the new image into 255 (white). Otherwise it leaves it the same.
ASRao 42
Bit-Plane Slicing
Remember that
pixels are
digital numbers
composed of
bits.
Separating a digital image into its bit planes is useful for analyzing the
relative importance played by each bit of the image.
ASRao 45
ASRao 46
Figure: (a) An 8-bit gray-scale image of size 500 X 1192 pixels. (b) through (i)
Bit planes through 8, with bit plane 1 corresponding to the least significant
bit. Each bit-plane is a binary image.
ASRao 47
ASRao 48
An image histogram is a graphical representation between number of
pixels and intensity value. It plots the number of pixels vs each
intensity value.
ASRao 49
Why Image Histogram?
ASRao 50
175 255 65 0
255 65 0 65
65 0 65 255
0 65 255 175
ASRao 51
ASRao 52
Examples: Image Histogram
ASRao 53
ASRao 54
ASRao 55
Let us see gray level images which are dark, light, low-contrast and
high-contrast and its corresponding histograms.
For a dark image, histogram is on the low (dark) side of gray scale.
For a bright image, histogram is biased towards high side of gray scale.
ASRao 56
The histogram of a digital image with gray levels from 0 to L-1 is a
discrete function
h( r k ) nk
Normalized Histogram
ASRao 58
Contrast Stretch
Commercial digital video cameras for home and professional, use a full-
scale histogram stretch to the acquired image, before stored in camera
memory.
ASRao 59
ASRao 60
ASRao 61
ASRao 62
ASRao 63
ASRao 64
Histogram Equalization
Image enhancement
Applications Contrast adjustment
Medical imaging
ASRao 65
Histogram provides a global description of the appearance of the
image.
ASRao 66
The Histogram Equalization is an approach to enhance a given image.
The approach is to design a transform T(.) such that gray values in the
output is uniformly distribution 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.
ASRao 67
Histogram Equalization (Idea)
Idea: Apply a monotone transform resulting in an approximately uniform
histogram
ASRao 69
How does it work?
nk
pin (rk ) 0 rk 1 0 k L 1
n
k
sk T (rk ) pin (r j ) 0 k L 1
j 0
ASRao 71
ASRao 72
ASRao 73
Example: Histogram Equalization?
Normal Normalized
k nk rk P(rk) = nk/n
0 790 0 0.19
S
1 1023 1/7 0.25
T
E 2 850 2/7 0.21
P 3 656 3/7 0.16
1
s1 T (r1 ) pin (r j ) pin (r0 ) pin (r1 )
j 0
2
s2 T (r2 ) pin (r j ) pin (r0 ) pin (r1 ) pin (r2 )
j 0
3
s3 T (r3 ) pin (r j ) pin (r0 ) pin (r1 ) ... pin (r3 )
j 0
ASRao 75
4
s4 T (r4 ) pin (r j ) pin (r0 ) pin (r1 ) ..... pin (r4 )
j 0
5
s5 T (r5 ) pin (r j ) pin (r0 ) pin (r1 ) .... pin (r5 )
j 0
6
s6 T (r6 ) pin (r j ) pin (r0 ) pin (r1 ) .... pin (r6 )
j 0
7
s7 T (r7 ) pin (r j ) pin (r0 ) pin (r1 ) .... pin (r7 )
j 0
ASRao 76
Input Image Histogram Equalized Output Image Histogram
ASRao 77
Comments:
ASRao 78
ASRao 79
ASRao 80
Histogram Matching
Image normalization
Applications Object recognition
Quality control
ASRao 81
Histogram equalization automatically determines a transformation
function that seeks to produce an output image that has a uniform
histogram.
In fact, one has to specify the shape of the histogram that we want the
processed image to have.
ASRao 82
Approach of derivation
ASRao 83
Histogram Specification Procedure:
(1) Compute the histogram pr(r) of the given image, and use it to find the
histogram equalization transformation in equation
k nj
sk T ( rk ) ( L 1) , k 0,1, 2, ...., L 1
j 0 MN
And round the resulting values to the integer range [0, L-1].
(3) For every value of sk, k=0, 1, …., L-1, use the stored values of G to find
the corresponding value of zq so that G(zq) is closer to sk and store these
mappings form s to z.
ASRao 84
(4) Form the histogram-specified image by first histogram-equalizing the
input image and then mapping every equalized pixel value, sk, of this
image to the corresponding value zq in the histogram-specified image
using the mappings found in step 3.
ASRao 85
Figure: (a) Histogram of a 3-bit image. (b) Specified histogram. (c)
transformation function obtained from obtained from the specified
histogram. (d) Result of performing histogram specification. Compare (b)
ASRao 86
and (d)
zq Specified pz(zq) Actual pz(zk)
Z0 = 0 0.00 0.00
Z1 = 1 0.00 0.00
Z2 = 2 0.00 0.00
Z3 = 3 0.15 0.19
Z4 = 4 0.20 0.25
Z5 = 5 0.30 0.21
Z6 = 6 0.20 0.24
Z7 = 7 0.15 0.11
ASRao 91
Key Differences between Histogram Equalization & Histogram Matching
ASRao 92
ASRao 93
Histogram Processing methods discussed in the previous two sections
are Global, in the sense that pixels are modified by a transformation
function based on the intensity distribution of an entire image.
This function is finally used to map the intensity of the pixel centered
in the neighborhood.
ASRao 95
ASRao 96
ASRao 97
Using Histogram Statistics for Image Enhancement
The statistics obtained from an image histogram are used for image
enhancement.
Let r denote a discrete random variable in the image (0, L-1) and P(r)
be the normalized histogram corresponding to r.
L 1
n (r ) (ri m) n p(ri )
i 0
L 1
m ri p (ri )
i 0
ASRao 98
The intensity variance is given by
L 1
u2 (r ) (ri m) 2 p(ri )
2
i 0
We can directly estimate the mean & variance without computing the
histogram.
1 M 1 N 1
m f ( x, y )
MN x 0 y 0
1 M 1 N 1
2
f ( x , y ) m 2
MN x 0 y 0
for x 0,1,2,...., M 1 and y 0,1,2,...., N 1
ASRao 99
Let (x, y) denote the coordinates of any pixel in a given image, and let
Sxy denote a neighborhood of specified size, centered on (x, y).
ASRao 100
Histogram Statistics - Example
0 0 1 1 2
1 2 3 0 1
3 3 2 2 0
2 3 1 0 0
1 1 3 2 2
The pixels are represented by 2 bits; therefore, L=4 and the intenisity
levels are in the range [0, 3].
ASRao 101
Case 1: When histogram of image is known
6 7
p (r0 ) 0.24; p (r1 ) 0.28;
5 25
7 5
p (r2 ) 0.28; p (r3 ) 0.20;
25 25
3
m ri p (ri )
i 0
(0)(o.24) (1)(0.28) (2)(0.28) (3)(0.20)
1.44
ASRao 102
Case 2: When histogram of image is not known
1 M 1 N 1
m f ( x, y )
MN x 0 y 0
1 4 4
m f ( x, y )
25 x 0 y 0
1
0(6) 1(7) 2(7) 3(5)
25
1.44
ASRao 103
ASRao 104
Local or Neighborhood Criterion
ASRao 105
Local or Neighborhood Criteria refers to the process of examining and
manipulating image pixels within a specified neighborhood or window,
considering the spatial relationships and interactions among adjacent
pixels.
Key Aspects
1. Window Size: Defines the neighborhood's dimensions (e.g., 3x3, 5x5).
2. Neighbor Pixels: Pixels surrounding the center pixel within the window.
3. Weighting: Assigning importance to neighbor pixels (e.g., equal,
Gaussian).
4. Operations: Various image processing techniques applied within the
window.
ASRao 106
Applications
1. Image Filtering: Smoothing, sharpening, edge detection.
2. Image Enhancement: Contrast adjustment, noise reduction.
3. Image Segmentation: Thresholding, edge detection.
4. Image Restoration: Noise removal, deblurring.
Neighborhood Operations
1. Averaging: Average neighbor pixel values.
2. Median: Median of neighbor pixel values.
3. Mode: Most frequent neighbor pixel value.
4. Weighted Sum: Weighted sum of neighbor pixel values.
ASRao 107
Smoothing Filters
ASRao 108
ASRao 109
Fundamentals of Spatial Filtering
In the filtering process the filter mask is moved from point to point in
an image starting at one end. Then using a predefined relationship
the response of the filter at each point is calculated.
The filter mask may be 3X3 mask or
5X5 mask or to be 7X7 mask
ASRao 110
Mechanism of Spatial Filtering
This process shows
moving filter mask
point to point.
Mask Coefficients
ASRao 111
Spatial filtering is similar to neighborhood operation.
Output pixel value is determined from the pixels under the mask.
ASRao 112
The Approaches of Spatial Filtering
ASRao 113
ASRao 114
ASRao 115
ASRao 116
Types of Spatial Filters
There are two types of filters:
1. Linear Spatial Filter 2. Non-Linear Spatial Filter
ASRao 117
Linear Spatial Filtering
For Linear spatial filtering:
Result = sum of product of filter coefficient and the corresponding
image pixel.
a b
g ( x, y ) w( s, t ) f ( x s, y t )
s a t b
It is a simplified notation
R w1 z1 w2 z 2 ..... wmn z mn
mn
wi zi
i 1
ASRao 120
w1 w2 w3
w4 w5 w6
w7 w8 w9
For above 3 x 3 general Mask response at any point (x, y) in the image
is given by
R w1 z1 w2 z 2 ..... wmn z mn
mn
wi zi
i 1
ASRao 121
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.
Types of Smoothing Filtering
There are 2 way of smoothing spatial filters:
ASRao 122
Smoothing Linear Filters
These are also called as averaging filter (or) Mean filter (or) LPF
Linear spatial filter is simply the average of the pixels contained in the
neighborhood of the filter mask.
Drawback: It blur the edges of the image, which is the main feature in
an image.
ASRao 123
Two 3 X 3 Smoothing Linear Filters
1
X
25
a b
w( s, t ) f ( x s, y t )
s a t b
g ( x, y ) a b
w( s, t )
s a t b
x = 0, 1, 2, . . . . . ., M-1
y = 0, 1, 2, . . . . . ., N-1
ASRao 125
Example: 3 X 3 average
ASRao 126
Box Filters
A Box filter, also known as a Box blur or Average filter, is a simple linear
spatial filter used in image enhancement to smooth an image and
reduce noise.
A spatial averaging filter in which all the coefficients are equal, are
sometimes called as Box filter.
1
X
25
ASRao 127
Weighted Average Filter
Instead of averaging all the pixel values in the window, give the closer-
by pixels higher weighting, and far-away pixels lower weighting.
Note that the coefficient of this mask sum to one, so the image
brightness will be retained, and the coefficients are all positive, so it
will tend to blur the image.
This type of mean filter smoothens out local variations within an
image, so it essentially a low pass filter. So a low pass filter can be used
to attenuate image noise that is composed primarily of high frequency
components. ASRao 129
ASRao 130
Gaussian Filter
Gaussian filters are linear spatial filters used in image enhancement to
smooth an image, reduce noise, and preserve edges.
Gaussian filters are a class of linear smoothing filters with the weights
chosen according to the shape of Gaussian function. This is to ensure
that filter has one peak.
ASRao 132
Nonlinear Spatial Filtering (Smoothing Nonlinear Filters)
ASRao 133
Order – Statistics (Image Statistics Filters)
ASRao 134
Median Filter
Replaces the value of a pixel by the median of the gray level.
This is most popular for excellent noise reduction.
Provides less blurring.
Effective for Impulse noise (salt and pepper noise)
ASRao 135
Example:
5 5 6
Given the following 3X3 neighborhood
3 4 5
3 4 7
We first sort the value in order of size (3,3,4,4,5,5,5,6,7) ; then we
select the middle value , in this case it is 5. This 5 is then placed in
center location.
A median filter can use a neighborhood of any size, but 3X3, 5X5 and
7X7 are typical. Note that the output image must be written to a
separate image (a buffer); so that the results are not corrupted as this
process is performed. (The median filtering operation is performed on
an image by applying the sliding window concepts, similar to what is
done with convolution). ASRao 136
The window is overlaid on the upper left corner of the image, and the
median is determined. This value is put into the output image (buffer)
corresponding to the center location of the window. The window is then
slide one pixel over, and the process is repeated.
When the end of the row is reached, the window is slide back to the left
side of the image and down one row, and the process is repeated. This
process continues until the entire image has been processed.
ASRao 137
Note that the outer rows and columns are not replaced. In practice this
is usually not a problem due to the fact that the images are much larger
than the masks. And these “wasted” rows and columns are often filled
with zeros (or cropped off the image).
For example, with 3X3 mask, we lose one outer row and column, a 5X5
mask we lose two rows and columns. This is not visually significant for a
typical 256X256 or 512X512 images.
ASRao 138
No reduction in contrast across steps, since output values available
consist only of those present in the neighborhood (no averages).
The median is, in a sense, a more robust “average” than the mean, as
it is not affected by outliers (extreme values).
Since the output pixel value is one of the neighboring values, new
“unrealistic” values are not created near edges.
Since edges are minimally degraded, median filters can be applied
ASRao 139
repeatedly, if necessary.
The median filter is more expensive to compute than a smoothing
filter.
Averaging Filter Vs Median Filter Example
The maximum and minimum filters are two order filters that can be used
for elimination of salt- and-pepper noise.
Maximum filter: The highest value is assigned to the center pixel, which
is useful for finding the brightest point in an image.
The minimum filters works best for salt- type noise (High value), and the
maximum filters work best for pepper-type
ASRao noise. 141
For example we may find for certain type of pepper noise that selecting
the second highest values works better than selecting the maximum
value.
ASRao 142
Sharpening Filters
ASRao 143
Sharpening Spatial Filters
f
f ( x 1) f ( x)
x
ASRao 145
For a second order derivative
It must be zero in constant areas
It must be non-zero at the onset and end of intensity ramp or
step, and
It must be non-zero along ramps of constant slope.
2 f
f ( x 1) f ( x 1) 2 f ( x)
x 2
ASRao 146
FIGURE: (a) A section of a horizontal scan line from an image, showing
ramp and step edges, as well as constant segments. (b)Values of the scan
line and its derivatives.
ASRao 147
Example:
ASRao 148
Gray – Level Profile
ASRao 149
Derivative of Image Profile
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
the 1st order derivative.
ASRao 150
The Laplacian (2nd Order Derivative for Image Sharpening)
ASRao 152
The digital implementation of the 2D Laplacian is obtained by summing
2 components
2 f 2 f
f
2
x
2
2 y
2 f [ f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1)]
4 f ( x, y )
ASRao 153
Laplacian Masks
ASRao 154
ASRao 155
As Laplacian is a derivative operator, its use highlights intensity
discontinuities in an image and deemphasizes regions with slowly
varying intensity levels.
This will produce images that have grayish edge lines and other
discontinuities.
Implementation
f ( x, y ) 2 f ( x, y ) if the coefficient is negative
g ( x, y )
f ( x , y ) 2
f ( x, y ) if the coefficient is positive
f ( x, y ) f ( x, y )
g mask ( x, y )ASRao 157
Then we add a weighted portion of the mask back to the original image
g ( x, y ) f ( x, y ) k g mask ( x, y )
ASRao 158
f ( x, y )
f ( x, y )
g mask ( x, y )
g ( x, y )
ASRao 159
First – Order Derivatives (Nonlinear) Image Sharpening
First derivatives in image processing are implemented using the
magnitude of the gradient. For a function f(x, y), the gradient of f at
coordinates (x, y) is defined as the two-dimensional column vector.
f
G x x
f Grad ( f )
G y f
y
This vector has the important geometrical property that it points in the
direction of the greatest rate of change of f at location (x. y).
ASRao 160
f f
Gradient direction: tan 1 ,
y x
is the value at (x, y) of the rate of change in the direction of the gradient
vector. Note that M(x, y) is an image of the same size as the original,
created when x and y are allowed to vary over all pixel locations in f. it is
common practice to refer to this image as the gradient image (or simply
as the gradient). Gx
This mask is simple, and
no isotropic. It result only
Gy
horizontal and vertical.
ASRao 163
Three important operators are used to compute the gradient.
Robert Cross Gradient operator
Prewitt operator
Sobel operator
ASRao 164
Robert Crossbar Gradient operator
ASRao 165
Prewitt Operator
ASRao 166
Sobel Operator
It is the difference between 3rd and 1st row approximates the derivative
in the x-direction.
The difference between 3rd and 1st column approximates the derivative
in the y-direction.
ASRao 167
ASRao 168
In the spatial domain in image processing, every element of the matrix
deals with the intensity of the pixels. This aspect of 2D matrices
denotes the intensity distribution of the picture.
The frequency of the picture draws its focus on the rate of changes in
the pixels. Frequency domain definition dwells on the Fourier
transformation of the image. Moreover, the pixels’ rate changes.
Basic Steps for Filtering in the Frequency Domain
1. Multiply the input image by (1) x y to center the transform to u=M/2
and v=N/2 (if M and N are even numbers, then the shifted coordinates
will be integers).
Low pass filtered image would have less sharp detail than the original
image as the higher frequencies are removed. This image will appear
smoother than the original.
High Pass Filters
A filter that attenuates lower frequency and passes the high frequency
is called LPF of an image.
As low frequencies are removed a high pass filtered image would have
less gray level variations in smooth area. But the sharp gray level
details such as edges are emphasized. Therefor such an image will
appear sharper than the original image.
Smoothing Frequency-domain filters: Ideal Low Pass Filters
Image power circles
Result of Ideal LPF
Smoothing Frequency-domain filters: Butterworth LPF