0% found this document useful (0 votes)
61 views123 pages

Mod 3

Uploaded by

xt PAVAN
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)
61 views123 pages

Mod 3

Uploaded by

xt PAVAN
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/ 123

Module – 3 IMAGE

ENHANCEMENT IN
SPATIAL DOMAIN

By,
Dr.K.Venkateswaran
Professor
Dept. of ECE CMRIT, Bengaluru
Spatial Domain: Some Basic Intensity
Transformation Functions, Histogram Processing,
Fundamentals of Spatial Filtering, Smoothing Spatial
Filters, Sharpening Spatial Filters
Frequency Domain: Preliminary Concepts, The
Discrete Fourier Transform (DFT) of Two Variables,
Properties of the 2-D DFT, Filtering in the Frequency
Domain, Image Smoothing and Image Sharpening
Using Frequency Domain Filters, Selective Filtering.

Dept. of ECE, CMRIT,Bengaluru 2


• A process of improving the visual
quality of any image so that the result is
more suitable than the original image
for a specific application.

• It is a Subjective Process.

Dept. of ECE, CMRIT,Bengaluru 3


• To remove Un-necessary noises.
• To remove defects caused by image
acquisition
oUneven illumination: non-uniform.
oLens: blurring object or
background
o Motion : blurring

Dept. of ECE, CMRIT,Bengaluru 4


Image Enhancement Methods
• Spatial Domain Methods (Image Plane)
Two Categories are Intensity
Transformations and spatial filtering.
• Frequency Domain Methods
Techniques are based on modifying
the Fourier transform of the image.
• Combination Methods
There are some enhancement techniques
based on various combinations of methods
from the first two categories

Dept. of ECE, CMRIT,Bengaluru 5


Spatial Domain Methods
• Intensity transformations operate on single pixels
of an image for contrast manipulation and image
thresholding.
• Spatial filtering operates working in a
neighborhood of every pixel in an image.

Dept. of ECE, CMRIT,Bengaluru 6


Spatial Domain Enhancement Techniques

Point Processing Neighborhood


(Intensity Transformations) Processing
• Image Negative • Smoothing Spatial Filter
• Log Transformation • Linear Spatial Filters
• Power Law Transformation • Low Pass filter
• Piecewise Linear Transformation • Non Linear Spatial Filters
Functions • Median Filter
• Contrast Stretching • Max & Min Filter
• Gray level Stretching • Sharpening Spatial Filter
• Bit Plane Slicing • Using 2nd order
• Histogram processing derivatives(Laplacian)
• Histogram Equalization • Unsharp Masking and
• Histogram Specification High Boost Filtering
• Using 1st order
derivatives(Robert’s &
Sobel Operators).
Dept. of ECE, CMRIT,Bengaluru 7
• Techniques are based on direct manipulation of pixels
in an image.
• Operation: The gray value of each pixel/neighboring
pixels are mapped to a new pixel value and move to
next pixel.
• It is expressed as a mathematical function T[.].
g(x,y)=T[f(x,y)]
Where f(x,y) is the input image, g(x,y) is an
output image and T is an operator on f defined
over a neighborhood of point (x,y).

Dept. of ECE, CMRIT,Bengaluru 8


Contd….
The Operator T applied on f(x,y) may be
defined over
a) A single pixel (x,y). This is called ‘point
Processing’.

Point Processing
b) Some neighborhood of (x,y).
This is called ‘Neighborhood processing’.

Neighborhood Processing

Dept. of ECE, CMRIT,Bengaluru 9


Point Processing
• This is the simplest case of spatial domain
techniques.
• The output at (x,y) depends on the input
intensity at the same point (x,y).
• It is a memoryless operation.
• This technique is extremely useful and
powerful.
g(x,y) = T[f(x,y)]
Also s = T(r)
T
Where r = grey level of f(x,y)
s = grey level of g(x,y)
r s

f(x,y) g(x,y)
Dept. of ECE, CMRIT,Bengaluru 10
Prob 1: Do the transformation g1(x,y)=f(x,y)+1 and
g2(x,y)=f(x,y)2 . On the image f(x,y).
-2 -1 0
f(x,y) =
0 1 2

-2+1 -1+1 0+1 -1 0 1


g1(x,y)
= 0+1 1+1 2+1 = 1 2 3

