0% found this document useful (0 votes)
30 views125 pages

IP Module2

Chapter 2 discusses image enhancement techniques aimed at improving the visual appearance of images without increasing inherent information. It covers various methods such as point processing, contrast stretching, histogram processing, and transformations like log and power-law transformations. The chapter emphasizes the importance of selecting appropriate techniques for specific applications and provides examples of operations like thresholding and histogram equalization.

Uploaded by

leken52079
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)
30 views125 pages

IP Module2

Chapter 2 discusses image enhancement techniques aimed at improving the visual appearance of images without increasing inherent information. It covers various methods such as point processing, contrast stretching, histogram processing, and transformations like log and power-law transformations. The chapter emphasizes the importance of selecting appropriate techniques for specific applications and provides examples of operations like thresholding and histogram equalization.

Uploaded by

leken52079
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/ 125

Chapter 2

(Part 1)

Image Enhancement

Dr. Archana Ekbote


Image Enhancement

❖ Objective
– To process an image so that the result is more suitable than the
original image for a specific application.

➢ Image Enhancement does not increase the inherent information in


the data (image).
➢ It improves the visual appearance of an image in a subjective way.
➢ Predicting the best enhancement technique for a given application is
rather difficult.

01
Image Enhancement

Image Enhancement

Spatial Domain Frequency Domain


Techniques Techniques
(Direct manipulation (Modify the Fourier
of pixels in an Image) Transform of an Image)

Linear Filtering

Point Processing Mask Processing Global Operation


or
Local Operation

02
Outline of the Chapter

❖ Point Processing
❖ Piecewise Linear Transformations
❖ Histogram Processing
❖ Arithmetic & Logic Operations

03
Point Processing

04
Point Processing Operations

– Point Processing operations are essentially gray scale transformation


operations
– They are defined by
s = T(r)
where r  Input gray level
s  Output gray level
T  Transformation function

– Transformation function is applied to each of the gray level of the


individual pixels one at a time.
– Zero memory operations.

05
Examples of Point Processing Operations

– Image Negative
– Contrast Stretching
– Thresholding
– Noise Clipping
– Dynamic Range Compression
– Gray (Intensity) Level Slicing
– Bit-plane Slicing
– Image Subtraction and Addition

06
Image Negative

❖ Transformation Function
s = ( L − 1) − r

( L − 1)

Output gray level, s

0 ( L − 1)
Input gray level, r

– It is equivalent to a photographic negative


– Enhances white or gray details in dark regions
– Useful in displaying medical images

07
Image Negative

08
Log Transformation

❖ Transformation Function
s = c log(1 + r ) r 0
( L − 1)

Output gray level, s

0 ( L − 1)
Input gray level, r

– Maps narrow range of low gray levels of input image to wider range of gray
levels in the output image.
– Useful in displaying Fourier spectrums

09
Log Transformation

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


10
Log Transformation

11
Power-Law Transformation

❖ Transformation Function
s = c r c,   0
( L − 1)

0   1

Output gray level, s


 =1

 1

0
0 ( L − 1)
Input gray level, r

– For  < 1 : Maps narrow range of low gray levels of input image to wider
range of gray levels in the output image.
– For  > 1 : Maps narrow range of high gray levels of input image to wider
range of gray levels in the output image.

12
Power-Law Transformation

– Effect of changing 

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson

13
Power-Law Transformation

 = 0.5  = 1.5

Images courtesy : Jacques Joffre


14
Power-Law Transformation

– Gamma Correction

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson

15
Piecewise Linear Transformations

16
Piecewise Linear Transformations

❖ Contrast Stretching
❖ Gray Level Slicing
❖ Bit-plane Slicing

17
Contrast Stretching

❖ Low contrast in image is due to


– Poor & non-uniform lighting conditions
– Non linearity of imaging sensor
– Small dynamic range of the imaging sensor

❖ Contrast Stretching increases the dynamic range of the gray levels


in the image.

18
Contrast Stretching contd…

❖ Transformation Function
s = m1 r 0  r  r1
= m2 (r − r1 ) + s1 r1  r  r2
= m3 (r − r2 ) + s2 r2  r  L − 1
( L − 1)
Output gray level, s (r2 , s2 ) m3

m2

T (r )

m1 (r1 , s1 )

0
0 ( L − 1)
Input gray level, r

Slope is kept more than unity in the region where contrast stretching is
needed
19
Special cases of Contrast Stretching

