0% found this document useful (0 votes)
66 views148 pages

CGIP - Mod5ppt1 (Autosaved)

Module 5 of CST 304 covers image enhancement techniques in the spatial domain and image segmentation methods, including gray level transformations, contrast stretching, and histogram equalization. It discusses various image enhancement methods such as spatial domain and frequency domain techniques, along with specific transformations like log and power-law transformations. Additionally, it explains the significance of histograms in image processing and the processes of histogram stretching and equalization for improving image contrast.

Uploaded by

boxabhi2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views148 pages

CGIP - Mod5ppt1 (Autosaved)

Module 5 of CST 304 covers image enhancement techniques in the spatial domain and image segmentation methods, including gray level transformations, contrast stretching, and histogram equalization. It discusses various image enhancement methods such as spatial domain and frequency domain techniques, along with specific transformations like log and power-law transformations. Additionally, it explains the significance of histograms in image processing and the processes of histogram stretching and equalization for improving image contrast.

Uploaded by

boxabhi2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 148

CST 304

Computer Graphics & Image Processing


Module - 5 Part-1

(Image Enhancement in Spatial Domain and Image


Segmentation)
Image segmentation
https://www.ece.uvic.ca › ~aalbu ›

https://www.dynamsoft.com/blog/insights/image-processing/
image-processing-101-image-enhancement/
Module - 5 (Image Enhancement in Spatial Domain and Image
Segmentation)
 Basic gray level transformation functions - Log transformations, Power-
Law transformations
 Contrast stretching. Histogram equalization. Basics of spatial filtering -
Smoothing spatial filter-Linear and nonlinear filters, and Sharpening
spatial filters-Gradient and Laplacian.
 Fundamentals of Image Segmentation. Thresholding - Basics of Intensity
thresholding and Global Thresholding. Region based Approach - Region
Growing, Region Splitting and Merging.
 Edge Detection - Edge Operators- Sobel and Prewitt.
Image Enhancement

 Image enhancement refers to the process of highlighting certain


information of an image or bring out details that are hidden, as well as
weakening or removing any unnecessary information according to specific
needs.
 Enhancement is to process an image so that the result is more suitable than
the
original image for a specific application.
 Enhancement techniques are so varied, and use so many different image
processing approaches
Useful examples of image enhancement

• Smooth and sharpen, Noise removal, Deblur images, Contrast adjustment,


Brighten an image, Grayscale image histogram equalization
Image Enhancement

• If 256 intensities of grayscale used, then: -


 In dark image the most of pixels value <128
 In bright image the most of pixels value >128
 Let x: old image S: new image
S = x+c where c is constant value
>> S=imadd(x,50); -----------------brighter image
 S = x-c where c is constant value
>> S=imsubtract(x,50); -------------darker image
 We can add 2 images :
S = x+y (where x and y are 2 images having same size)
Image Enhancement Methods
 Spatial Domain Methods (Image Plane)
Enhancement of the image space that divides an image into uniform
pixels according to the spatial coordinates with a particular resolution.
The spatial domain methods perform operations on pixels directly.
Techniques are based on direct manipulation of pixels in an image.
 Frequency Domain Methods
Enhancement obtained by applying the Fourier Transform to the spatial
domain. In the frequency domain, pixels are operated in groups as
well as indirectly. 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.
Spatial domain
• Spatial domain processes:
1. Intensity transformation(Point operation)
- Point operations refer to running the same conversion operation for
each pixel in a grayscale image. The transformation is based on the
original pixel and is independent of its location or neighboring pixels.
- g depends only on the value of f at (x,y)

2. Spatial filter (or mask, kernel, template or window)


• The output value depends on the values of f(x,y) and its
neighborhood.
Basic Intensity (Gray-level) transformations functions

Gray-level transformation function


s = T(r) s, r : denote the intensity of g and f at any point (x,y).
g(x,y) = T [ f(x,y) ]
where r is the gray level of f(x, y) and s is the gray level of g(x,y) at any point.
Here, T is called intensity transformation function or (mapping, gray level function)
In addition, T can operate on a set of input images.
Intensity transformations functions
Intensity transformation functions fall into 2 approaches:
1) Basic intensity transformations
• Linear Functions:
- Identity Transformation
- Negative Transformation
• Logarithmic Functions:
- Log Transformation
- Inverse-log Transformation
• Power-Law Functions:
- nth power transformation
- nth root transformation
2) Piecewise Linear transformation functions
• Contrast stretching, thresholding
• Gray-level slicing
• Bit-plane slicing
Identity Transformation

• Output intensities are identical to input intensities


