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

Digital Image Processing_Unit 2_ASRao

Image enhancement improves image quality for specific applications through techniques like spatial and frequency domain methods. It includes pixel point processing, block processing, and various transformation functions such as contrast stretching and gray-level slicing. The document details different enhancement techniques and their applications, emphasizing the subjective nature of image enhancement based on the intended use.
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)
2 views

Digital Image Processing_Unit 2_ASRao

Image enhancement improves image quality for specific applications through techniques like spatial and frequency domain methods. It includes pixel point processing, block processing, and various transformation functions such as contrast stretching and gray-level slicing. The document details different enhancement techniques and their applications, emphasizing the subjective nature of image enhancement based on the intended use.
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/ 182

Image Enhancement: Introduction

 Image Enhancement is the process that improves the quality of the


image for a specific application.

 Image Enhancement is the process an image so that the result will be


more suitable than the original image for a specific application.
Normally referred as “Preprocessing”.

 The suitableness is up to each application.

 A method which is quite useful for enhancing an image may not


necessarily be the best approach for enhancing another images.

 Enhancement refers to accentuation, or sharpening, of image features


such as edges, boundaries, or contrast to make graphic display more
useful for display and analysis.
Image Enhancement Methods

 Spatial Domain : (Image plane)


 Techniques are based on direct manipulation of pixels in an
image

 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

Spatial Domain Frequency Domain


Operates on Pixels Operates on FT of Image

 Image Enhancement is subjective (Problem/Application oriented)


Types of Image Enhancement Operations – Pixel Point Processing

 Pixel point processing is a form of image enhancement based only on


the intensity of single pixels. No consideration what-so-ever is taken of
neighboring pixels, or the spatial arrangement of groups of pixels or the
position of the pixel within the digital image.

 Pixel point processing is a simple but important type of image


enhancement technique. All pixels are processed individually.
I(x,y) O(x,y)
y y

x x

 The general equation for a point process is given by:

where g(x,y) is the output digital image, f(x,y) is the input digital
image, and M is the mapping function.

M maps or converts input pixel brightness to an output pixel brightness.

The mapping function can be non-linear.


Types of Image Enhancement Operations – Block Processing

Local Operations The output value at (x,y) is dependent on the


input values in the neighborhood of (x,y)

Global Operations The output value at (x,y) is dependent on the


input values in the input image.
Spatial Domain Methods

The term Spatial Domain refers to the aggregate of pixels composing an


image.
Spatial domain methods are procedures that operate directly on these
pixels (Point Processing)
Spatial domain processes will be 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 and
T is an operator on f defined over some
neighborhood of (x,y)

Neighborhood about (x,y): a square or rectangular sub-image area


centered at (x,y)
In addition, T can operate on a set of input images.
Figure: A 3 × 3 neighborhood
about a point (x0,y0 ) in an image.
The neighborhood is moved from
pixel to pixel in the image to
generate an output image.

 The simplest form of T, is when the neighborhood of size 1X1 (that is a


single pixel). In this case, g depends only on the value of f at (x,y), and T
becomes a gray-level transformation function of the form:
s=T(r)
where, for simplicity in notation, r and s are variables denoting,
respectively, the gray level of f(x,y) and g(x,y) at any point (x,y)
Examples of Enhancement Techniques
Contrast Stretching:
 If T(r) has the form as in figure, the
effect of applying the transformation
to every pixel of f to generate the
corresponding pixels in g would:
 Produce higher contrast than the
original image, by:

 Darkening the levels below m in the original image.


 Brightening the levels above m in the original image.

 So, Contrast Stretching is a simple image enhancement technique that


improves the contrast in an image by ‘stretching’ the range of intensity
values it contains to span a desired range of values.
 Typically, it uses a linear function.
Thresholding:

 It is a limited case of Contrast


Stretching, it produces a two-level
(binary) image.

 The values below m are transformed


as black and above m are transformed
as white.

 Some fairly simple, yet powerful, processing approaches can be


formulated with gray-level transformations. Because enhancement at
any point in an image depends only on the gray level at that point,
techniques in this category often are referred to as point processing.
 Larger neighborhoods allow considerable more flexibility. The general
