Image Enhancement in Spatial Domain

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 43

Image Enhancement in Spatial Domain

Local enhancement using statistical parameters from


histogram

Local enhancement can be based on statistical properties of the gray


levels in a block instead of using full histogram

Examples:
• Mean gives the average brightness of the image
• Variance (σ2) and its square root the standard deviation gives the
deviation of intensities on average from the mean value (average
contrast)
Local enhancement using statistical parameters

Sxy : a neighborhood (subimage) of size NSxy; a block centered at


(x,y)
: gray-level mean in Sxy

: gray-level variance in Sxy

: standard deviation, square root of variance

MG : global mean of f(x,y)

DG : global standard deviation of f(x,y)


Local enhancement using statistical parameters

The statistical parameters can be used in various ways:


• For the direct calculation of transformation function (adaptive
transformation function) for example

where is the local gain factor,

• Using them in defining ranges for different transfer functions for


example

where E, k0, k1, k2, are specified parameters


Local enhancement with adaptive transformation function

Original moon image Image enhanced using Histogram equalized


adaptive transformation image
window size: 15x15, k = 0.5
Local enhancement using statistical parameters

Defining ranges for different transformation functions


Local enhancement using statistical parameters

Image formed from the Image formed from the Image formed from the
local means local standard deviations multiplication constants
selected for different
mean/std ranges

E = 4.0, k0 = 0.4, k1 = 0.02, and k2 = 0.4,


Local enhancement using statistical parameters

Input microscopic image Enhanced output image


Mathematical/logical operations on images

• Addition
– Averaging images for noise removal

• Subtraction
– Removal of background from images
– Image enhancement
– Image matching
– Moving/displaced object tracking

• Multiplication
– Superimposing texture on an image
– Convolution and correlation of images

• And, Or operations
– To remove the unnecessary area of an image through mask
operations
Image averaging for noise reduction

A noisy image can be represented by

where denotes the noise in the image

The noise is random and the content is fixed

The noise can be removed by taking more noisy images of the same
object and averaging them out
Image averaging for noise reduction

Original image Noisy image

Result of Using 16 noise


averaging using samples Using 64 noise Using 128 noise
8 noise samples samples samples
Image averaging for noise reduction

Noisy image

Noise
reduction by
averaging
256 samples
Examples of image subtraction

Original image Image after moving one coin

Difference image after


pixel by pixel subtraction
of second image from first
image
Examples of image subtraction

Difference of images from quality control: a missing chip in PCB is detected


by subtracting the master image from image of each sample
Examples of image Multiplication

Multiplication of images can be used for superimposing texture on


an image

Smooth spherical surface Texture to be


output image
image superimposed
Example of logical operations using masks
Local enhancement 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 masks 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
Local enhancement through spatial filtering

The mechanics of spatial


filtering
For an image of size M x N and
a mask of size m x n,
The resulting output gray level
for any coordinates x and y is
given by
Basics of spatial filtering

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


• The mask cover 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
Basics of spatial filtering

Mask operation near the image border


Problem arises when part of the mask is located outside the image plane;
to handle the problem:
1. Discard the problem pixels (e.g. 512x512 input 510x510output if mask size
is 3x3)
2. Zero padding: expand the input image by padding zeros (512x512 input
514x514output)
– Zero padding is not good, it creates artificial lines or edges on the
border;
3. 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.
Mask operation near the image border
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


Smoothing filters
Spatial filtering for Smoothing (example)
Spatial filtering for Smoothing (example)

Original image Smoothed by


size: 500 x 500 3 x 3 box filter

Smoothed by Smoothed by
5 x 5 box filter 9 x 9 box filter

Smoothed by Smoothed by
15 x 15 box filter 35 x 35 box filter
Spatial filtering for Smoothing (example)
Order Statistics Filters

• Non-linear spatial-filters

• Median Filters: The pixels contained in the image area


encompassed by the filter are ordered and then the value
of the center pixel is replaced with the median value.