4 1 0
g2(x,y)= -2X-2 -1X-1 0X0 =
0X0 1X1 2X2 0 1 4
Dept. of ECE, CMRIT,Bengaluru 11
• The process consists of moving
the origin of the neighborhood
from pixel to pixel and applying
the operator T to the pixels in
the neighborhood to yield the
output at that location.
• The process starts at the top
left of the input image and
proceeds pixel by pixel in a
horizontal scan, one row at
a time.

Dept. of ECE, CMRIT,Bengaluru 12


• When the origin of the
neighborhood is at the border of the
image, part of the
neighborhood will reside outside
the image.
• The procedure is to either ignore
the outside neighbors or to pad
the image with a border of 0s.
• The procedure is called spatial
filtering, and the neighborhood is
called spatial filter or spatial mask
or kernel or template or window.

Dept. of ECE, CMRIT,Bengaluru 13


• The three basic types of functions used
frequently for image enhancement:
• Linear Functions:
• Negative Transformation
• Identity Transformation
• Logarithmic Functions:
• Log Transformation
• Inverse-log Transformation
• Power-Law Functions:
• nth power transformation
• nth root transformation

Dept. of ECE, CMRIT,Bengaluru 14


Dept. of ECE, CMRIT,Bengaluru 15
IDENTITY TRANSFORMATION

•This is also called as ‘Lazy Man Operation’.


• The Transformation is
s=r
• After this operation, there is no change in the pixel
values of the output image.
s

L-1
s=
r

L-1 r

Dept. of ECE, CMRIT,Bengaluru 16


Prob 2: Find the Identity Transformation of an image f to
g
0 10 50 100

5 95 150 200
s=r
110 150 190 210

175 210 255 100

0 10 50 100

5 95 150 200

110 150 190 210

175 210 255 100

Dept. of ECE, CMRIT,Bengaluru 17


IMAGE NEGATIVES

• Let the intensity levels are in the range [ 0, L-1].


• Image negative Transformation
is s = (L-1)-r
• Highest gray level is mapped to lowest and vice
versa.
• For an 8-bit image s = 255 – r. s

L-1
s =L-1- r

L-1 r

Dept. of ECE, CMRIT,Bengaluru 18


Contd….
• Function reverses the order from black to
white so that the intensity of the output
image decreases as the intensity of the
input increases.
• Produces the equivalent of a photographic
negative
• Suited for enhancing white or gray detail
embedded in dark regions of an image
especially when the dark area is dominant
in the image.
• Used mainly in medical images.

Dept. of ECE, CMRIT,Bengaluru 19


Contd….

Dept. of ECE, CMRIT,Bengaluru 20


Another Example

Dept. of ECE, CMRIT,Bengaluru 21


Prob 3: Find the Image Negative Transformation on an
image f to obtian g
0 10 50 100

5 95 150 200
s = 255 - r
110 150 190 210

175 210 255 100

255 245 205 155

250 160 105 55

145 105 65 45

80 45 0 155

Dept. of ECE, CMRIT,Bengaluru 22


LOG TRANSFORMATION
• The general form of the log transformation :
s = c log(1+r)
where c is a constant and r is assumed as: r >= 0.
• The details that are hidden in dark values are
highlighted.
• It is a monotonic and reversible process.
• The transformation leads to only one curve.
• The amount of expansion and s
compression to be done is fixed L-1
and cannot be changed.
• It maps a narrow range of low intensity
values in the input into a wider range of s = c log(1+r)
output values.
• It compresses the dynamic range of image
with large variation in grey level values.
L-1 r

Dept. of ECE, CMRIT,Bengaluru 23


LOG TRANSFORMATION

•Example of image with dynamic range: Fourier spectrum image


• It can have intensity range from 0 to 10^6 or higher.
•We can’t see the significant degree of detail as it will be lost in
the display.

Dept. of ECE, CMRIT,Bengaluru 24


INVERSE LOGARITHM TRANSFORMATION
• Do opposite to the log transformations
• Inverse Log transforms - opposite to the Log
Transformations
• Used to expand the values of high pixels in an image while
compressing the darker-level values.

L-1

L-1 r

Dept. of ECE, CMRIT,Bengaluru 25


POWER LAW TRANSFORMATION
• Power Law Transformation is
given by γ
where c and s=cr
are positive