❖ Case 1: r1 = s1 and r2 = s2
– Identity Transformation
– Gray levels are unchanged

( L − 1)

(r2 , s2 )
Output gray level, s

( r1 , s1 )

0
0 ( L − 1)
Input gray level, r

20
Special cases of Contrast Stretching contd…

❖ Case 2: r1 = r2 , s1 = 0 and s2 = L − 1
– Thresholding
– Converts gray image to binary image
– An important initial operation in segmentation

( L − 1)
Output gray level, s
(r2 , s2 )

( r1 , s1 )
0
0 ( L − 1)
Input gray level, r

21
Special cases of Contrast Stretching contd…

Example of Thresholding

Original Image Image after Thresholding


r1 = r2 = 35

22
Special cases of Contrast Stretching contd…

❖ Case 3: r1  r2 , s1 = 0 and s2 = L − 1
– Clipping
– If the useful image signal is known to be in the range (r1,r2), clipping
helps in noise removal

( L − 1) (r2 , s2 )
Output gray level, s

(r1 , s1 )
0
0 ( L − 1)
Input gray level, r

23
Special cases of Contrast Stretching contd…

Example of Clipping

Original Image Image after clipping


r1 = 70, r2 =160

Images courtesy : MATLAB Toolbox


24
Contrast Stretching contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


25
Gray Level Slicing

– Highlights specific range of gray levels in the image

❖ Method 1: Without Background


s = s2 r1  r  r2
= s1 otherwise
( L − 1)
T (r ) – Produces a binary image
– Does not preserve the details
Output gray level, s

s2

s1

0 A B ( L − 1)
Input gray level, r

26
Gray Level Slicing contd…

❖ Method 2: With Background


s = s2 r1  r  r2
=r otherwise
( L − 1)
– Enhances the brightness of the
s2
desired gray levels
Output gray level, s

– Preserves the background


T (r )

0 A B ( L − 1)
Input gray level, r
❖ Applications of Intensity Level Slicing
– Enhancing masses of water in satellite images
– Enhancing flaws in X-ray images
– Segmentation of low temperature regions in an infrared image
27
Gray Level Slicing contd…

r1 = 30, r2 = 40
s1 = 0, s2 = 255

28
Bit-plane Slicing

❖ It indicates the contribution made by specific bits to the total image


❖ Higher order bit-plane (Most significant bits) contribute to visually
significant data
❖ Other bit-planes contribute to details

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


29
Bit Plane Slicing contd…

8-bit fractal image

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


30
Histogram Processing

31
Histogram Processing

❖ Histogram:
Histogram of a digital image with gray levels in range [0,L-1] is a
discrete function
h(rk)=nk
where rk= kth gray level
nk = no. of pixels in the image having gray level rk

❖ Normalized Histogram:
nk
p (rk ) =  Probability Distribution Function
n
where n = total no. of pixels in the image

32
What does Histogram Tell Us?

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


33
What does Histogram Tell Us? contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


34
What does Histogram Tell Us? contd…

Original Image Histogram of Original Image

Transformation function Image after Contrast Stretching

(125,180)

(55,160)

35
What does Histogram Tell Us? contd…

36
Histogram Equalization

❖ Histogram Equalization is a form of Automatic Contrast


Stretching.
❖ Contrast stretching is done on the entire image
automatically without requiring any parameter selection
(Global processing)
❖ Transforms r to s through T(r) such that the histogram of
output image is flat.

37
Histogram Equalization contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


38
Histogram Equalization contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


39
Histogram Equalization contd…

❖ Consider r = [0,1] be normalized gray levels


❖ Transformation function
s = T(r) 0≤r≤1

❖ T(r) must satisfy two conditions


– It should be single valued & monotonically increasing function
Single Valued  to guarantee inverse transformation exist
Monotonicity  to preserves increasing order from black to white
– 0 ≤ T(r) ≤ 1 0≤r≤1
Range of output gray levels (s) must be same as input gray levels (r)

❖ If the above conditions are satisfied, then we can write the Inverse
Transformation Function from s to r as
r = T –1(s) 0≤s≤1

40
Histogram Equalization contd…

❖ Consider pr(r) and ps(s) be the PDFs of input and output gray levels

❖ If pr(r) and T(r) is known and T-1(s) exists then


dr
p s ( s ) = pr ( r )      (1)
ds

❖ Consider the transformation function


r
s = T (r ) =  pr ( w) dw     (2)
0

where w = dummy variable for integration

❖ Here RHS is CDF (Cumulative Distribution Function) of random


variable r

41
Histogram Equalization contd…

❖ Differentiating eq. (2) w.r.t. r

ds d T (r )
=
dr dr
d  
r
=   pr ( w) dw
dr  0 
= pr (r )  (3)

❖ Substituting in eq. (1)


dr 1
p s ( s ) = pr ( r ) = pr ( r )
ds pr ( r )
=1     (4)
 Uniform Distribution

42
Histogram Equalization contd…

❖ For Digital Image

nk
p (rk ) = k = 0,1, , L − 1
n

k
sk = T (rk ) =  pr (rj )
j =0

k nj
= k = 0,1, , L − 1
j =0 n

43
Example of Histogram Equalization

r = [0,7]

Histogram of the image


nk

0 1 3 4 0 6

5
4 1 3 2 0
4
2 6 2 2 6
3

2 0 7 5 7 2

2 0 4 3 5 1

0 rk
0 1 2 3 4 5 6 7

45
Example of Histogram Equalization contd…

rk nk pr(rk) sk sk (L-1) Valid s


0 5 0.20 0.20 1.4 1
1 2 0.08 0.28 1.96 2
2 6 0.24 0.52 3.64 4
3 3 0.12 0.64 4.48 4
4 3 0.12 0.76 5.32 5
5 2 0.08 0.84 5.88 6
6 2 0.08 0.92 6.44 6
7 2 0.08 1 7 7
∑ = 25 ∑=1

46
Example of Histogram Equalization contd…

s
1 7
0.9285
0.857 6
0.7855
0.714 5
0.6425
0.571 4
0.5005
0.429 3
0.3575
0.286 2
0.2145
0.143 1
0.0715
0 0
0 1 2 3 4 5 6 7 r
0.143

0.286

0.429

0.571

0.714

0.857
0

1
47
Example of Histogram Equalization contd…

r s
0 1
0 1 3 4 0 1 2 1 2 4 5 1

4 1 3 2 0 2 4 5 2 4 4 1

2 6 2 2 6 3 4 4 6 4 4 6

2 0 7 5 7 4 5 4 1 7 6 7

2 0 4 3 5 5 6 4 1 5 4 6

6 6
7 7

48
Histogram Equalization contd…

– Repeated application of Histogram Equalization on the same image


does not change the appearance of the image.

– Drawback of global Histogram Equalization : When applied to


smooth noisy areas, enhances noise with slight increase in contrast.

– Local Histogram Equalization can enhance actual image details


more effectively with less enhanced noisy area

48
Histogram Equalization contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


49
Histogram Equalization contd…

❖ Is it possible to convert a given histogram to a flat


histogram?
For Analog Image For Digital Image
✓ YES ✓ NO
✓ As all the gray levels are ✓ Limited levels are available
available in range [0,L-1], in range [0,L-1] because of
 r can be transformed to quantization,
any required s  required s may not exist
and so r has to be
transformed to closer s
available

50
Histogram Matching

❖ Also known as Histogram Specification


– It is a process to generate an image that has a specified histogram.
– Allows us to select the shape of the histogram.
pr (r )  PDF of Input Image
pz ( z )  Specified PDF of Output Image
r
Let s = T (r ) =  pr ( w) dw  Continuous Histogram Equalization
0

where w = dummy variable of integration


z
Define G ( z ) =  pz (t ) dt = s
0

where t = dummy variable of integration


 G ( z ) = T (r )
and z = G −1 ( s ) = G −1[T (r )]
51
Histogram Matching contd…

Histogram Matching for Digital Image


k
sk = T (rk ) =  pr (rj )
j =0
k nj
= k = 0,1, 2, , L − 1
j =0 n

k
vk = G ( z ) =  pz ( zi ) = sk
i =0

k = 0,1, 2, , L − 1

zk = G −1[T (rk )] = G −1 ( sk )
k = 0,1, 2, , L − 1

52
Histogram Matching contd…

Implementation of Histogram Matching

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


53
Histogram Matching contd…

Example

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


54
Histogram Matching contd…

Example

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


55
Histogram Matching contd…

Problem
Modify the histogram A as given in histogram B

Histogram A
Normalized gray level rk 0 1/7 2/7 3/7 4/7 5/7 6/7 1
No. of pixels nr 790 1023 850 656 329 245 122 81

Histogram B
Normalized gray level zk 0 1/7 2/7 3/7 4/7 5/7 6/7 1
No. of pixels nz 0 0 0 614 819 1230 819 614

56
Histogram Matching contd…

Step 1: Histogram equalization of the original image

Closest valid
rk nr pr(rk) sk
level
0 790 0.19 0.19 1/7

1/7 1023 0.25 0.44 3/7

2/7 850 0.21 0.65 5/7

3/7 656 0.16 0.81 6/7

4/7 329 0.08 0.89 6/7

5/7 245 0.06 0.95 1

6/7 122 0.03 0.98 1

1 81 0.02 1 1

57
Histogram Matching contd…

Step 2: Equalized original image

sk ns ps(sk)

0 0 0

1/7 790 0.19

2/7 0 0

3/7 1023 0.25

4/7 0 0

5/7 850 0.21

6/7 656+329 = 985 0.24

1 245 + 122 + 81 = 488 0.11

58
Histogram Matching contd…

Step 3: Histogram Matching

Closest valid
zk nz pz(zk) vk
level
0 0 0 0 0

1/7 0 0 0 0

2/7 0 0 0 0

3/7 614 0.15 0.15 1/7

4/7 819 0.20 0.35 3/7

5/7 1230 0.30 0.65 5/7

6/7 819 0.20 0.85 6/7

1 614 0.15 1 1

59
Histogram Matching contd…

Step 3: Histogram Matching (contd.)

sk ns zk sk nz

0 0 0 0 0

1/7 790 1/7 0 0

2/7 0 2/7 0 0

3/7 1023 3/7 1/7 790

4/7 0 4/7 3/7 1023

5/7 850 5/7 5/7 850

6/7 985 6/7 6/7 985

1 488 1 1 488

60
Arithmetic & Logical Operations

61
Image Subtraction

– g(x,y) = f(x,y) – h(x,y)


– Applications
• Can effectively compare two complicated images
• Powerful method to find missing components on a circuit board /
automated inspection of PCB
• Security monitoring systems
• Used to make masking films for fabrication of ICs
• Useful in mask mode radiography

62
Image Subtraction contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


63
Image Subtraction contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


64
Image Subtraction contd…

Image 2

Image 1

65
Image Subtraction contd…

Difference Image after rescaling gray levels using


g ( x, y ) + ( L − 1)
g rescaled ( x, y ) =
2

66
Image Subtraction contd…

Difference Image after rescaling gray levels using

g rescaled ( x, y ) =
( g ( x, y ) − g min )  ( L − 1)
( g max − g min )

67
Image Subtraction contd…

Difference Image after rescaling gray levels using


( L − 1)
g rescaled ( x, y ) = ( g ( x, y ) − g min ) 
g max

68
Image Subtraction contd…

Difference Image after rescaling gray levels using

g rescaled ( x, y ) = g ( x, y )

69
Logical Operations

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


70
Chapter 2
(Part 2)

Spatial Filtering For


Image Enhancement

Dr. Archana Ekbote


Outline of the Chapter

❖ Concept of Spatial Filtering


❖ Smoothing Filters
❖ Sharpening Filters

01
Spatial Filtering

➢ Spatial Filtering is also known as Mask Processing.

➢ Filtering operations are performed directly on the pixels of an image


i.e. directly in the Spatial Domain.

➢ Spatial Filtering operations are carried out by choosing a group of


pixels at a time  Local operation

➢ All the chosen pixels participate in the transformation action.

➢ Pixels are grouped by defining a neighborhood.

02
Neighborhood of a pixel

3x3 neighborhood

5x5 neighborhood

7x7 neighborhood

2x2 neighborhood

4x4 neighborhood

– Odd numbered matrix taken in order to conveniently identify center pixel.


– For even numbered matrix, the center pixel should be defined properly
e.g. top-left corner for 2 x 2

03
Mechanics of Spatial Filtering

➢ All pixels in the image are processed according to the values of a


Subimage whose dimensions are same as that of neighborhood
matrix defined.  Local operation

➢ Spatial filtering is not zero memory operation  Can’t be performed


INPLACE

➢ The Subimage is called a filter, mask, kernel, template or window.

➢ Values of mask are called filter coefficients.

04
Mechanics of Spatial Filtering contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


05
Mechanics of Spatial Filtering contd…

➢ Spatial Filtering = 2-D Convolution of Image with Mask


New pixel value of center pixel = 
Over Neighborhood
( Mask coefficients  Image coefficients )

For image of size M  N and mask of size m  n


a b
g ( x, y ) =   w(s, t ) f ( x + s, y + t )
s =− a t =− b

where a = (m − 1) / 2 and b = (n − 1) / 2
➢ 2-D Convolution will expand the image 

➢ Border pixels need to be processed carefully to avoid expansion of


the image.

06
Spatial Frequency

➢ It is the rate of change of gray levels w.r.t coordinates.

➢ An image with abrupt variations in gray level is considered to contain


very high spatial frequency components.

➢ A image with more or less similar adjacent gray levels is considered


to have low spatial frequency components.

07
Classification of Spatial Filters

Spatial Filters

Smoothing Filters Sharpning Filters


(Low-Pass Filters) (High-Pass Filters)

Linear Filters Non-Linear Filters Gradient Laplacian


(Order Statistics Filters) (1st order derivative) (2nd order derivative)

Median filter Sobel

Min filter Prewitt

Max filter Roberts

Mid-point filter

08
Smoothing Filters

09
Linear Low Pass Filtering

➢ Also called as Averaging Filters

➢ It tries to remove abrupt variations (high frequency component) in the


gray levels.

➢ Helps in eliminating random noise (e.g. Gaussian noise) since noise


appears as a sudden variation in the gray level values.

➢ Simple approach: replace the center pixel value by average of the


neighborhood

➢ Results in blurring (larger the neighborhood, more will be the blurring)

10
Mask for Low Pass Filtering

Simple Average Mask

1 1 1 1 1 1 1 1
1
x 1 1 1 1 1 1 1 1
9
1
1 1 1 x 1 1 1 1 1
25
3x3 Mask 1 1 1 1 1

1 1 1 1 1

5x5 Mask
Weighted Average Mask / Gaussian Mask

1 2 1
1
x 2 4 2
16
1 2 1

3x3 Mask

11
Example of Low Pass filtering

1 1 1 5 3 4 7 10
1
x 1 1 1
9
3 2 4 7 10
1 1 1

2 2 4 5 7
10 0 0 11 10
1 2 2 3 4
1 3 2 10 10
1 1 1 1 2
1 1 3 10 10

2 3 1 1 2 6 2 3 8 10

1 1 1 1 2 4 2 4 8 10
Image 1 2 4 6 8
1 2 1
1 2 2 2 3 4
x 2 4 2
16
1 2 1 1 1 1 1 2

12
Effect of Mask size

Original Image LP Filtering with 3x3 Mask LP Filtering with 5x5 Mask

LP Filtering with 9x9 Mask LP Filtering with 15x15 Mask LP Filtering with 35x35 Mask

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


13
Order Statistics Filters

➢ Non-linear Spatial Filters

➢ Response is based on ordering (ranking) the pixel contained in the


image area encompassed by the filter and then replacing the value of
the centre pixel with the value determined by the ranking result.

➢ Examples of Order Statistics Filters

– Median filter
– Min filter
– Max filter
– Midpoint Filter

14
Median Filter

➢ Center pixel is replaced by the median of the neighborhood pixels

fˆ ( x, y ) = median{ g ( s, t )}
( s ,t )S xy

➢ Forces the center pixel not to assume the extreme values

➢ Very effectively eliminates salt-and-pepper noise

➢ Median filter fails to eliminate salt-and-pepper noise if the noisy pixels


are more than half of the neighborhood coefficients

15
Median Filter contd…

Example of Median Filter using 3x3 mask

2 3 4 6 6 2 3 4 6 6
0 15 2 6 6 2 2 4 6 6
Median
1 2 3 15 14 1 2 3 6 13
Filter
1 3 12 0 13 2 3 4 12 13
2 4 11 12 11 2 4 11 11 11

Median of [0,1,2,2,2,3,3,4,15] = 2

16
Median Filter contd…

Original Image Image after adding salt-and-pepper noise

Image after averaging Image after median filtering

17
Median Filter contd…

3x3 median mask 5x5 median mask

18
Max and Min Filters

➢ Center pixel is replaced by the Maximum or Minimum of the


neighborhood pixels
For max filter
fˆ ( x, y ) = max {g ( s, t )}
( s ,t )S xy

For min filter


fˆ ( x, y ) = min {g ( s, t )}
( s ,t )S xy

➢ Max Filter is useful in finding the brightest point in the image

➢ Min Filter is useful for finding darkest point in the image

19
Max and Min Filters contd…

Example of Max and Min Filters using 3x3 mask


2 3 4 6 6 15 15 15 6 6
2 15 2 6 6 15 15 15 6 6
Max
4 2 3 5 2 15 15 15 6 6
Filter
4 3 3 0 3 4 4 5 5 5
2 4 4 2 1 4 4 4 4 3

2 2 2 2 6
2 2 2 2 2
Min
2 2 0 0 0
Filter
2 2 0 0 0
2 2 0 0 0

20
Midpoint Filters

➢ Center pixel is replaced by the Midpoint of the Maximum and Minimum


gray level of the neighborhood pixels

fˆ ( x, y ) =  max {g ( s, t )} + min {g ( s, t )}


1
2 ( s ,t )S xy ( s ,t )S xy 

➢ Works best for the randomly distributed noise (Gaussian or Uniform


noise)

21
Midpoint Filters contd…

Example of Midpoint Filters using 3x3 mask

2 3 4 6 6 8 8 9 4 6
0 15 2 6 6 8 8 9 9 11
Midpoint
1 2 3 15 14 8 8 8 8 8
Filter
1 3 12 0 13 3 7 6 8 8
2 4 11 12 11 3 7 6 7 7

22
Sharpening Filters

23
Sharpening Filters

➢ These are High Pass Filters.

➢ It emphasize the high frequency component of an image and


attenuates low frequency component.

➢ Sharp edges & abrupt change in pixel values are made further
dominant.

➢ Areas of constant gray levels are converted to dark after High Pass
filtering.

24
Sharpening Filters contd…

Why Sharpening / High Pass Filters ???

➢ Input image may be blurred due to poor focus or other defects of the
imaging device.

➢ Principal objective of sharpening filters is to highlight fine details (like


edges) or to enhance detail that has been blurred.

25
Sharpening Filters contd…

Blurring = Averaging = Integrating ; Sharpening = Differentiation

➢ Image differentiation enhances edges & other discontinuities


including noise.

➢ Image differentiation for digital images can be considered as


differences between neighboring pixel values.

26
Conditions for the derivative function

1st Order Derivative

− must be zero in flat segments (areas of constant gray levels)


− must be nonzero at the onset of a gray level step or ramp
− must be nonzero along ramp

2nd Order Derivative

− must be zero in flat segments


− must be nonzero at the onset and end of gray level step or ramp
− must be zero along ramps of constant slope

27
Derivative of Digital Image

❖ For 1-D digital signal


1st Order Derivative
f
= f ( x − 1) − f ( x)
x

2nd Order Derivative


2 f
= f ( x + 1) + f ( x − 1) − 2 f ( x)
x 2

28
Derivative of Digital Image contd…

Ref. :- R. C. Gonzalez, and R. E. Woods, Digital Image Processing, Pearson


29
First Order Derivative : Gradient

For a function f(x,y)


f
f x = G x = = f ( x − 1, y ) − f ( x, y )
x

f
f y = G y = = f ( x, y − 1) − f ( x, y )
y

The Gradient of f at coordinates (x,y) is defined as 2-D column vector


 f 
Gx   x 
f =   =  
G y   f 
 y 

30
First Order Derivative : Gradient contd…

The Magnitude of this vector is

f = mag ( f )
= Gx 2 + G y 2
2
 f   f 
2

=   + 
 x   y 

To simplify the implementation, it is approximated as

f  G x + G y  Find the difference function first in x-direction


and then in y-direction.

31
Various Gradient Operators

Gradient Operator

-1 -1 1

Robert Cross Gradient Operator

-1 0 0 -1

0 1 1 0

32
Mask and their effects

Gx

-1

1 Gx + G y

Gy

-1 1

33
Mask and their effects

Gx

0 -1
Gx + G y
1 0

Gy
-1 0

0 1

34
Various Gradient Operators contd…

Prewitt Operator

-1 -1 -1 -1 0 1

0 0 0 -1 0 1

1 1 1 -1 0 1

35
Various Gradient Operators contd…

Sobel Operator

-1 -2 -1 -1 0 1

0 0 0 -2 0 2

1 2 1 -1 0 1

36
Example of Gradient Operators

37
Second Order Derivative : Laplacian

➢ These are Isotropic Filters or Rotation Invariant .

For a function f(x,y)


2 f 2 f
 f= 2 +
2

x y 2

For a digital image


2 f
= f ( x + 1, y ) + f ( x − 1, y ) − 2 f ( x, y )
x 2

2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y )
y 2

  2 f =  f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)  − 4 f ( x, y )

38
Second Order Derivative : Laplacian contd…

Laplacian Operator

0 1 0

1 -4 1

0 1 0

➢ It is isotropic for increments of 900 i.e. even if rotated by 900 doesn’t


change the result.

➢ Not effective on Diagonal Edges.

39
Mask and their effects

0 1 0

1 -4 1

0 1 0

40
Various Laplacian Operators

0 1 0 1 1 1

1 -4 1 1 -8 1

0 1 0 1 1 1

0 -1 0 -1 -1 -1

-1 4 -1 -1 8 -1

0 -1 0 -1 -1 -1

41
Example of Laplacian Filtering

0 0 0 0 0
0 -1 0 -15 -15 -15 0 0
-1 4 -1 15 15 30 -15 0
0 -1 0 0 0 15 -15 0
0 0 0 0 0
0 0 15 -15 0
0 0 0 0 0
15 15 15 0 0
15 15 15 0 0
0 0 0 0 0
15 15 15 0 0
-1 -1 -1 -45 -45 -30 -15 0

-1 8 -1 45 45 75 -30 0
-1 -1 -1 0 0 45 -45 0
0 0 45 -45 0

42
Image Sharpening using Laplacian Filter

➢ HPF highlights discontinuities at the cost of slowly varying gray levels,


producing images with grayish edge lines on a dark featureless
background

How do we recover background while still preserving sharpening effect ?

➢ Add the original image to Laplacian image


(if center coefficient is negative then subtract)

43
Image Sharpening using Laplacian Filter contd…

44
Image Sharpening using Laplacian Filter contd…

 f ( x, y ) −  2 f ( x, y ) if the center coefficient of the



 Laplacian mask is negative
g ( x, y ) = 
 f ( x, y ) +  f ( x, y )
2
if the center coefficient of the

 Laplacian mask is positive

if  2 f =  f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)  − 4 f ( x, y )
then g ( x, y ) = f ( x, y ) −  f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)  + 4 f ( x, y )
= 5 f ( x, y ) −  f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) 

0 -1 0

-1 5 -1  Composite Laplacian Mask


0 -1 0

45
Image Sharpening using Laplacian Filter contd…

0 1 0

1 -4 1

0 1 0

0 -1 0

-1 5 -1

0 -1 0

46
Image Sharpening using Laplacian Filter contd…

47
1st Order versus 2nd Order

1st Order Operators 2nd Order Operators


• Nonzero at the onset of a gray • Nonzero at the onset and end of
level step or ramp a gray level step or ramp
• Non-zero along the ramp • Zero along the ramp
• Produces thick edges • Produces finer edges
• Response at & around isolated • Response at & around isolated
points is much weaker points is much stronger i.e. it
can enhance fine details
(including noise) much more
• Have stronger response to step • “Double edge” effect (thin
double line) at step changes

48
High-Boost Filtering

➢ HPF removes average brightness while enhancing edges & gives a


darker appearance to the image

➢ High Boost consists of adding a portion of the original image to the


HPF image

49
High-Boost Filtering contd…

f hb ( x, y ) = ( A − 1) f ( x, y ) + f s ( x, y ) where A 1
and f s ( x, y ) = sharpened image

If image is sharpened with Laplacian


then
 A f ( x, y ) −  2 f ( x, y ) if the center coefficient of the

 Laplacian mask is negative
f hb ( x, y ) = 
 A f ( x , y ) +  2
f ( x, y ) if the center coefficient of the

 Laplacian mask is positive

50
High-Boost Filtering contd…

➢ If A = 1, then high-boost filtering is standard Laplacian sharpening

➢ As A increases, the contribution of the sharpening filter becomes less


and less important

➢ High-boost filtering helps in brightening the image

51
Various High-Boost Operators

0 -1 0 -1 -1 -1

-1 A+4 -1 -1 A+8 -1

0 -1 0 -1 -1 -1

52
Image Sharpening using High-Boost Filter contd…

53

You might also like