approach is to use a function of the values of f in a predefined
neighborhood of (x,y) to determine the value of g at (x,y).
 One of the principal approaches in this formulation is based on the use of
so-called masks (also referred to as filters)

 A mask/filter is a small (say 3X3) 2D


array, such as the one shown in the
figure, in which the values of the
mask coefficients determine the
nature of the process, such as image
sharpening.
 Enhancement techniques based on
this type of approach often are
referred to as mask processing or
filtering.
ASRao 14
Some Basic Intensity (Gray-level) Transformation Functions

 Gray-level transformation functions (also called Intensity functions), are


considered the simplest of all image enhancement techniques.

 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

 Output intensities are identical to input intensities

 This function doesn’t have an effect on an image.

 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

 which reverses the intensity levels of an image, in this manner


produces the equivalent of a photographic negative..

 The negative transformation is suitable for enhancing white or gray detail


embedded in dark regions of an image, especially when the black area
are dominated in size.

 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)

where c is a constant, and r ≥ 0

 Log curve maps a narrow range of low gray-level values in the input
image into a wider range of the output levels.

 Used to expand the values of dark pixels in an image while


compressing the higher-level values.

 Result high contrast image.


Fourier Spectrum Log transformation with c=1
 Properties of Log Transformations
 For lower amplitudes of input image the range of gray level is
expanded.
 For higher amplitudes of input image the range of gray level is
compressed.

 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.

 Also called “dynamic-range compression/expansion.


Inverse Logarithm Transformation

 Do opposite to the log transformations

 Used to expand the values of high pixels in an image while compressing


the darker-level values.

 Result low contrast image.


P o w e r - L a w Tr a n s f o r m a t i o n s
 Power-Law (Gamma) Transformations have the basic form of:

s = c rγ where c and γ are positive constants

 γ > 1: nth Power


 Γ < 1: nth Root

 Γ > 1: changes brighter to darker images


 γ < 1: changes darker to brighter images

 c = gamma = 1 means it is an identity transformations.

 Process used to correct these power law response phenomena is called


gamma correction.
Figure: Plots of the gamma equation s = c rγ for various values of g
(c = 1in all cases).
γ < 1: changes darker to
brighter images

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).

(b)–(d) Results of applying


the Transformation in Eq.
s = crγ with c = 1 and γ = 0 6 .
, 0.4, and 0.3, respectively.
(i.e. γ <1)
FIGURE 3.9
(a) Aerial image.
(b)–(d) Results of applying
the transformation in Eq.
s=crγ with g= 3.0, 4.0 and
5.0, respectively.
(c = 1 in all cases.)
ASRao 31
ASRao 32
P i e c e w i s e - L i n e a r Tr a n s f o r m a t i o n F u n c t i o n s
Principle: Rather than using a well defined mathematical function, we can
use arbitrary user defined transforms.

Advantage: Some important transformations can be formulated only as a


piecewise function..

Disadvantage: Their specification requires more user input than previous


transformations.

Types of Piecewise Transformations

- 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.

 Low contrast images may result from:


 Poor illumination
 Wrong setting of lens aperture during image acquisition..

 Darker portion becomes more darker.


 Lighter portion becomes more lighter.

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.

 If r1=s1 and r2=s2, the transformation is a linear function that produces


no changes in gray levels.

 If r1=s2, s1=0 and s2=L-I, the transformation becomes a thresholding


function that creates a binary image.

 Intermediate values of (r1, s1) and (r2, s2) produce various degrees of
spread gray levels of the output image, thus affecting its contrast.

 In general, r1 ≤ r2 and s1 ≤ s2 is assumed, so the function is always


increasing (monotonically) .

 Figure 3.10(b) shows an 8-bit image with low 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

 This technique is used to highlight a specific range of gray levels in a


given image. Similar to thresholding. Other levels can be suppressed or
maintained.

 Enhances features such as masses of water in satellite imagery and


enhancing flaws in X-ray images.

 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.

display in one value(e.g white) all Brightens or darkens the desired


the values in the range of interest , range of intensities but leaves all
and in another (e.g black) all other other intensity levels in the image
intensities unchanged

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

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 convert it to 0 (black).

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

 Pixels are digital numbers, each one composed of bits. Instead of