• - This function doesn’t have an effect on an image, it was included in
the graph
only for completeness
• - Its expression: s=r
Negative transformation
• If r be the gray-level of image before processing and s after
processing then for the gray-level in the range [0, L-1], the
expression
s = (L – 1) – r defines the negative transformation.
• Negative transformation reverses the intensity levels in the image
and produces an equivalent photographic negative.
• So, well suited for enhancing an image with white and gray detail
embedded in dark regions of the image, especially when there is
more black area in the image.
Negative transformation
• Image negatives s = (L – 1) –
• Enhance white orr gray details
Log transformation
• The expression for log transformation is given as:
s = c log (1 + r), c is a constant and r ≥ 0.
• It helps to obtain the negative of an image for the gray-level in the range
[0, L-1].
• Log transformation derives a narrow range of gray-level values in input
image to wider range of gray-levels in the output image.
• Use these transformations to expand the values of dark pixels in an
image while compressing the higher level values
• The log transformation compresses the dynamic range of images with
large variations in pixel values
• Log functions are particularly useful when the input grey level values may
have an extremely large range of values
• So the given range turns to 0 to approximate 7, which is easily
displayable with 8-bit display.
Log transformation
• From the range 0 to 1.5 x 10^6 to the range 0 to 6.2
Inverse-Log transformation
• The inverse-log is applied for the opposite to the log
transformations.
• Used to expand the values of high pixels in an image while
compressing the darker-level values.
Power-law transformation
 The expression for power-law transformation is given as:
s = crᵞ, c and ᵞ are positive constants
 For c = ᵞ = 1 the power-law transformations s = crᵞ becomes s = r that is
an identity transformations.
 The exponent used in power-law transformation is called gamma. So, using
the ᵞ value, either ᵞ < 1 or ᵞ > 1, various responses are
obtained.
 Power law curves with fractional values of y 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 gray levels. Different transformation curves
are obtained by varying ᵞ (gamma)
 Gamma correction is the process to correct power-law transformation
response phenomena.
 power-law transformations are much more versatile for
spreading/compressing of gray levels in an image than the log
Gamma correction
• A 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 phenomenon is called gamma correction.
• For eg- CRT devices have intensity to voltage response that is a power
function. In such devices output appears darker than input. So, gamma
correction is a must in this case.
• Gamma correction is important if 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. Color phenomenon also uses this
concept of gamma correction.
• It is becoming more popular due to use of images over the internet. It is
important in general purpose contrast manipulation.
• y>1 black image and y<1 for white image.
• If gamma <1 : the mapping is weighted toward brighter output values.
• If gamma =1 (default): the mapping is linear.
• If gamma >1 : the mapping is weighted toward darker output values.
Power-law transformation
Power-law transformation
• Monitor,
 2.5
Power-law transformation
Some Basic Gray Level Transformations
Piece-wise linear transformation functions
Advantage
• These piecewise linear functions can be arbitrarily complex.
• practical implementation of some important transformations can be
formulated only as piecewise functions.
Disadvantage
• their specification requires considerably more user input.

(i) Contrast Stretching:


• It is the simplest piecewise linear transformation function.
• We may have various low contrast images and that might result due to
various reasons such as lack of illumination, problem in imaging sensor or
wrong setting of lens aperture during image acquisition.
• The idea behind contrast stretching is to increase the dynamic range of
gray levels in the image being processed.
Contrast Stretching

Contrast Stretching (a) Form of Transformation function (b) A low-contrast image


(c) Result of contrast stretching (d) Result of thresholding.
Contrast Stretching

The location of points (r1,s1) and (r2,s2) controls the shape of the curve.
a) If r1 = r2 and s1 = s2, the transformation is a linear function that deduces no
change in gray levels.
b) If r1 = s1, s1 = 0 , and s2 = L-1, then the transformation becomes a thresholding
function that creates a binary image
c) Intermediate values of (r1, s1) and (r2, s2) produce various degrees of spread
in the gray value of the output image thus effecting its contrast.
Generally r1≤ r2 and s1≤ s2 so that the function is single valued and monotonically
increasing.
This condition preserves the order of gray levels, thus preventing the creation of
intensity artifacts in the processed image.
Contrast Stretching

• If T(r) has the form as shown in the figure


below, 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
Contrast Stretching

Assume that
a: rmin , b: rmax

Contrast stretching:
(r1,s1)=(rmin, 0)
(r2,s2)=(rmax, L-1)
Contrast Stretching

• Example: in the graph, suppose we have the


following intensities : a=90, b=180, m=100
• If r is above 180 ,it becomes 255 in s.
• If r is below 90 , it becomes 0,
• If r is between 90, 180 , T applies as follows:
• when r < 100, s closes to zero(darker)
• when r>100, s closes to 255 (brighter)

This is called contrast stretching, which means that


the bright pixels in the image will become brighter
and the dark pixels will become darker, this means :
higher contrast image.
Contrast Stretching
• The function takes the form of:

• Where r represents the intensities of the input image, s the


