Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Lecture_06 Image Enhancement in Spatial Domain

The document presents a lecture on Image Enhancement in the Spatial Domain, focusing on local operations, spatial filtering techniques, and histogram processing. It covers various types of smoothing filters, including linear and non-linear methods, as well as the importance of handling border pixels and the application of histogram equalization for image enhancement. The lecture emphasizes the significance of neighborhood operations for improving image quality and detail enhancement.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture_06 Image Enhancement in Spatial Domain

The document presents a lecture on Image Enhancement in the Spatial Domain, focusing on local operations, spatial filtering techniques, and histogram processing. It covers various types of smoothing filters, including linear and non-linear methods, as well as the importance of handling border pixels and the application of histogram equalization for image enhancement. The lecture emphasizes the significance of neighborhood operations for improving image quality and detail enhancement.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Digital Image Processing

Lecture # 6
Image Enhancement in Spatial Domain- II
ALI JAVED

Lecturer

SOFTWARE ENGINEERING DEPARTMENT

U.E.T TAXILA

Email:: ali.javed@uettaxila.edu.pk

Office Room #:: 7


Presentation Outline
 Local/ Neighborhood Operations on images

 Local Enhancement through Spatial Filtering

 Smoothing Spatial Filtering

 Linear Filters
 Non-Linear Filters

 Linear Smoothing Spatial Filtering

 Average Filters
 Weighted Average Filters

 Non-Linear Smoothing Spatial Filtering

 Median Filters
 Minimum Filters
 Maximum Filters

 Border Pixel Treatment

 Image Histogram

 Histogram Equalization
Neighborhood Operations on Images
 Neighbourhood operations simply operate on a larger neighbourhood of
pixels than point operations

 Neighbourhoods are mostly selected a square regions around a central


pixel

 Any size and any shape filter are possible


Origin x

(x, y)
Neighbourhood

3/31/2011
y Image f (x, y)
Local Operations through Spatial Filtering
 The output intensity value at (x,y) depends not only on the
input intensity value at (x,y) but also on the specified
number of neighboring intensity values around (x,y)

 Spatial masks (also called window, filter, kernel,


template) are used and convolved over the entire image for
local enhancement (spatial filtering)

 The size of the mask determines the number of


neighboring pixels which influence the output
value at (x,y)

 The values (coefficients) of the mask determine the


nature and properties of enhancing technique

3/31/2011
Basics of Spatial Filtering

 Given the 3×3 mask with coefficients: w1, w2,…, w9


 The mask covers the pixels with gray levels: z1, z2,…, z9

 z gives the output intensity value for the processed


image (to be stored in a new array) at the location of z5 in
the input image

3/31/2011
Local Operations through Spatial Filtering
x
a b c r s t
d
g
e
h
f
i
* u
x
v
y
w
z
Original Image Filter
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i

 The above is repeated for every pixel in the original image to


generate the smoothed image

3/31/2011
Local Operations through Spatial Filtering

3/31/2011
Types of Spatial Filtering

3/31/2011
Spatial Filtering for Smoothing
 For blurring/noise reduction;

 Blurring is usually used in preprocessing steps, e.g., to remove


small details from an image prior to object extraction, or to bridge
small gaps in lines or curves

 Equivalent to Low-pass spatial filtering in frequency domain


because smaller (high frequency) details are removed based on
neighborhood averaging (averaging filters)

 Implementation:
 The simplest form of the spatial filter for averaging is a square
mask (assume m×m mask) with the same coefficients 1/m2 to
preserve the gray levels (averaging).

 Applications: Reduce noise; smooth false contours

 Side effect: Edge blurring

3/31/2011
Smoothing Spatial Filters
 One of the simplest spatial filtering operations we can
perform is a smoothing operation

 Simply average all of the pixels in a neighbourhood


around a central value

 Especially useful in removing noise from images

1/ 1/ 1/
9 9 9

1/ 1/ 1/
9 9 9

1/ 1/ 1/
9 9 9

Simple Averaging Filter 3/31/2011


Smoothing Spatial Filters
x
104 100 108

99 106 98

95 90 85
*
1/ 100
104
9
1/ 108
9
1/
9
Original Image
Simple 3*3 1/
99 1/ 1/
3*3 Smoothing Pixels
9 98
9 106 9
Neighbourhood 195
/9 190
/9 185
/9
Filter
e = 1/9*106 +
1/ *104 + 1/ *100 + 1/ *108 +
9 9 9
1/ *99 + 1/ *98 +
9 9
y 1/ *95 + 1/ *90 + 1/ *85
Image f (x, y) 9 9 9
= 98.3333
 The above is repeated for every pixel in the original image to
generate the smoothed image
3/31/2011
Spatial Filtering for Smoothing:: Example

3/31/2011
Spatial Filtering for Smoothing:: Example

3/31/2011
Weighted Smoothing Spatial Filters
 More effective smoothing filters can be generated by allowing
different pixels in the neighbourhood different weights in the
averaging function

 Pixels closer to the central pixel are more important

 Often referred to as a weighted averaging

1/ 2/ 1/
16 16 16

2/ 4/ 2/
16 16 16

1/ 2/ 1/
16 16 16

Weighted Averaging Filter 3/31/2011


Order Statistics Filtering
 Nonlinear spatial filters

 Output is based on order of gray levels in the masked area (sub-


image)

 Examples: Median filtering, Max & Min filtering

 Min: Set the pixel value to the minimum in the neighbourhood

 Max: Set the pixel value to the maximum in the


neighbourhood

 Median: The median value of a set of numbers is the midpoint