highlighting gray-level range, we could highlight the contribution made
by each bit.
 This method is useful and used in image compression.

Figure: Bit Plane representation of an 8-bit image

 Most significant bits contain the majority


ASRao of visually significant data 43
 8-bit image may be considered as being composed of eight 1-bit planes,
with plane 1 containing the lowest-order bit of all pixels, in the image
and plane 8 all the highest order bits.

Remember that
pixels are
digital numbers
composed of
bits.

8-bit Image composed of 8 1-bit planes

Figure: Bit-plane representation


ASRao of an 8-bit image 44
 Often by isolating particular bits of
the pixel values in an image we can
highlight interesting aspects of that
image

 Higher-order bits usually contain


most of the significant visual
information

 Lower-order bits contain subtle details

 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?

 Histograms are the basis for numerous spatial domain processing


techniques..

 Histograms manipulation can be used effectively for image


enhancement.

 Histograms can be used to provide useful image statistics.

 Information derived from histograms are quite useful in other image


processing applications, such as image compression and segmentation.

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.

 An image with low contrast has a histogram that is narrow and


centered toward the middle of the gray scale. This implies a dull,
washed-out gray look.

 An image whose pixels is occupying entire range of gray level and


distributed uniformly, has high contrast and show variety of gray
tones. Thus it has a high dynamic range.

ASRao 56
 The histogram of a digital image with gray levels from 0 to L-1 is a
discrete function
h( r k )  nk

where: rk is the kth gray level (intensity value)


nk is the no.of pixels in the image with that gray level rk
n is the total number of pixels in the image
k=0, 1, 2, ………., L-1

 Histogram manipulation can be used for image enhancement

 For practical applications, one has to normalize histogram by dividing


each of its values by the number of pixels in the image, n

 Thus 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.


ASRao 57
Draw the Image Histogram
rk 0 1 2 3 4 5 6 7
nk 7 10 6 5 3 0 3 2

Normalized Histogram

 It represents the normalized


number of pixels which is equal to
(Number of pixels/total number
of pixels).

ASRao 58
Contrast Stretch

 One of the simple techniques to expand the histogram to fill entire


gray-scale range is contrast stretch of full-scale histogram 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

Purpose Enhances contrast

Process Adjusts intensity distribution

Produces an image with uniform


Output
intensity spread

Image enhancement
Applications Contrast adjustment
Medical imaging

ASRao 65
 Histogram provides a global description of the appearance of the
image.

 It is one of the important nonlinear point operations. In this results are


similar to Contrast stretching but offer the advantage of full
automation.

 Since HE automatically determines a transformation function to


produce a new image with a uniform histogram.

 An image with a perfectly flat histogram contains largest possible


amount of information.

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.

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


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

ASRao 67
Histogram Equalization (Idea)
Idea: Apply a monotone transform resulting in an approximately uniform
histogram

FIGURE (a) Monotonically increasing function, showing how multiple values


can map to a single value. (b) Strictly monotonically increasing function. This
is a one-to-one mapping, both ways. ASRao 68
Conditions on T(r):

(1) T(r) is a monotonically increasing function for 0≤r≤1 (preserves order


from black to white)
(2) T(r) maps [0, 1] into [0, 1] (preserves the range of allowed Gray
values).

ASRao 69
How does it work?

Figure: Illustration of histogram equalization of a 3-bit (8 intensity levels)


image. (a) Original histogram. (b) Transformation function. (c) Equalized
histogram.

 As a result of Histogram equalization, output image will have gray


“equal proportion”. ASRao 70
How to implement histogram equalization?
Step 1: For images with discrete gray values, compute

nk
pin (rk )  0  rk  1 0  k  L 1
n

L: Total number of gray levels


Nk: Number of pixels with gray value rk
n: Total number of pixels in the image

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


transformation

k
sk  T (rk )   pin (r j ) 0  k  L 1
j 0
ASRao 71
ASRao 72
ASRao 73
Example: Histogram Equalization?

Consider an input image with gray levels (k) given as 0, 1, 2, 3, 4, 5, 6, 7.


The histogram of image is as shown below:

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 4 329 4/7 0.08