corresponding intensity values in the output image, and E controls the
slope of the function.
• Notice that the intensity transformation function T, made the pixels with
dark intensities darker and the bright ones even more brighter, this is
called contrast stretching
Gray level histogram
• In Statistics, Histogram is a graphical
representation showing a visual
impression of the distribution of data.
• An Image Histogram is a type of
histogram that acts as a graphical
representation of the lightness/color
distribution in a digital image.
• It plots the number of pixels for each
intensity value.
• Histogram of images provide a global
description of their appearance.
• Histogram of an image represents
relative frequency of occurrence of
various gray levels.
Gray level histogram
• Histogram can be plotted in two ways:
• First Method:
• X-axis has Gray levels & Y-axis has No. of pixels in each gray levels.
• The histogram of a digital image with gray 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 r k.
Gray level histogram
• Second Method:
• common practice to normalize a histogram
• X-axis has gray levels & Y-axis has probability of occurrence of gray
levels.
P(μk) = nk/ n
μk – gray level,
nk–no. of pixels in kth gray level,
n –total number of pixels in an image
• sum of all components of a normalized histogram is equal to 1.
• Advantage of 2nd method: Maximum value plotted will always be 1.
• White–1, Black–0.
Gray level histogram
• Different images can have same histogram
• 3 images below have same histogram
• Half of pixels are gray, half are white, so Same histogram = same
statisics
• Can we reconstruct image from histogram? No !
Gray level histogram

Why Histograms?

• Histograms are the basis for numerous spatial domain processing


techniques
• Histogram 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.
Gray level histogram
Types of Histograms
Gray level histogram
Types of Histograms
• In dark Image the components of the histogram are concentrated on the low
(dark) side of gray scale
• The components of the histogram of the bright image are biased toward the
high side of gray scale.
• A low contrast image histogram will be narrow and centered towards the
middle of the gray scale.
• Components of the histogram in the high-contrast image cover a broad
range of the gray scale and, further, that the distribution of pixels is not too
far from uniform, with very few vertical lines being much higher than the
others.
• It is reasonable to conclude that an image whose pixels tend to occupy the
entire range of possible gray levels and, in addition, tend to be distributed
uniformly, will have an appearance of high contrast and will exhibit a large
variety of gray tones. The last graph is the best image; a high contrast image.
• Aim is to transform the first 3 histograms into the 4th type. That is try to
Gray level histogram
Histogram Processing

• There are two methods of enhancing contrast.


 Histogram Stretching

 Histogram Equalization
Histogram Processing - Histogram Stretching
• Process of histogram stretching increases the dynamic range of the image and hence improves
the contrast of the image.
• In this process, the basic shape of the histogram is not modified, but the entire range of image
of histogram values is stretched.
• Before stretching process, it is necessary to specify the upper and lower limits for pixels of
normalized range.
• Limit values depends on type of image. (eg: 8 bit image ,limit values ranges between 0 & 255)
• Simplest histogram function: S = T(r) = ((Smax-Smin) / (rmax-rmin)) (r - rmin) +
Smin

Smax– maximum limit value of image,


Smin– minimum limit value of image,
rmax– highest pixel value of image,
rmin– lowest pixel value of image
Histogram Processing - Histogram Stretching
Histogram Processing - Histogram Stretching
Histogram Processing - Histogram Equalization
•Equalization is a process that attempts to spread out the gray levels in
an image so that they are evenly distributed across their range.
•It reassigns the brightness values of pixels based on image histogram.
•The histogram of resultant image is made as flat as possible.
•Provides more visually pleasing results across a wide range of images.
•Steps to perform Histogram Equalization:-
 Find the running sum of histogram values.
 Normalise the values from step1 by dividing by the total number of
pixels
 Multiply the values from step 2 by the maximum gray level value and
round
 Map the gray level values to the results from step 3 using a one to one
correspondence.
Histogram Processing - Histogram Equalization
•Example:
Q. Perform histogram equalization of the image.

•Maximum value is found to be 5. We need a minimum of 3 bits to represent


the number.
•There are 8 possible gray levels from 0 to 7
•Histogram of input image:-
Histogram Processing - Histogram Equalization
Step1: Compute the running sum of histogram values.
• Running sum is otherwise known as Cumulative Frequency
Distribution(CFD).
Histogram Processing - Histogram Equalization
Step 2 : Divide the running sum obtained in step1 by the total number
of pixels
(which is 25 in this case).
Histogram Processing - Histogram Equalization
Step3: Multiply the values from step 2 by the maximum gray level value
(which is 7 in this case). The result is then rounded to closest
integer.
Histogram Processing - Histogram Equalization
Step 4: Map the gray level values to the results from step 3 using a one
to one
correspondence
Tutorial :- Histogram Equalization
Tutorial :- Histogram Equalization
Edge Detection
Edge
• Sudden changes or discontinuities in an image are called as edges.
• Significant transitions in an image are called as edges
• Edges are significant local changes of intensity in an image.
Edge
Edge Detection

• Edge detection - An image processing technique for finding


the boundaries of objects within images
• It works by detecting discontinuities in brightness
• Used for image segmentation and data extraction in areas like
image processing, computer vision, etc.
• Generally edges are of three types:
• Horizontal Edges
• Vertical Edges
• Diagonal Edges
Edge Detection

Edge detection methods


• Prewitt Operator
• Sobel Operator
• Roberts Operator

• All these masks find edges. Some find horizontally and


vertically, some find in one direction only and some find in all
the directions.
Edge Detection
Gradient based Edge detection methods
• Prewitt Operator : Prewitt operator is used for detecting edges
horizontally and vertically.
• Sobel Operator: The Sobel operator is very similar to Prewitt
operator. It is also a derivate mask which calculates edges in
both horizontal and vertical direction.
• Roberts Operator: This method is based on differences between
adjacent pixels. Here +1 and -1 are explicitly used to find the
edges. The difference is called as forward differences.
Edge Detection
Prewitt Operator
•It detects two types of edges: Horizontal edges & Vertical Edges
•Edges are calculated by using difference between corresponding
pixel intensities of an image.
•Changes in a image can only be calculated using differentiation.
So these operators are also called as derivative operators or
derivative masks.
•All the derivative masks should have the following properties:
•Opposite sign should be present in the mask.
•Sum of mask should be equal to zero.
•More weight means more edge detection.
•Prewitt operator provides us two masks one for detecting edges
in horizontal direction and another for detecting edges in an
vertical direction.
Edge Detection • When you will convolve this mask on an image,
Prewitt it will give you the vertical edges in an image.
Operator
• Vertical • When we apply this mask on the image it
direction prominent vertical edges.
• It simply works like as first order derivate and
calculates the difference of pixel intensities in
a edge region.
• As the center column is of zero so it does not
include the original values of an image but
rather it calculates the difference of right and
left pixel values around that edge.
• This increase the edge intensity and it become
enhanced comparatively to the original image.
• Above mask will find the edges in vertical
direction and it is because the zeros column in
the vertical direction.
Edge Detection • Above mask will find edges in horizontal direction
because the column of zeros is in horizontal
Prewitt Operator direction.
• Horizontal
direction • When you will convolve this mask onto an image
it would prominent horizontal edges in the image.
• As the center row of mask consists of zeros, it
does not include the original values of edge in the
image but rather it calculates the difference of
above and below pixel intensities of the particular
edge.
• Thus increasing the sudden change of intensities
and making the edge more visible.
• In the picture on which we apply vertical mask, all
the vertical edges are more visible than the
original image.
• Similarly in the picture which we apply the
horizontal mask ,all the horizontal edges are
visible.
Edge Detection
Prewitt
Operator
Edge Detection
Sobel operator
• Very similar to Prewitt operator.
• also detects two types of edges: Horizontal edges & Vertical Edges
• Edges are calculated by using difference between corresponding pixel
intensities of an image.
• Major difference is that in Sobel operator the coefficients of masks are not
fixed and they can be adjusted according to our requirement unless they
do not violate any property of derivative masks.
• provides us two masks one for detecting edges in horizontal direction and
another for detecting edges in an vertical direction.
Edge Detection • This mask works exactly same as the Prewitt
operator vertical mask.
Sobel
• There is only one difference that is it has “2”
operator and “-2” values in center of first and third
• Vertical column.
direction
• This give more weightage to the pixel values
around the edge region. This increase the
edge intensity and it become enhanced
comparatively to the original image.
• When applied on an image this mask will
highlight the vertical edges.
• It simply works like as first order derivate and
calculates the difference of pixel intensities in
a edge region.
• As the center column is of zero so it does not
include the original values of an image but
rather it calculates the difference of right and
Edge Detection •Above mask will find edges in horizontal direction
and it is because that zeros column is in
Sobel operator horizontal direction. On convolving this mask
• Horizontal onto an image it would prominent horizontal
edges in the image.
direction
•The only difference between it is that it have 2
and -2 as a center element of first and third row.
•As the center row of mask is consist of zeros so it
does not include the original values of edge in
the image but rather it calculate the difference of
above and below pixel intensities of the
particular edge. Thus increasing the sudden
change of intensities and making the edge more
visible.
•Also if you compare the result of sobel operator
with Prewitt operator, you will find that sobel
operator finds more edges or make edges more
visible as compared to Prewitt Operator as more
weight has been allotted to the pixel intensities
around the edges.
Edge Detection
Sobel
operator
• there are no fixed coefficients in sobel operator, so here is another
weighted operator

• This will give out more edges as compared to previous mask because
we have allotted more weight in the mask.
Edge Detection
Roberts Cross
•operator
The Robert’s cross operator performs a simple, quick to compute edges on an
image.
• As a differential operator, the idea behind the Roberts cross operator is to
approximate the gradient of an image through discrete differentiation which is
achieved by computing the sum of the squares of the differences between
diagonally adjacent pixels.
• According to Roberts, an edge detector should have the following properties:
• the produced edges should be well-defined
• the background should contribute as little noise as possible
• the intensity of edges should correspond as close as possible to what a human
would
• With these criteria in mind Roberts proposed the following equations:
Edge Detection
Roberts Cross operator
• The results of this operation will highlight changes in intensity in a diagonal
direction.
• In order to perform edge detection with the Roberts operator, we first
convolve the original image, with the following 2x2 convolution masks Mx and
M y.

• One mask is simply the other rotated by 90 degrees. Thus the Robert’s cross
Edge Detection
Roberts Cross
operator
• Let I(x,y) be a point in the original image
Gx(x,y) be a point in an image formed by convolving with the first
kernel and
Gy(x,y) be a point in an image formed by convolving with the second
kernel.
• The gradient can then be defined as:

• Direction of gradient can then be defined as:


Neighborhood processing in spatial domain: Here, to modify one pixel,
values of the immediate neighboring pixels also considered. For this purpose,
3X3, 5X5, or 7X7 neighborhood mask can be considered.

Low Pass filtering: It is also known as the smoothing filter. It removes the
high-frequency content from the image. It is also used to blur an image.
High Pass Filtering: It eliminates low-frequency regions while retaining or
enhancing the high-frequency components
A high pass filtered image may be computed as the difference between the
original image and a low pass filtered version of that image as follows
High pass = Original – Low pass
Multiplying the original by an amplification factor yields a high boost or high
frequency-emphasis filter.

A high pass filtering mask is as shown.

Median Filtering: It is also known as nonlinear filtering. It is used to


eliminate salt and pepper noise. Here the pixel value is replaced by the
median value of the neighboring pixel.
SPATIAL CONVOLUTION AND CORRELATION
Spatial filtering
• Filtering refers to accepting(passing) or rejecting certain frequency
components. This effectively smoothens or sharpens the image.
• E.g. Low pass filter, high pass filter, etc.

• If the operation performed on the image pixels is linear, then the filter is
called a linear spatial filter, otherwise nonlinear.
Spatial Filters
Spatial filters can be classified by effect into:
Smoothing Spatial Filters: also called lowpass filters. They include:
Averaging linear filters
Order-statistics nonlinear filters.
Sharpening Spatial Filters: also called highpass filters.
Laplacian linear filters.
Spatial Filters
Smoothing Spatial Filters
Used for blurring and for noise reduction.
Blurring is used in preprocessing steps to:
 remove small details from an image prior to (large) object extraction
 bridge small gaps in lines or curves.
Noise reduction can be accomplished by blurring with a linear filter and also
by nonlinear filtering.
Averaging Linear Filters
The response of averaging filter is simply the average of the pixels
contained in the neighborhood of the filter mask.
The output of averaging filters is a smoothed image with reduced "sharp"
transitions in gray levels.
Noise and edges consist of sharp transitions in gray levels. Thus smoothing
filters are used for noise reduction; however, they have the undesirable side
effect that they blur edges.
Linear Spatial Filtering (Convolution)
The process consists of moving the filter mask from pixel to pixel in an image. At each
pixel (x,y), the response is given by a sum of products of the filter coefficients and the
corresponding image pixels in the area spanned by the filter mask.
For the 3×3 mask shown in the previous figure, the result (or response), R, of linear
filtering is:

In general, linear filtering of an image f of size M× N with a filter mask of size m× n is


given by the expression:

where a = (m - 1)/2 and b = (n - l)/2. To generate a complete filtered image this


equation must be applied for x = 0,1, 2,..., M-1 and y = 0,1, 2,..., N-1.
Nonlinear Spatial Filtering

 This operation also consists of moving the filter mask from pixel to pixel
in an image.
 The filtering operation is based conditionally on the values of the pixels
in the neighborhood, and they do not explicitly use coefficients in the
sum-of-products manner.
 For example, noise reduction can be achieved effectively with a
nonlinear filter whose basic function is to compute the median gray-level
value in the neighborhood in which the filter is located.
 Computation of the median is a nonlinear operation.
Linear Spatial Filtering
Use the following 3×3 mask to perform the convolution process on the shaded pixels in the
5×5 image below. Write the filtered image.
Spatial Filtering
Weighted Average Filter has different coefficients to give more importance (weight) to
some pixels at the expense of others. The idea behind that is to reduce blurring in the
smoothing process.

Averaging Linear Filtering of an image f of size M× N with a filter mask of size m×n is
given by the expression given here.
To generate a complete filtered image this equation must be applied for
x = 0,1, 2,..., M-1 and y = 0,1, 2,..., N-1.
Effects of Averaging linear filter
Averaging Linear Filter

Effects of averaging linear filter are:


 Blurring which is increased whenever the mask size increases.
 Blending (removing) small objects with the background. The
size of the mask establishes the relative size of the blended
objects.
 Black border because of padding the borders of the original
image.
 Reduced image quality.

Effects of median filter are:


1. Noise reduction
2. Less blurring than averaging linear filter
 Order-statistics filters
Nonlinear spatial filters whose response is based on ordering (ranking) the
pixels
contained in the neighborhood, and then replacing the value of the center pixel
with
the value determined by the ranking result.
Examples include Max, Min, and Median filters.
• Median filter: Computes the median gray-level value of the neighbourhood,
(noise reduction).
• Max filter: Used to find the brightest points in an image R=max{ z|k=1,2,...,9}
• Min filter: Used to find the dimmest points in an image R=min{ z|k=1,2,...,9}
Median filter
It replaces the value at the center by the median pixel value in the
neighborhood, (i.e. the middle element after they are sorted). Median filters are
particularly useful in removing impulse noise (also known as salt-and-pepper
noise).
Salt = 255, pepper = 0 gray levels.
In a 3×3 neighborhood the median is the 5th largest value, in a 5×5
neighborhood the 13th largest value, and so on.
Nonlinear Median Filter
Median
filter
Median
filter
Median
filter
Sharpening Spatial Filters
Sharpening aims to highlight fine details (e.g. edges) in an image, or
enhance detail that has been blurred through errors or imperfect
capturing devices.
Image blurring can be achieved using averaging filters, and hence
sharpening can be achieved by operators that invert averaging operators.
In mathematics, averaging is equivalent to the concept of integration, and
differentiation inverts integration. Thus, sharpening spatial filters can be
represented by partial derivatives.
Partial derivatives of digital functions

 The first derivative must be:


zero along flat segments (i.e. constant gray values).
non-zero at the outset of gray level step or ramp (edges or noise)
non-zero along segments of continuing changes (i.e. ramps).
Partial Derivatives

 The second derivative must be:


 zero along flat segments.
 nonzero at the outset and end of a gray-level step or ramp;
 zero along ramps of constant slope
Partial Derivatives
Partial Derivatives
Partial Derivatives

 Conclusion:
 1st derivative detects thick edges while 2nd derivative detects thin
edges.
 2nd derivative has much stronger response at gray-level step than 1st
derivative.
Thus, we can expect a second-order derivative to enhance fine details
(thin lines, edges, including noise) much more than a first-order
derivative.
The Laplacian
Filter

 Since the Laplacian filter is a linear spatial filter, it can be applied using the
same mechanism of the convolution process.
 This will produce a laplacian image that has 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 simply by adding the original and Laplacian
images.
 The main disadvantage of the Laplacian operator – it produces double edges.
The Laplacian Filter
The Laplacian Filter
SPATIAL CONVOLUTION AND CORRELATION
Correlation & Convolution
• Correlation & Convolution are two closely related concepts used in linear
spatial filtering.
• Both are used to extract information from images.
• Both are basically linear and shift invariant operations.
• Term linear indicates that a pixel is replaced by the linear combination of
its neighbours.
• Term shift variant means that same operations are performed at every
point in the image.
• Correlation: It is a process of moving a filter mask over an image &
computing the sum of products at each location.
• Convolution: mechanics are same, except that the filter is first rotated by
180 ̊.
SPATIAL CONVOLUTION AND CORRELATION
Spatial convolution

• Method which replaces a pixel with the weighted average of the pixel and
its neighbours of the convolution mask.
• Convolution is basically mathematical operation where each value in the
output is expressed as the sum of values in the input multiplied by a set of
weighting coefficients.
• An image can be either smoothened or sharpened by convolving the
image with respect to low pass and high pass filter respectively.
• Application areas - image filtering, image segmentation, feature extraction
etc.
The Mechanism of Linear Spatial Filtering
The Mechanism of Linear Spatial Filtering

W(-1,-1) W(-1,0) W(-1,1)

W(0,-1) W(0,0) W(0,1)

W(1,-1) W(1,0) W(1,1)


Linear Spatial Filtering
• For linear spatial filtering, the response is given by a sum of products of
the filter coefficients and the corresponding image pixels in the area
spanned by the filter mask. For the 3 X 3 mask shown in the previous
figure, the result (response), of linear filtering with the filter mask at a
point (x,y) in the image is:

g(x,y) = w (-1,-1) f(x-1, y-1) + w(-1,0) f (x-1, y) + … + w(0,0) f(x,y) + … +


w(1,0) f(x+1, y) + w(1,1) f(x+1, y+1)

which we see is the sum of products of the mask coefficients with the
corresponding pixels directly under the mask.
a b
g( x , y )= ∑ ∑ w ( s , t ) f ( x + s , y +t )
s=− a t=− b
Linear Spatial Filtering
Linear Spatial Filtering

• There are two closely related concepts that must be understood clearly
when performing linear spatial filtering.
• One is correlation; the other is convolution.
• Correlation is the process of passing the filter mask w by the image and
computing the sum of products at each location
• Mechanically, convolution is the same process, except that w is rotated by
180 degrees prior to passing it by f.
Exercise - Spatial convolution
Spatial Correlation
Spatial Convolution
Image Segmentation
Aim: To partition an image into a collection of set of pixels
– Meaningful regions (coherent objects)
– Linear structures (line, curve, …)
– Shapes (circles, ellipses,…)
Segmentation is an approach for Feature Extraction in an image
Features of Image: Points, lines, edges, corner points, regions, etc
Geometrical attributes: orientation, length, curvature, area, diameter, perimeter, etc
Topological attributes: overlap, adjacency, common end point, parallel, vertical, etc
Image Segmentation
Image Segmentation divides an image into regions that are connected and
have
some similarity within the region and some difference between adjacent
regions.
• The goal is usually to find individual objects in an image.
• For the most part there are fundamentally two kinds of approaches to
segmentation:
discontinuity and similarity.
– Similarity may be due to pixel intensity, color, texture, histogram, features
etc.
– Differences are sudden changes (discontinuities) in any of these, but
especially
sudden changes in intensity along a boundary line, which is called an edge.
Image Segmentation
Approaches in Image Segmentation
 Similarity approach: This approach is based on detecting similarity
between image pixels to form a segment, based on a threshold.
ML algorithms like clustering are based on this type of approach to
segment an
image.
 Discontinuity approach: This approach relies on the discontinuity of pixel
intensity values of the image.
Line, Point, and Edge Detection techniques use this type of approach for
obtaining intermediate segmentation results which can be later
processed to obtain the final segmented image.
Detection of Discontinuities
• There are three kinds of discontinuities of intensity: points, lines and
edges.
• The most common way to look for discontinuities is to scan a small mask
over
the image.
Detection of Discontinuities
Point Detection
where T : a nonnegative threshold
Detection of Discontinuities
Line Detection
Only slightly more common than point detection is to find a one pixel
wide line in an image.
• For digital images the only three point straight lines are
only horizontal, vertical, or diagonal (+ or –45°).
Detection of Discontinuities
Edge Detection - Gradient Operators
Detection of Discontinuities
Gradient Operators
Detection of Discontinuities
Gradient Operators
Detection of Discontinuities
Gradient Operators
Image Segmentation Techniques
 Threshold Based Segmentation
 Edge Based Segmentation
 Region-Based Segmentation
 Clustering Based Segmentation
 Artificial Neural Network Based Segmentation
Threshold Based Segmentation
 Image thresholding segmentation is a simple form of image
segmentation.
 It is a way to create a binary or multi-color image, based on setting a
threshold
value on the pixel intensity of the original image.
In this thresholding process:
• First consider the intensity histogram of all the pixels in the image.
• Then set a threshold to divide the image into sections.

Eg:- Considering image pixels ranging from 0 to 255, we set a threshold of


60.
So all the pixels with values less than or equal to 60 will be provided with a
value
of 0(black) and all the pixels with a value greater than 60 will be provided
with a
Thresholding
Assumptions:
1. the intensity values are different in different regions
2. within each region, which represents the corresponding object in a scene,
the intensity values are similar
3. the range of intensity levels covered by objects of interest is different
from the
background
Types of Thresholding

 Global or Fixed Thresholding:


A threshold value is selected where the threshold value depends only on
the pixel
intensities f(x,y) in the image. In fixed (or global) thresholding, the
threshold value
is held constant throughout the image.
 Dynamic or Adaptive or Local thresholding:
Threshold depends on pixel value and pixel position (both f(x,y) and p(x,y)-
Local
thresholding. So, the threshold for different pixels in the image will be
different.
The image is divided into overlapping sections which are thresholded
one by one.
If T depends on the spatial coordinates x and y, the threshold is called dynamic or
Basic Global Thresholding

Global Thresholding with T midway Global Thresholding with T


between the maximum and minimum estimated by iteration
gray levels
Intensity Thresholding
 Image Binarization applies often just one global threshold T for mapping a
Scalar image I into a Binary image.

 The global threshold can be identified by an optimization strategy aiming


at
creating “large” connected regions and at reducing the number of small‐
sized
regions (artifacts).

Thresholding
Thresholding
Thresholding

Advantages:
 Simple to implement
 Fast (especially if repeating on similar images)
 Good for some kinds of images (e.g., documents, controlled lighting)

Disadvantages:
 No guarantees of object coherency— may have holes, extraneous
pixels, etc.
 (incomplete) solution: post-processing with morphological operators
Region-Based Segmentation
• Edges and thresholds sometimes do not give good results for
segmentation.
• Region-based segmentation is based on the connectivity of similar
pixels in a region.
– Each region must be uniform.
– Connectivity of the pixels within the region is very important.
• There are two main approaches to region-based segmentation:
region growing and region splitting.
Region:
• A group of connected pixels with similar properties
• Closed boundaries
• Computation of regions is based on similarity
• Regions may correspond to objects in a scene or parts of objects
• Spatial proximity + Similarity
Note that a complete segmentation of an image must satisfy a number of criteria:
1) All pixels must be assigned to regions
2) Each pixel must belong to a single region only
3) Each region must be a connected set of pixels
4) Each region must be uniform
5) Any merged pair of adjacent regions must be non-­‐uniform
Region-Based Segmentation - Basic Formulation
Region Growing
 Thresholding still produces isolated image
• Region growing algorithms works on principle of similarity
• It states that a region is coherent if all the pixels of that region are
homogeneous
with respect to some characteristics such as colour, intensity, texture,
or other
statistical properties
• Thus idea is to pick a pixel inside a region of interest as a starting point
(also known as a seed point) and allowing it to grow
• Seed point is compared with its neighbours, and if the properties match,
they are
merged together
• This process is repeated till the regions converge to an extent that no
further
merging is possible
Region homogeneity

Examples of homogeneity criteria for region R:-


 difference between max and min grey-values in R is small
 difference between any pixel and mean grey-value in R is small
 variance of grey-values in R is small

Segmentation depends on:-


 properties used
 measure of similarity between properties
 similarity variation tolerance (threshold)
Region Growing Algorithm

• It is a process of grouping the pixels or subregions to get a bigger region


present
in an image.
• Selection of the initial seed: Initial seed that represent the ROI should be
given
typically by the user. Can be chosen automatically. The seeds can be
either single
or multiple.
• Seed growing criteria: Similarity criterion denotes the minimum difference
in the
grey levels or the average of the set of pixels. Thus, the initial seed ‘grows’
by
adding the neighbours if they share the same properties as the initial
Region Growing (Seeded
Segmentation)
Region-Based Segmentation

 Goal: find coherent (homogeneous) regions in the image


 Coherent regions contain pixels which share some similar property.

 Advantages:
Region-based techniques are generally better in noisy images (where
borders are
difficult to detect) It is difficult to segment the defects by thresholding
methods.

 Drawbacks:
 The output of region-growing techniques is either over segmented (too
many regions) or under segmented (too few regions).
 Can’t find objects that span multiple disconnected regions.
Region Merging algorithms
 START with an over segmented image
 Define a criterion for merging two adjacent regions
 Merge all adjacent regions satisfying the merging criterion
 STOP when no two regions can be merged
Region splitting is the opposite of region growing.
– First there is a large region (possible the entire image).
– Then a predicate (measurement) is used to determine if the region is
uniform.
– If not, then the method requires that the region be split into two
regions.
– Then each of these two regions is independently tested by the
predicate
(measurement).
– This procedure continues until all resulting regions are uniform.
• Region growing algorithm is slow
• So seed point can be extended to a seed region
• Instead of a single pixel, a node of a Regional Adjacency Graph (RAG) a
region
itself is now considered as a starting point.

 The split process can be stated as follows:


1) Segment the image into regions R1, R2,….Rn using a set of thresholds.
2) Create RAG. Use a similarity measure and formulate a homogeneity test.
3) The homogeneity test is designed based on the similarity criteria such as
intensity
or any image statistics.
4) Repeat step 3 until no further region exits that requires merging.
The main problem with region splitting is determining where to split a
region.
• One method to divide a region is to use a quadtree structure.
• Quadtree: a tree in which nodes have exactly four descendants.
• Entire image is assumed as a single region. Then the homogeneity test is
applied.
If the conditions are not met, then the regions are split into four quadrants.
• This process is repeated for each quadrant until all the regions meet the
required
homogeneity criteria. If the regions are too small, then the division process
is stopped.

1) Split and continue the subdivision process until some stopping criteria is
fulfilled.
The stopping criteria often occur at a stage where no further splitting is
possible.
2) Merge adjacent regions if the regions share any common criteria. Stop the
process
The Split and Merge procedure:
– Split into four disjoint quadrants any region Ri for which P(Ri) =
FALSE.
– Merge any adjacent regions Rj and Rk for which P(RjURk) = TRUE.
(the quadtree structure may not be preserved)
– Stop when no further merging or splitting is possible.
Split and merge algorithm
START: consider entire image as one region
1. If region satisfies homogeneity criteria, leave it unmodified
2. If not, split it into four quadrants and recursively apply 1 and 2 to each
newly generated region.
STOP when all regions in the quadtree satisfy the homogeneity criterion.
3. If any two adjacent regions Ri , Rj can be merged into a homogeneous
region, merge them.
STOP when no merging is possible any more.

You might also like