value in that set (e.g. from the set [1, 7, 15, 18, 24] 15 is the
median). Sometimes the median works better than the average

3/31/2011
Order Statistics Filtering
Median Filtering
 Assigns the mid value of all the gray levels in the mask to the
center of mask;

 Particularly effective when

 the noise pattern consists of strong, spiky components ( salt-


and-pepper)

 edges are to be preserved

 Force points with distinct gray levels to be more like their


neighbors

3/31/2011
Order Statistics Filtering

3/31/2011
Order Statistics Filtering
Minimum Filtering
 Assigns the minimum value of all the gray levels in the mask to the center
of mask;

 Particularly effective when

 Only Salt noise is present

Maximum Filtering
 Assigns the maximum value of all the gray levels in the mask to the center
of mask;

 Particularly effective when

 Only Pepper noise is present

 Edges are to be preserved

 Force points with distinct gray levels to be more like their neighbors
3/31/2011
Order Statistics Filtering

3/31/2011
Strange Things Happen At The Edges!
 At the edges of an image we are missing pixels to form a
neighbourhood

Origin x
e e

e e e
y Image f (x, y) 3/31/2011
Border Pixels Treatment
 Mask operation near the image border

 Problem arises when part of the mask is located outside the


image plane; to handle the problem:

 Truncate the image

 Discard the problem pixels (e.g. 512x512 input 510x510 output, if


mask size is 3x3)

 Image Padding

 expand the input image by padding zeros or 255


(512x512 input 514x514output)

 Image padding is not good; creates artificial lines or edges on the


border
3/31/2011
Border Pixels Treatment
 Replicate border pixels

 We normally use the gray levels of border pixels to fill up the expanded
region (for 3x3 mask). For larger masks a border region equal to half of the
mask size is mirrored on the expanded region.

3/31/2011
Histogram
 The histogram of an image represents the frequency of pixels in an image

 The histogram of an image shows the distribution of gray levels in the


image

 Massively useful in image processing especially in image segmentation

 Histogram of an image with gray level (0 to L-1):

 How to obtain histogram?

 For B bit image, initialize 2^B counters with 0


 Loop over all pixels x,y
 When encouraging gray level f(x,y)=I, increment counter # i
Histogram : Example
Histogram : Example
 A selection of images and their Histograms

 Note that the high contrast image has the most evenly spaced histogram

 Histograms of low contrast images are located in certain portions and not in
the entire gray scale range
Histogram Equalization
 The idea is to find a transformation s=T(r) to be applied to each pixel of the
input image f(x,y) such that a uniform distribution of gray levels in the entire
range results for the output image g(x,y)
Histogram Equalization
 Spreading out the frequencies in an image (or equalising the
image) is a simple way to improve dark or washed out images

 The formula for histogram equalisation is given where

sk  T (rk )
 rk: input intensity
 sk: processed intensity
 k: the intensity (e.g 0.0 – 1.0)
k
  pr ( r j )
 nj: the frequency of intensity j
 n: the sum of all frequencies
j 1
k nj

j 1 n
Histogram Equalization: Example
Histogram Equalization: Example

Initial Image Image After Equalization

Notice that the minimum value (52) is now 0 and the maximum value (154) is now 255.
Histogram Equalization: Example
Histogram Equalization: Example

No. of pixels

6
2 3 3 2 5

4 2 4 3 4

3
3 2 3 5
2
2 4 2 4
1
Gray level
4x4 image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9]
histogram
Histogram Equalization: Example
Gray
0 1 2 3 4 5 6 7 8 9
Level(j)

No. of 0 0 6 5 4 1 0 0 0 0
pixels

0 0 6 11 15 16 16 16 16 16

k nj 6 11 15 16 16 16 16 16
s 0 0 / / / / / / / /
j 1 n 16 16 16 16 16 16 16 16

3.3 6.1 8.4


sx9 0 0 9 9 9 9 9
3 6 8
Histogram Equalization: Example

No. of pixels

6
3 6 6 3 5

8 3 8 6 4

3
6 3 6 9
2
3 8 3 8
1
Output image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level
Equalized histogram
Local Enhancement through Histogram Processing

 The histogram processing methods discussed earlier are global in


the sense that pixels are modified by a transformation function
based on the gray level content of the entire image

 Although this global approach is suitable for overall enhancement.


There are cases in which it is necessary to enhance details over
small areas in the image

 The histogram equalization can be easily adapted to local


enhancement

 The procedure is to define a 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 then histogram transformation function is
obtained

3/31/2011
Local Enhancement through Histogram Processing

 Map the intensity of the pixel centered in the neighborhood

 Move to the next location and repeat the procedure

3/31/2011
Use of Histogram Statistics for Image Enhancement

Average Intensity

L 1
m   ri p(ri )
M 1 N 1
1

MN
  f ( x, y )
x 0 y 0
i 0

Variance
M 1 N 1
1
    f ( x, y)  m
2

MN x 0 y 0

3/31/2011
Use of Histogram Statistics for Image Enhancement

Local average intensity


L 1
msxy   ri psxy (ri )
i 0

sxy denotes a neighborhood


Local variance
L 1
 2
s xy   (ri  msxy ) 2 psxy (ri )
i 0

 The following statistical conditions are used here for enhancement

 g(x,y) = { E.f(x,y) if mSxy <= k0MG AND k1DG <= <= k2DG }

 g(x,y) = f(x,y) otherwise


3/31/2011
Use of Histogram Statistics for Image Enhancement

3/31/2011
Any question

You might also like