5 245 5/7 0.06
6 122 6/7 0.03
7 81 1 0.02
ASRao 74
k
 Applying the transformation, sk  T (rk )   pin (r j )
j 0

s0  T (r0 )   pin (r j )  pin (r0 )


j 0

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:

 Histogram equalization may not always produce desirable results,


particularly if the given histogram is very narrow. It can produce false
edges and regions.

ASRao 78
ASRao 79
ASRao 80
Histogram Matching

Purpose Normalizes images

Maps source histogram to


Process
reference histogram

Produces an image matching the


Output
reference histogram

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.

 But there are applications where uniform histogram is not required.

 In fact, one has to specify the shape of the histogram that we want the
processed image to have.

 The method used to generate a processed image that has a specified


histogram is called histogram matching or histogram specification.

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].

(2) Compute all values of the transformation function G using same


equation
k nj
G ( z q )  ( L  1)  , k  0,1, 2, ...., L  1
j 0 MN

And round values of G.

(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

Table: Specified and actual histograms


ASRao 87
zq G(zq) Sk  zq
Z0 = 0 0
Z1 = 1 0 1  3
Z2 = 2 0 3  4
Z3 = 3 1
5  5
Z4 = 4 2
6  6
Z5 = 5 5
Z6 = 6 6 7  7
Z7 = 7 7

Table: All possible values Table: Mappings of


of the transformation all the values of sk
function G scaled, into corresponding
rounded and ordered values of zq.
with respect to z.
ASRao 88
FIGURE: (a) Image of the Mars moon, and (b) its
histogram.
ASRao 89
FIGURE : (a) Transformation function for histogram equalization. (b)
Histogram equalized image. (c) Histogram
ASRao of equalized image. 90
FIGURE:
Histogram
specification.
(a) Specified histogram.
(b) Transformation G(
zq), labeled (1),
and G-1(sk), labeled (2).
(c) Result of histogram
specification.
(d) Histogram of image
(c).

ASRao 91
Key Differences between Histogram Equalization & Histogram Matching

Histogram Histogram Matching


Equalization

Purpose Enhances contrast Normalizes images

Adjusts intensity Maps source histogram


Process
distribution to reference histogram

Produces an image Produces an image


Output with uniform intensity matching the reference
spread histogram

Image enhancement Image normalization


Applications Contrast adjustment Object recognition
Medical imaging Quality control

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.

 There are some cases in which it is necessary to enhance detail over


small areas in an image.

 This procedure is to define 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 a histogram equalization or histogram
specification transformation function is obtained.

 This function is finally used to map the intensity of the pixel centered
in the neighborhood.

 Centre of the neighborhood region is then moved to an adjacent pixel


location and the procedure is repeated.
ASRao 94
 This approach has obvious advantages over repeatedly computing the
histogram of all pixels in the neighborhood region each time the
region is moved one pixel location.

FIGURE: (a) Original image. (b) Result of global histogram equalization.


(c) Result of local histogram equalization.

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.

 The nth moment of r about its mean is defined as

L 1
 n (r )   (ri  m) n p(ri )
i 0

 Here m is the mean average intensity value of r and

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.

 These estimations are known as sample mean and sample variance


and we have sample mean.

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).

 The mean value of the pixels in this neighborhood is


L 1
mS xy   ri pS xy (ri )
i 0

 Where pS xy is the histogram of the pixel in region Sxy.

 The variance of the pixels in the neighborhood is


L 1
 S2xy   (ri  mS xy ) 2 pS xy (ri )
i 0

ASRao 100
Histogram Statistics - Example

Consider the following 2-bit image of size 5*5:

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].

 The total number of pixels is 25.

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

 In local or neighborhood operation, the pixels in an image are


modified based on some function of the pixels in their neighborhood.

 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.

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

 Filtering operations that are performed directly on the pixels of an


image is called Spatial Filtering.

 Filtering is a sub-image which is also known as mask, kernel, template


or window.
 The values in a filter sub-image are referred to as coefficients, rather
than pixels.

 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

 Example: 3X3 mask in a 5X5 image

ASRao 110
Mechanism of Spatial Filtering
This process shows
moving filter mask
point to point.

Mask Coefficients