γ
constants.

•Variety of devices used for


image capture, printing and
display respond according to a
power law.

• The process used to correct this


power-law response phenomena
is called gamma correction.
γ
• Plots of s versus r for various
values of are show in Fig.

Dept. of ECE, CMRIT,Bengaluru 26


POWER LAW TRANSFORMATION
• Power-law curves with fractional
values of map a narrow range of
dark input values into a wider
range of output values, with the
opposite being true for higher
values of input levels.

• Unlike the log function, here a


family of possible transformation
curves can be obtained simply by
varying .
• Curves generated with valuesγ of
> 1 have exactly the opposite
effect as those generatedγ with
γ <1.
• The above equation reduces γto the identity
transformation whenvaluesof

c= = 1.

Dept. of ECE, CMRIT,Bengaluru 27


Contd…
GAMMA CORRECTION (an application of POWER LAW TRANSFORMATION)
• The exponent in the
power law equation is
referred to as gamma.
• The process used to
correct this power law
response phenomena is
called gamma correction.
•If the value γ of is
2.5,then such display
system would tend to
produce an image that
are darker than original.
•So to avoid this,
preprocessing of i/p
image[1/2.5=0.4] is
done. Then it produces
o/p that is close appear
to original image.
Dept. of ECE, CMRIT,Bengaluru 28
An another example MRI

Dept. of ECE, CMRIT,Bengaluru 29


Effect of decreasing Gamma
•When the gamma is reduced too much, the
image begins to reduce contrast to the point
where the image started to have very slight
“wash-out” look, especially in the background
• Gamma correction is important when
displaying an image accurately on a
computer screen is of concern. Images that
are not corrected properly can look either
bleached out or too dark .

Dept. of ECE, CMRIT,Bengaluru 30


An another example

Dept. of ECE, CMRIT,Bengaluru 31


PIECEWISE LINEAR TRANSFORMATION
• In Grey Level Transformation, transformation is
applied to whole image.
• If it is required to highlight or enhance particular
part of image, Piecewise linear Transformation is
more suitable.
• Piecewise Linear Transformation is of 3 types
a. Contrast Stretching
b. Gray Level Slicing
c. Bit Plane Slicing

Dept. of ECE, CMRIT,Bengaluru 32


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 image can result from poor illumination, lack of
dynamic range in the image sensor or wrong setting of lens
aperture during image acquisition.
• Contrast stretching is used to increase the dynamic range of
grey level in the image being processed.
• Figure shows the typical transformation used for contrast
stretching.

33
Contd…
• The locations of (r1,s1) and (r2,s2) control the shape of the
transformation function.
I. If r1= s1 and r2= s2 the transformation is a linear function and
produces no changes.
II. If r1=r2, s1=0 and s2=L-1, the transformation becomes a
thresholding function that creates a binary image
• More on function shapes:
I. Intermediate values of (r1,s1) and (r2,s2) produce various
degrees of spread in the gray levels of the output image,
thus affecting its contrast.
II. Generally, r1≤r2 and s1≤s2 is assumed.
s s

L-1 L-1
r1 = r2
s = s =0
r11 s2 = s21 = L-1
r2
0 L-1 r 0 L-1 r

Dept. of ECE, CMRIT,Bengaluru 34


Contd…

Dept. of ECE, CMRIT,Bengaluru 35


GREY LEVEL SLICING
highlight a specific range of gray
• This technique is used to
levels in a given image. Two basic methods to implement this
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. This
transformation, shown in Fig , produces a binary image.
– The second approach, based on the transformation shown in Fig
3.11 (b), brightens the desired range of gray levels but
preserves gray levels unchanged.

36
BIT PLANE SLICING
could
• Instead of highlighting gray-level range, we
highlight the contribution made by each bit.
• This method is useful and used in image compression.
• Each pixel in an image represented by 8 bits.
• Image is composed of eight 1-bit planes, ranging from bit-
plane 0 for the least significant bit to bit plane 7 for the most
significant bit.

Dept. of ECE, CMRIT,Bengaluru 37


BIT PLANE SLICING(contd…)

Dept. of ECE, CMRIT,Bengaluru 38


BIT PLANE SLICING(contd…)

Dept. of ECE, CMRIT,Bengaluru 39


BIT PLANE SLICING(contd…)

Dept. of ECE, CMRIT,Bengaluru 40


HISTOGRAM

• Histogram of an image represents the number of times a


particular grey level has occurred in an image.
• It is a graph between various gray levels on x-axis and the
number of times a grey level has occurred on y-axis.

Dept. of ECE, CMRIT,Bengaluru 41


Plot the histogram of an 8 bit image shown below

155 200 50
255 0 50
255 200 255

No. of pixels
Intensity nk with
Value rk intensity
values rk
0 1
50 2
155 1
200 2
255 3

Dept. of ECE, CMRIT,Bengaluru 42


Histogram of a Digital Image h(rk)

2.5

1.5

0.5

00 50 100 150 200 250

Dept. of ECE, CMRIT,Bengaluru 43


Plot the normalized histogram of an 8 bit image shown below

155 200 50
255 0 50
255 200 255

Normalized

No. of pixels No. of pixels nk


Intensity nk with Intensity Value with intensity
Value rk intensity rk values rk =

values rk nk/MN
0 1 0 1/9
50 2 50 2/9
155 1 155 1/9
200 2 200 2/9
255 3 255 3/9
=1

Dept. of ECE, CMRIT,Bengaluru 44


Normalized Histogram

0.35

0.3

0.25

0.2

0.15

0.1

0.05

00 50 100 150 200 250


Dept. of ECE, CMRIT,Bengaluru 45
HISTOGRAM PROCESSING

• Histogram of an image represents the number of times a


particular grey level has occurred in an image.
• It is a graph between various gray levels on x-axis and the
number of times a grey level has occurred on y-axis.
• The histogram of a digital image with grey levels in the
range [0,L-1] is a discrete function h(rk) = nk.
• Where rk is the kth gray level and nk is the number of pixels
in the image having gray level rk.
• Let the total number of pixels in the image is denoted by
‘MN’.
• The normalized histogram is given by p(rk) = nk /MN.
• p(rk) is an estimate of the probability of occurrence of gray level rk.

• The sum of all components of a normalized histogram is


equal to 1.

Dept. of ECE, CMRIT,Bengaluru 46


OVER EXPOSED IMAGE

1600

1400

1200

1000

800

600

400

200

0 50 100 150 200 250

Dept. of ECE, CMRIT,Bengaluru 47


UNDER EXPOSED IMAGE

1600

1400

1200

1000

800

600

400

200

0 50 100 150 200 250

Dept. of ECE, CMRIT,Bengaluru 48


LOW CONTRAST IMAGE

1600

1400

1200

1000

800

600

400

200

0 50 100 150 200 250

Dept. of ECE, CMRIT,Bengaluru 49


HIGH CONTRAST IMAGE

1600

1400

1200

1000

800

600

400

200

0 50 100 150 200 250

Dept. of ECE, CMRIT,Bengaluru 50


Histogram Equalization

• Histogram equalization:
– To improve the contrast of an image
– To transform an image in such a way that the
transformed image has a nearly uniform
distribution of pixel values

Dept. of ECE, CMRIT,Bengaluru 51


Cont....
• Transformation:
– Assume r has been normalized to the interval [0,L-1],
with r = 0 representing black and r = L-1 representing
white
– The Transformation function is of the form s = T(r) 0
≤ r ≤ L-1
– The transformation function satisfies the
following conditions:
• T(r) is single-valued and strictly monotonically
increasing in the interval 0 ≤ r ≤ L-1
• 0≤T(r)≤L-1 for 0≤r≤L-1

Dept. of ECE, CMRIT,Bengaluru 52


Contd…..

• Histogram equalization is based on a transformation of


the probability density function of a random variable.
• Consider continuous intensity values. Let pr(r) and ps(s) denote
the probability density function of random variables r and s,
respectively.
• If pr(r) and T(r) are known, and T(r) is continuous and differentiable,
then the probability density function ps(s) of the transformed
variable s can be obtained
dr
ps (s)  pr (r) ds

• Define a transformation functions  T (r)  (L 1)r p (w)dw


where w is a dummy variable of integration0 rand the right
side of this equation is the cumulative distribution function
of random variable r .
Dept. of ECE, CMRIT,Bengaluru 53
Contd…..
• Given transformation function T(r), T (r)  (L 1)r p (w)dw
• From Leibniz’s rule in basic calculus, wkt., the 0 r

derivative of the definite integral with respect to it’s


upper limit is the integrand evaluated at that limit.
ds  dT (r)
dr dr
ds dr 
 (L 1) 0 pr (w)dw  (L 1) pr (r)
dr dr  
p (s)  p (r)
dr
 p (r)
1 1 0  s  L-1

s r r
ds (L 1) pr (r) L -1
ps(s) now is a uniform probability density function.
• T(r) depends on pr(r), but the resulting ps(s) always is
uniform.
Dept. of ECE, CMRIT,Bengaluru 54
Contd…..

Dept. of ECE, CMRIT,Bengaluru 55


Contd…..

• In discrete version:
– The probability of occurrence of gray level rk in an image is
p (r )  nk k  0,1,2,..., L 1
r k MN
MN: the total number of pixels in the image
nk : the number of pixels that have gray level rk
L : the total number of possible gray levels in the image
sk
– The transformation function is
 T (rk )  (L 1) pr (rj )  (L 1)
nj
k  0,1,2,..., L 1

k k

MN
j 0 j 0

– Thus, an output image is obtained by mapping each pixel with level rk


in the input image into a corresponding pixel
with level sk .rksk
– The Transformation fromto is called histogram
equalization.
Dept. of ECE, CMRIT,Bengaluru 56
EXTRA
⁻ Probability Density Function(PDF): It is a function that describes
the relative likelihood for the random variable to take on a given
value.
i. bf(x) >= 0
f (x)dx 1
ii. a
⁻ Cumulative Density Function(CDF): It is the area under the PDF
from minus infinity to x.
⁻ To find PDF in the case of Transformed Variables
dr
ps (s)  pr (r) ds

⁻ Definite Integral: An integral expressed as the difference


between the values of the integral at specified upper and lower
limits of the independent variable.

Dept. of ECE, CMRIT,Bengaluru 57


Examples of histogram equalization

Dept. of ECE, CMRIT,Bengaluru

58
Examples of histogram equalization

Dept. of ECE, CMRIT,Bengaluru 59


Examples of histogram equalization

Dept. of ECE,
CMRIT,Bengaluru 60
 Comments:
Histogram equalization may not always produce desirable results,
particularly if the given histogram is very narrow. It can produce false
edges and regions. It can also increase image “graininess” and

Dept. of ECE, CMRIT,Bengaluru 61


Histogram Matching(Specification)

• Histogram equalization automatically determines a


Transformation Function that seeks to produce an output image
that has a uniform histogram.
•For some applications histogram equalization is not best
approach.
•The method used to generate a processed image that has a
specified histogram is called histogram matching or histogram
specification.

Dept. of ECE, CMRIT,Bengaluru 62


Histogram Matching(Specification) Contd….

• Let be a random variable with the property


s  T (r)  (L 1)
r
p (w)dw      (1)
0 r
Where w is a temporary variable.
• This expression is the continuous version of histogram equalization
• Define a random variable z with the property
G(z)  (L 1) p (t)dt  s      (2)
z
0 z
• Where t is temporary variable.
• From the above two equation it follows that G(z)=T(r)
• Therefore z must satisfy the condition

z  G1[T (r)]  G1 (s)      (3)


• The transformation T(r) can be obtained from eqn.(1) once pr(r) has
been estimated from input image.
• Similarly the transformation function G(z) can be obtained using eqn.(2)
because pz(z) is given.

Dept. of ECE, CMRIT,Bengaluru 63


Histogram Matching(Specification) Contd….

• In discrete version:
sk – The probability of occurrence of gray level rk in an image is
k k
 T ( r k )  (L 1)  pr ( rj )  (L 1) 
n
j k  0,1,2,..., L 1

MN
j 0 j 0

MN: the total number of pixels in the image


nk : the number of pixels that have gray level rk
L : the total number of possible gray levels in the image
– The transformation function is
q

G(zq )  (L 1) pz (zi )


i 0
– For a value of q, so that
G(zq )  sk
p (z )
– Where z i is the ith value of the specified histogram.
– The inverse transformation is given by
z  G1 (sk )
Dept. of ECE, CMRIT,Bengaluru
Histogram Matching(Specification) Contd….

rk Histogram sk=T(rk)
Equilization
sk= G(zq)

zq Histogram G(zq)
Equilization

s
k Inverse z1 =G-1 (s )
Transformation of q k

2nd system

Dept. of ECE, CMRIT,Bengaluru 65


LOCAL AND GLOBAL ENHANCEMENT

Dept. of ECE, CMRIT,Bengaluru 66


Enhancement Using Arithmetic/Logic Operations
• Arithmetic/logic operations involving images are
performed on a pixel-by-pixel basis between two or
more images (this excludes the logic operation NOT,
which is performed on a single image).
Logic operations:
Logic operations
• include AND, OR and NOT operations.
• Logic operations operate on a pixel-by-pixel basis.
• We concerned only with the implementation of AND,
OR,and NOT logic operators because these three
operators are functionally complete. In other words any
other logic operator can be implemented by using only
these three basic functions.
• When dealing with logic operations on gray-scale
images, pixel values are processed as strings of
binary numbers.
Dept. of ECE, CMRIT,Bengaluru 67
Dept. of ECE, CMRIT,Bengaluru 68
Arithmetic operations:
Arithmetic operations include
subtraction of two images
addition of two images (image averaging)
division and multiplication of two images
Of the four arithmetic operations subtraction and addition (in that
order) are the most useful for image enhancement.
Image Subtraction
Subtraction of two images results in a new image whose pixel at
coordinates (x, y) is the difference between the pixels in that same
location in the two images being subtracted .
The difference between two images f(x, y) and h(x, y), expressed as
gx, y= f x, y hx, y
Image division: Division of two images is simply the multiplication
of one image by the reciprocal of the other.
Image multiplication: Multiplying an image by a constant is used to
increase its average gray level. Image multiplication finds use in
enhancement primarily as a masking operation that is more general
than the logical masks (implements only binary masks). Multiplication of
one image by another can be used to implement gray-level masks.
Dept. of ECE, CMRIT,Bengaluru 69
Image Averaging
• When taking pictures in reduced lighting (i.e.,
low illumination), image noise becomes
apparent.
• A noisy image g(x,y) can be defined by
g(x, y)  f (x, y) (x, y)
where f (x, y): an original image
: the addition of noise
• One simple(x,y) way to reduce this granular
noise is to take several identical pictures and
average them, thus smoothing out the
randomness.

Dept. of ECE, CMRIT,Bengaluru 70


 If an image g x, yis formed by averaging
K
g K different noisy images,
 1
g x, y =  i x, y 
K
 Then it follows that: i=1

 1 K
 1 K 
g f
E g x, y = E   i x, y  = E   i x, y + ηx, y 
K K
 i=1   i=1 

Eg x, y E g x, y = f x, y 


where is the expected val ue of
g

And it that:
2
1 2
σ g x,y  = K σ η x,y 
2
σ g x,y  and σ η2 x,y  are the variances of g and η , all at
coordinates (x, y).
• That is; the standard deviation at any point in the average image is
1
σ = σ
g x,y  K ηx,y  71
Dept. of ECE, CMRIT,Bengaluru
​ Filter term in “Digital image processing” is
referred to the subimage
​ There are others term to call subimage such as
mask, kernel, template, or window
​ The value in a filter subimage are
referred as coefficients, rather than pixels.
​ The concept of filtering has its roots in the
use of the Fourier transform for signal processing
in the so-called frequency domain.
​ Spatial filtering term is the filtering
operations that are performed directly on the
pixels of an image
​ The process consists simply of moving
the filter mask from point to point in an
image.
​ At each point (x,y) the response of the
filter at that point is calculated using a
predefined relationship
Basics of Spatial Filtering - Linear

Spatial filtering are filtering


operations performed on
the pixel intensities of an
image and not on the
frequency components of
the image.
a b

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

a = (m - 1) / 2 b = (n - 1) / 2

Dept. of ECE, CMRIT,Bengaluru 75


Linear spatial filtering
The result is the sum of
Pixels of image products of the mask
coefficients with the
w(-1,-1) w(-1,0) w(-1,1)
corresponding pixels
directly under the mask
w(0,-1) w(0,0) w(0,1)

w(1,-1) w(1,0) w(1,1)


Mask coefficients
w(-1,-1) w(-1,0) w(-1,1)

w(0,-1) w(0,0) w(0,1)

f (x, y)  w(1,1) f (x 1, y 1)  w(1,0) f (x 1, y)  w(1,1) f (x 1, y 1) 


(1, -1) w(1,0) w( ,1)
w(0,1) f (x, y 1)  w(0,0) f (x, y)  w (0 ,1) f (x, y 1 ) 
w(1,1) f (x 1, y 1)  w(1,0) f (x 1, y)  w(1,1) f (x 1, y 1)
​ The coefficient w(0,0) coincides with
image value f(x,y), indicating that the
mask is centered at (x,y) when the
computation of sum of products takes
place.
​ For a mask of size mxn, we assume
that m=2a+1 and n=2b+1, where a and b
are nonnegative integer. Then m and n are
odd.
​ In general, linear filtering of an
image f of size MxN with a filter mask
of size mxn is given by the expression:

a b

g(x, y)  w(s, t) f (x  s, y  t)
sat b
​ The process of linear filtering similar
to a frequency domain concept called
“convolution”

Simplify expression mn
 wz w1 w2 w3
R  w1z1  w2 z2 ...  wmn zmn  9
i i
w4 w5 w6

i1

w w w
R  w1z1  w2 z2 ...  w9 z9  wi zi 7 8 9
i1
Where the w’s are mask coefficients, the z’s are the value of the
image gray levels corresponding to those coefficients
​ 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
​ 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
​ There are 2 way of smoothing spatial filters
◦ Smoothing Linear Filters
◦ Order-Statistics Filters(Non Linear)
​ Linear spatial filter is simply the average of
the pixels contained in the neighborhood of
the filter mask.
​ Sometimes called “averaging filters”.
​ 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.
1 1 1 1 2 1
1 1
1 1 1 2 4 2
9 16
1 1 1 1 2 1

Standard average Weighted average


5x5 Smoothing Linear Filters

1 1 1 1 1

1 1 1 1 1
1
1 1 1 1 1
25
1 1 1 1 1

1 1 1 1 1
​ 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at b
g(x, y)  a b

w(s, t)
sat b
Result of Smoothing Linear Filters

Original Image

[3x3] [5x5] [7x7]


​ Order-statistics filters are nonlinear
spatial filters whose response is based on
ordering (ranking) the pixels contained in
the image area encompassed by the filter,
and then replacing the value of the center
pixel with the value determined by the
ranking result.
​ Egs: Median filter, Min Filter, Max Filter.
​ Median Filter reduces both Salt
and Pepper Noise.
​ Min Filter reduces Salt noise.
​ Max Filter reduces Pepper noise.

Dept. of ECE, CMRIT,Bengaluru 89


​ Crop region of
neighborhood
10 15 20
​ Sort the
20 100 20 values of the
pixel in our
20 20 25 region
​ In the MxN mask
the median is
10, 15, 20, 20, 20, 20, 20, 25, 100 MxN div 2 +1
Dept. of ECE, CMRIT,Bengaluru 91
Result of median filter

Noise from Glass effect Remove noise by median filter


The principal objective of sharpening is to
highlight
​ transitions in intensity(edge sharpening).
​ fine detail in an image
​ to enhance detail that has been blurred,
either in error or as an natural effect of a
particular method of image acquisition.
​ The image blurring is accomplished in
the spatial domain by pixel averaging in a
neighborhood.
​ Since averaging is analogous to integration.
​ Sharpening could be accomplished by
spatial differentiation(first and second
derivatives).
​ We are interested in the behavior of these
derivatives in areas of constant gray level(flat
segments), at the onset and end of
discontinuities(step and ramp discontinuities),
and along gray-level ramps.
​ These types of discontinuities can be
noise points, lines, and edges.
​ First let us consider 1D Digital signals.
​ The derivatives of a digital function
are defined in terms of differences.
​ A basic definition of the first-order derivative of a
one-dimensional function f(x) is
 f
 x  f (x 1)  f (x)
​ Must be zero in flat segments
​ Must be nonzero at the onset of a gray-level step
or ramp; and
​ Must be nonzero along ramps.
First and second order derivatives

Dept. of ECE, CMRIT,Bengaluru 97


​ We define a second-order derivative as the
difference
2 f
 f (x 1)  f (x 1)  2 f (x).
x2
​ Must be zero in flat areas;
​ Must be nonzero at the onset and end
of a gray-level step or ramp;
​ Must be zero along ramps of constant slope
Gray level profile

99
​ 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 for the 1st-order derivative

1st make thick edge and 2nd make thin edge


Comparison between f" and f´
​ f´ generally produce thicker edges in an image
​ f" have a stronger response to file detail
​ f´ generally have a stronger response
to a gray-level step
​ f" produces a double response at step
changes in gray level
​ f" responses given similar changes in
gray- level values line > point > step
​ For image enhancement, f" is generally
better suited than f´
​ Major application of f´ is for edge extraction;
f´ used together with f" results in
impressive enhancement effect
10
Dept. of ECE, CMRIT,Bengaluru 2

9/17/2018 Digital Image Processing 102


​ Shown by Rosenfeld and Kak[1982]
that the simplest isotropic derivative
operator is the Laplacian is defined as
f f
2 f     x2
2 2

y2
f(x-1,y) f(x,y) f(x+1,y) 2 f
x2  f (x 1, y)  f (x 1, y)  2 f (x, y)

f(x,y-1)

2
f(x,y) f
 f (x, y 1)  f (x, y 1)  2 f (x, y)
y 2

f(x,y+1)
​ The digital implementation of the 2-
Dimensional Laplacian is obtained by
summing 2 components
2f 2f
2 f    
2 2
x y
2 f  f (x 1, y)  f (x 1, y)  f (x, y 1)  f (x, y 1)  4 f (x, y)
1

1 -4 1

1
1 1 1
0 1 0
1 -8 1
1 -4 1

1 1 1
0 1 0

1 0 1

0 -4 0

1 0 1
0 -1 0

-1 4 -1 -1 -1 -1

0 -1 0 -1 8 -1

-1 -1 -1
-1 0 -1

0 4 0

-1 0 -1
​ The Laplacian filters are
isotropic filters(rotation
invariant).
◦ In the sense that rotating the image and then
applying the filter gives the same result as appling
the filter to the image first and then rotating the
result.
10
Dept. of ECE, CMRIT,Bengaluru 8
 f (x, y)  2 f (x, y) When centre co-efficient is negative
g(x, y)   When centre co-efficient
 f (x, y)  2 f (x, y) is positive

Where f(x,y) is the original image


2 f (x, y) is Laplacian filtered image
g(x,y) is the sharpen image
Laplacian for image enhancement
(example)

11
0
1. Blur the original image
2. Subtract the blured image from the original (the
resulting difference is called the mask)
3. Add the mask to the original
​ Letting f ’(x,y) denote the blured image, unsharp masking is
expressed in equation form as follows. First obtain the mask:
gmask(x,y)=f(x,y)-f ’(x,y)
​ Then we add a weighted portion of the mask back to the
original image:
g(x,y)=f(x,y)+k* gmask(x,y)
When k=1, we have unsharp masking
When k>1, the process is referred to as highboost filtering When
k<1, de-emphasizes the contribution of the unsharp mask

11
1
11
Dept. of ECE, CMRIT,Bengaluru 2
11
3
f(x+1,y)–f(x,y+1)

This mask is simple, and no isotropic. Its


result only horizontal and vertical.
​ The simplest approximations to a
first- order derivative that satisfy the
conditions stated in that section are

z1 z2 z3 Gx = (z9-z5) and Gy = (z8-z6)

z4 z5 z6 2 2
f  (z9  z5 )  (z8  z6 )

z z z
7 8 9 f  z9  z5  z8  z6
​ These mask are referred to as
the Roberts cross-gradient
operators.

-1 0 0 -1

0 1 1 0
​ Mask of even size are awkward to apply.
​ The smallest filter mask should be 3x3.
​ The difference between the third and
first rows of the 3x3 image region
approximate derivative in x-direction, and
the difference between the third and first
column approximate derivative in y -
direction.
​ Using this equation

f  (z7  2z8  z9 )  (z1  2z2  z3 )  (z3  2z6  z9 )  (z1  2z4  z7 )

-1 -2 -1 -1 0 1

0 0 0 -2 0 2

1 2 1 -1 0 1
11
Dept. of ECE, CMRIT,Bengaluru 9

You might also like