• Median Filters are useful to remove the random noise (i.e.


impulse noise) and provide less blurring than linear
smoothing filter of the same size.

• The principal function of median filters is to force points


with distinct gray levels to be more like their neighbors.
• Max Filters:
– The Median replaces the 50th percentile of a ranked set
of numbers but if 100th percentile is used then it gives
max filter.
– Max filter is useful to find the brightest points in an
image.
• In general Median Filtering is much better suited than
averaging for the removal of additive impulse/salt and
pepper noise.
Sharpening Spatial Filters

• Sharpening is used to highlight fine detail in an image or to


enhance detail that has been blurred.
• Averaging is analogous to Integration, sharpening can be
accomplished by spatial differentiation.
• The strength of the response of derivative operator is
proportional to the degree of discontinuity of the image at the
point at which the operator is applied.
• Image differentiation enhances edges and other discontinuities
(such as noise) and de-emphasizes areas with slowly varying
gray-level values.
Sharpening Spatial Filters

• First Derivative Filters: Any definition we use for the first


derivative must fulfill the following conditions:

– Must be zero in flat segments (areas of constant gray-level


values)

– Must be non-zero at the onset of a gray-level step or ramp

– Must be non-zero along ramps


Sharpening Spatial Filters

• Second Derivative Filters: Any definition we use for the second


derivative must fulfill the following conditions:

– Must be zero in flat segments (areas of constant gray-level


values)

– Must be non-zero at the onset of a gray-level step or ramp

– Must be zero along ramps of constant slope


Sharpening Spatial Filters

• A basic definition of first order derivative of a 1-D function


f(x) is:

• A second order derivative of a 1-D function f(x) can be given as:

04/13/2023 33
Sharpening Spatial Filters

04/13/2023 34
Sharpening Spatial Filters

• First order derivatives generally produce thicker edges in an


image
• Second order derivatives have a stronger response to fine detail
such as thin lines and isolated points
• First order derivatives generally have a stronger response to a
gray-level step
• Second order derivatives produce a double response at step
changes in gray level.
• Mostly, the second order derivative is better suited than first
order derivative for image enhancement because of the ability
of the former to enhance fine details.
• Principal use of first derivatives in image processing is for edge
extraction.
Use of Second Derivatives for Enhancement-The
Laplacian

• We want to develop an Isotropic Filter whose response is


independent of the direction of the discontinuities in the image
to which the filter is applied.
• Isotropic Filters are rotation invariant i.e. rotation of image
does not affect the outcomes.
• The simplest isotropic derivative operator is Laplacian.
• For a function/image f(x,y) of two variables it can be defined as:
Use of Second Derivatives for Enhancement-The Laplacian

• Derivatives of any order are linear operations so Laplacian is a


linear operator.
• There are different ways to define a digital Laplacian using
neighborhoods but the properties of second derivatives must be
satisfied.
• Let’s have two variables then the notation for the partial
second-order derivative in the x-direction can be given as:
Use of Second Derivatives for Enhancement-The Laplacian

• Similarly in the y-direction,as

• The digital implementation of 2-D Laplacian is obtained by


summing these two components
Use of Second Derivatives for Enhancement-The Laplacian

• The following mask is an implementation of this equation:


Use of Second Derivatives for Enhancement-The Laplacian

• The diagonal directions can be incorporated by the following


mask:
Use of Second Derivatives for Enhancement-The Laplacian

Because the Laplacian is a derivative operator, its use highlights


gray-level discontinuities in an image and deemphasizes the
regions with slowly varying gray levels.
• This will produce images that have grayish edge lines and other
discontinuities, all superimposed on a dark, featureless
background.
• Background features can be recovered while still preserving the
sharpening effect of the Laplacian operation by adding
/subtracting the original and Laplacian images.
Use of Second Derivatives for Enhancement-The Laplacian

• Assignment:

– Suggest a simplified mask for the implementation


of Laplacian.
Ref: Pages 153-154
Use of Second Derivatives for Enhancement-The Laplacian

You might also like