Filter at each point


(x, y) are calculated
by predefined Pixels of image section
relationship under mask

ASRao 111
 Spatial filtering is similar to neighborhood operation.

 A mask or filter or template or kernel or window defines the


neighborhood.

 Output pixel value is determined from the pixels under the mask.

ASRao 112
The Approaches of Spatial Filtering

 Spatial filter consist of two steps

 Filtering creates a new pixel value replaced by old pixel value.

 A neighborhood (small rectangle)

 A predefined operation performed on image pixels

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

 Each pixel in an image can be replaced with constant value it is called


spatial filter otherwise it is called as non-linear.

ASRao 117
Linear Spatial Filtering
 For Linear spatial filtering:
 Result = sum of product of filter coefficient and the corresponding
image pixel.

 For above figure Response R is


R = w(-1, -1) f(x-1, y-1) + w(-1, 0) f(x-1, y) + ……+ w(0, 0) f(x, y) + … +
w(1, 1)f(x+1, y+1)
 W(0, 0) indicates mask is centered at x, y
 R = ASRao
Result or response of linear filtering118
 Linear filter of an image f of size M X N with a filter
mask size of m x n is given by the expression:

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

 For a mask of size = m x n


 Assume that
 m = 2a + 1 , n = 2b + 1
 Where a and b are non-negativeASRao
integers, then m and n are odd 119
Convolution
 The process of linear filtering is same as convolution.

 So linear spatial filtering is referred to as “convolving a mask with an


image.”

 When interest lies on the response, R, of an m x n mask at any point


(x, y) and not on the mechanics of implementing mask convolution.

 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:

 Smoothing Linear Filters


 Ordered – Statistics Filters
(non-linear spatial filter)

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.

 The idea is replacing the value of every pixel in an image by the


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

 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

5 X 5 Smoothing Linear Filters

1
X
25

Note: For MXN mask, then it will beASRao


normalized with 1/mn 124
 The general implementation for filtering an MXN image with a
weighted averaging filter of size mxn is given by the expression:

a b
  w( s, t ) f ( x  s, y  t )
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.

 This type of operation for arbitrary weighting matrices is generally


called “2D Convolution or filtering”. When all the weights are positive,
it corresponds to weighted average.

 Weighted average filter retains low frequency and suppresses high


frequency (LPF)

 This replacement is done with a convolution mask such as the


following 3X3 mask Arithmetic mean filter smoothing or low pass filter.
ASRao 128
Example: Weighting Mask

 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.

 Gaussian filters remove “high frequency components” from the image.


So it is called “low-pass filter”.

How Gaussian Filters Work?


1. Convolution operation: The filter slides over the image, pixel by pixel.
2. Weighted average: Each pixel's intensity value is replaced by a
weighted average of neighboring pixels.
3. Gaussian distribution: Weights decrease as distance from the center
pixel increases.
ASRao 131
 The weights are samples of a 2D Gaussian function:

σ - width of the Gaussian function.

ASRao 132
Nonlinear Spatial Filtering (Smoothing Nonlinear Filters)

 Nonlinear spatial filters also operate on neighborhoods, and the


mechanics of sliding a mask past an image are the same as was just
outlined.

 The filtering operation is based conditionally on the values of the


pixels in the neighborhood under consideration.

 The mechanism behind non-linear spatial filtering is same as the


linear spatial filtering which uses a filter mask. But it does not use the
coefficients in the sum of product form.

 The main application of non-linear filtering is noise reduction.

ASRao 133
Order – Statistics (Image Statistics Filters)

 Order – Statistics filters are non-linear spatial filters whose response


is based on ordering (ranking) the pixels contained in the image area
encompassed by the filter, and then replacing the value of the center
pixel with the value determined by the ranking result.

 Best Known “Median Filter”

 Replacing the center pixel value with value determined by ranking


result.

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)

Process of Median Filter

 Crop region of neighborhood

 Sort the values of the pixel in our region.


 Median value is replaced at the center.

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).

 Median filtering does not shift boundaries, as can happen with


conventional smoothing filters (a contrast dependent problem)

 Since the median filter is less sensitive than the mean to


extreme values (outliers), those extreme values are more
effectively removed.

 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

Original Image Image after Image after


with noise Average Filter Median Filter

 Filtering is often used to remove noise from images.

 Sometimes a median filter works better


ASRao
than an averaging filter. 140
Maximum and Minimum Filters

 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.

 Minimum filter: Smallest pixel is assigned to the center pixel.

 In a manner similar to the median, minimum and maximum filter, order


filter can be defined to select a specific pixel rank within the ordered set.

 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.

 This type of ordered selection is very sensitive to their type of images


and their use it is application specific. It should note that, in general a
minimum or low rank filter will tend to darken an image and a maximum
or high rank filter will tend to brighten an image.

ASRao 142
Sharpening Filters

ASRao 143
Sharpening Spatial Filters

 Smoothing filters are to remove fine detail.

 Sharpening spatial filters used to highlight the transitions in intensity.

 Useful for highlighting fine details.

 Enhance the blurred image and edges.

 It is accomplished by spatial differentiation.

Applications: Electronics Printing


Medical imaging
Industrial Inspection
Autonomous Guidance in military systems
ASRao 144
Basics of Sharpening

 To understand the concept various derivatives are used.

 For a first order derivative


 It must be zero in areas of constant intensity
 It must be non-zero at the onset of an intensity step or ramp, and
 It must be non-zero along ramps.

 The first order derivative of 1D function is given by

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.

 The second order derivative of 1D function is given by

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.

1st make thick edge and 2nd make thin edge

 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)

 This approach consists of defining a discrete formulation of the second


order derivative and then constructing a filter mask based on that
formulation.

 A common sharpening filter and simplest is the Laplacian


 The simplest isotropic derivative operator is the Laplacian.
 Isotropic filters which are rotational invariant
 It means if we are rotating the image and then
applying the filter will give the same result as applying
the filter to that image first and then rotating the
result.
ASRao 151
 The Laplacian , which , for an image f(x,y) of two variable, is defined as
follows:
2 f 2 f
 f 
2

 x
2
2 y

Discrete form of derivative

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

where f ( x, y ) is the original image


 2 f ( x, y ) is the Laplacian filtered image
g ( x, y ) is the
ASRaosharpen image 156
Unsharp Masking and High boost Filtering

 Printing and publishing sharpen images consists of subtracting an


unsharp (smoothed) version of an image from the original image. This
process is called unsharp masking.

 Consists of the following steps:


1. Blur the original image
2. Subtract the blurred image from the original
(the resulting difference is called the mask)
3. Add the mask to the original.

 Letting f ( x, y ) denote the blurred image, unsharp masking is


expressed as follows. First we obtain the mask:

 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 )

where we included a weight, k (k ≥ 0), for generality.


• When k = 1, we have unsharp masking.
• When k ≥ 1, the process is referred to as highboost filtering.
• Choosing k < 1, deemphasizes the contribution of the
unsharp mask.

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 

 The edge strength is given by the gradient magnitude:


2 2
 f   f 
f      
 ASRao
x  y  161
ASRao 162
 The magnitude (length) of vector denoted as M(x, y), where
2 2
 f   f 
M ( x, y )  mag (f )  G x2  G y2        G x  G y
 x   y 

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

 The simplest approximations to a first order derivative that satisfy the


conditions stated earlier a

Robert’s Crossbar Gradient operators

ASRao 165
Prewitt Operator

 Prewitt operator provides us two masks.


 one for detecting edges in the horizontal direction and another for
detecting edges in a vertical direction.

ASRao 166
Sobel Operator

 The smallest filter mask should be 3 x 3 .

 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).

2. Compute F(u,v), the DFT of the image from (1)

3. Multiply F(u,v) by a filter function H(u,v)

4. Compute the inverse DFT of the result in (3)

5. Obtain the real part of the result in (4)

6. Multiply the result in (5) by (1)


x y
to cancel the multiplication of the
input image.
Classification of Frequency Domain Filters
Low Pass Filters
 A filter that attenuates higher frequency and passes the low frequency
is called LPF of an image.

 Low frequency in the Fourier transform corresponds to the gray level


appearance.

 High frequency in the Fourier transform corresponds to the details


such as edges and noise.

 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy