Lec 03
Lec 03
Lec 03
2
Spatial Domain Enhancement
• Here we can manipulate the pixels directly. There 2 types of this method:
• Intensity Transform – modification of intensity val 0
y
• Spatial Filtering – manipulation of spatial value is done with a mask.
Image f(x,y)
• Spatial domain function can be denoted as:
• g(x,y) = T{ f(x,y) }
• f(x,y) = input image on which transformation function has to be applied.
• g(x,y) = the output image or processed image.
• T is the transformation function or operator
(x,y)
x
• If we take a pixel at (x,y) then we can explore it neighbours and manipulate pixel
by pixel to carry on the spatial domain process.
• In simplest form, if we apply the operator T on neighbourhood of size 1×1.
3
Spatial Filtering
• Using a mask or 2D small array ,. e.g. 3×3 mask or filter or kernel or
template or window.
• Mask processing on filtering.
4
Image Transformation – Intensity Transformation Functions
• If we consider T as grey level transformation which is also known as intensity
transformation or mapping done on pixel by pixel.
• This relation between input image and the processed output image can be
represented as.
• s = T (r)
• where r is actually the pixel value or gray level intensity of f(x,y) at any point. And s is the pixel
value or gray level intensity of g(x,y) at any point.
• s => O/P image pixel value
• r => I/P image pixel value
• Look-up table technique
• – L LUT (L : # of gray levels, 2N)
• – s=LUT[r]
• – Filling LUT with T
5
Basic Intensity Transformation Functions
• Three basic types of functions used
frequently in image processing shown in
the figure3.3:
• linear (negative and identity transformations)
• The identity function is the trivial case in
which the input and output intensities are
identical. Its means no change in Image
• logarithmic (log and inverse-log
transformations),
• power-law (nth power and nth root
transformations).
6
Image Negatives
• The negative of an image with intensity levels in the range [0, L - 1] is obtained by
using the negative transformation function shown in Fig. 3.3, which has the form:
• s=L-1–r
• (0,1,2,…254,255)→(255,254,…,1,0)
• Reversing the intensity levels of a digital image in this manner produces the equivalent
of a photographic negative. This type of processing is used, for example,
• in enhancing white or gray detail embedded in dark regions of an image, especially when the black
areas are dominant in size
7
Log Transformations
• The general form of the log transformation in Fig. 3.3 is
• s = c log(1 + r)
• where c is a constant and it is assumed that r ≥ 0
• Any curve having the general shape of the log function shown in Fig. 3.3 would accomplish
spreading/compressing of intensity levels in an image.
• to expand the values of dark pixels in an image while compressing the higher-level values. (and vice
versa)
8
Power-Law (Gamma) Transformation
• Power-law transformations have the form
• s = crɣ
• where c and ɣ are positive constants.
Sometimes the equ. is written as s = c (r + e)ɣ
to account for offsets (that is, a measurable
output when the input is zero).
• ɣ> 1 represent nth power
• ɣ <1 represents nth root
• Compresses the dynamic range of the image
• the exponent is called gamma (g)
• gamma correction
• CRT monitors have an intensity to voltage response which is
a power-law with gamma 1.8-2.5
10
11
Piecewise-Linear Transformations - Contrast Stretching
• Low-contrast images can result from poor
illumination, lack of dynamic range in the imaging
sensor, or even the wrong setting of a lens
aperture during image acquisition.
• Contrast is the difference between the highest and
lowest grey level of an input image.
• Contrast stretching expands the range of intensity
levels in an image so that it spans the ideal full
intensity range of the recording medium or display
device.
• Making darker parts more darker and brighter parts
more brighter
• If r1 = s1 and r2 = s2 the transformation is a linear
function that produces no changes in intensity/
linear identity function
• If r1 = r2 = , s1 = 0, and s2 =L - 1 the
transformation becomes a thresholding function
that creates a binary image
• For intermediate values, spreading grey levels
• Generally, if 𝑟1 ≤ 𝑟2 and 𝑠1 ≤ 𝑠2, single valued
function will grow monotonically.
12
Intensity-Level Slicing
• There are applications in which it is of interest to highlight a specific range of
intensities in an image. Some of these applications include enhancing features in
satellite imagery, such as masses of water, and enhancing flaws in X-ray images.
• The method, called intensity-level slicing, can be implemented in several ways, but most are
variations of two basic themes.
• One approach is to display in one value (say, white) all the values in the range of interest and in another (say, black) all
other intensities. This transformation, shown in Fig. 3.11(a), produces a binary image.
• The second approach, based on the transformation in Fig. 3.11(b), brightens (or darkens) the desired range of
intensities, but leaves all other intensity levels in the image unchanged.
13
Intensity-Level Slicing-- Example
14
Bit-Plane Slicing
15
Histogram Processing– Histogram Equalization
• Visually represents the data
• In IP its used to process the data in an
digital image such as grey level values
• It can used to represent the relative
frequency of occurrence of various
grey level values.
• How many times a grey level value has
occur.
• Histogram manipulation is a
fundamental tool in image processing.
• Histograms are simple to compute and
are also suitable for fast hardware
implementations, thus making
histogram-based techniques a popular
tool for real-time image processing.
16
Example
17
18
Histogram Matching (Specification)
• The method used to generate images that have a specified histogram is called
histogram matching or histogram specification.
• HE is applied on whole image, but not necessary for some applications.
• Histogram matching gives us a processed image that has a specific histogram.
• Output image has a specific histogram which can be matched with a reference histogram.
19
Fundamentals of Spatial Filtering
• The name filter is borrowed from frequency domain processing where “filtering”
refers to passing, modifying, or rejecting specified frequency components of an
image.
• For example, a filter that passes low frequencies is called a lowpass filter.
• The net effect produced by a lowpass filter is to smooth an image by blurring it.
• We can accomplish similar smoothing directly on the image itself by using spatial filters.
• Spatial filtering modifies an image by replacing the value of each pixel by a
function of the values of the pixel and its neighbors.
• If the operation performed on the image pixels is linear, then the filter is called a linear
spatial filter. Otherwise, the filter is a nonlinear spatial filter.
20
Linear Spatial Filter
• A linear spatial filter performs a sum-of-products
operation between an image f and a filter kernel, w.
• The kernel is an array whose size defines the
neighborhood of operation, and whose coefficients
determine the nature of the filter.
• Other terms used to refer to a spatial filter kernel are
mask, template, and window. We use the term filter
kernel or simply kernel.
• The fig. shows linear spatial filtering using a 3 × 3 kernel.
• At any point (x, y) in the image, the response, g(x, y), of
the filter is the sum of products of the kernel
coefficients and the image pixels encompassed by the
kernel:
22
Example
23
How to perform convolution?
• In order to perform convolution on an image, following steps should
be taken.
• Flip the mask (horizontally and vertically) only once
• Slide the mask onto the image.
• Multiply the corresponding elements and then add them
• Repeat this procedure until all values of the image has been calculated
• Why Convolution
• Convolution can achieve blurring, sharpening, edge detection, noise
reduction e.t.c.
24
Example of Convolution
Flipping the mask Flipping the mask
horizontally vertically Image
Mask
1 2 3 3 2 1 9 8 7 2 4 6
4 5 6 6 5 4 6 5 4 8 10 12
7 8 9 9 8 7 3 2 1 14 16 18
Now place 52 in the original image at the first index and repeat this procedure for each
pixel of the image.
25
Another Example
26
ANOTHER EXAMPLE
27
ANOTHER EXAMPLE
28
ANOTHER EXAMPLE
29
What is a mask?
• A mask is a filter.
• Concept of masking is also known as spatial filtering.
• Masking just deal with the filtering operation that is performed
directly on the image.
• Mask can be a matrix which also called kernel.
30
What is filtering?
• The process of filtering is also known as convolving a mask with an
image. As this process is same of convolution so filter masks are also
known as convolution masks.
• Filtering process
• The general process of filtering and applying masks is consists of moving the
filter mask from point to point in an image. At each point (x,y) of the original
image, the response of a filter is calculated by a pre defined relationship. All the
filters values are pre defined and are a standard.
• Types of filters
• Generally there are two types of filters. One is called as linear filters or
smoothing filters and others are called as frequency domain filters.
31
Why filters are used?
• Filters are applied on image for multiple purposes. The two most common uses are as
following:
• Filters are used for Blurring and noise reduction
• Filters are used for edge detection and sharpness
• Blurring and noise reduction
• Filters are most commonly used for blurring and for noise reduction. Blurring is used in pre
processing steps, such as removal of small details from an image prior to large object extraction.
• The common masks for blurring are.
• Box filter
• Weighted average filter
• In the process of blurring we reduce the edge content in an image and try to make the
transitions between different pixel intensities as smooth as possible.
• Noise reduction is also possible with the help of blurring.
• Edge Detection and sharpness
• Masks or filters can also be used for edge detection in an image and to increase sharpness of an
image.
32
What are edges?
• We can also say that sudden changes of discontinuities or significant
transitions in an image are called as edges.
• A picture with edges is shown below.
33
Blurring
• In blurring, we simple blur an image.
• An image looks more sharp or more detailed if we are able to perceive all
the objects and their shapes correctly in it.
• For example. An image with a face, looks clear when we are able to identify eyes,
ears, nose, lips, forehead e.t.c very clear.
• This shape of an object is due to its edges. So in blurring, we simple reduce
the edge content and makes the transition form one color to the other very
smooth.
• Blurring vs zooming
• You might have seen a blurred image when you zoom an image. When you zoom an
image using pixel replication, and zooming factor is increased, you saw a blurred
image. This image also has less details, but it is not true blurring.
• Because in zooming, you add new pixels to an image, that increase the overall
number of pixels in an image, whereas in blurring, the number of pixels of a normal
image and a blurred image remains the same.
34
Example
35
Filters for Blurring
• Blurring can be achieved by many ways. The common type of filters that are used
to perform blurring are.
• Mean filter
• Weighted average filter
• Gaussian filter
• Mean filter
• Mean filter is also known as Box filter and average filter. A mean filter has the following
properties.
• It must be odd ordered
• The sum of all the elements should be 1
• All the elements should be same
• Weighted average filter
• In weighted average filter, we gave more weight to the center value. Due to which the
contribution of center becomes more then the rest of the values. Due to weighted average
filtering, we can actually control the blurring.
• Properties of the weighted average filter are.
• It must be odd ordered
• The sum of all the elements should be 1
• The weight of center element should be more then all of the other elements
36
Mean filter Example
1/9 1/9 1/9
• Consider an 3×3 mean filter given below:
• It has odd number i.e. 9 cells 1/9 1/9 1/9
• Sum of all elements 1/9 1/9 1/9
1/9 + 1/9 + 1/9 + 1/9 + 1/9 + 1/9 + 1/9 + 1/9 +
1/9 = 9/9 = 1
• All elements are same.
37
Weighted Average Filter
• In weighted average filter, we gave more weight to the center value. Due to
which the contribution of center becomes more then the rest of the values.
Due to weighted average filtering, we can actually control the blurring.
• Properties of the weighted average filter are.
• It must be odd ordered
• The sum of all the elements should be 1
• The weight of center element should be more then all of the other elements
1 2 1
1
× 2 4 2
16
1 2 1
38
Concept of Edges
• We can also say that sudden changes of discontinuities in an image are called as edges.
• Significant transitions in an image are called as edges.
• Types of edges
• Horizontal edges
• Vertical Edges
• Diagonal Edges
• Why edges are detected?
• Most of the shape information of an image is enclosed in edges. So first we detect these
edges in an image and by using these filters and then by enhancing those areas of image
which contains edges, sharpness of the image will increase and image will become
clearer.
• Here are some of the masks for edge detection:
• Prewitt Operator
• Sobel Operator
• Robinson Compass Masks
• Krisch Compass Masks
• Laplacian Operator
39
Image Sharpening
• Sharpening is opposite to the blurring. In blurring, we reduce the edge
content and in Sharpening, we increase the edge content. So in order to
increase the edge content in an image, we have to find edges first.
• Edges can be find by one of the any method described above by using any
operator.
• After finding edges, we will add those edges on an image and thus the
image would have more edges, and it would look sharpen.
• This is one way of sharpening an image.
40
Prewitt Operator
• Prewitt operator is used for edge detection in an image. It detects two types
of edges
• Horizontal edges
• Vertical Edges
• Edges are calculated by using difference between corresponding pixel
intensities of an image. All the masks that are used for edge detection are
also known as derivative masks. Because image is also a signal so changes in
a signal can only be calculated using differentiation. So that’s why 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.
41
Vertical Direction using Prewitt Operator
• When we apply this mask on the image it 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.
-1 0 1
-1 0 1
-1 0 1
42
Horizontal Direction Using Prewitt Operator
• This mask will prominent the horizontal edges in an image. It also works on the principle
of given mask and calculates difference among the pixel intensities of a particular edge.
• 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.
-1 -1 -1
0 0 0
1 1 1
43
Sobel Operator
• Difference with Prewitt Operator
• The 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.
• How vertical mask works?
• When we apply this mask on the image it 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. Also the center
values of both the first and third column is 2 and -2 respectively.
• This give more weight age to the pixel values around the edge region. This increase the edge
intensity and it become enhanced comparatively to the original image.
• How horizontal mask works?
• This mask will prominent the horizontal edges in an image. It also works on the principle of
above mask and calculates difference among the pixel intensities of a particular edge.
• 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.
44
Sobel Operator -- example
-1 0 1
-2 0 2
-1 0 1
-1 -2 -1
0 0 0
1 2 1
46
Robinson Compass Mask example
47
Robinson Compass Mask example
48
Kirsch Compass Mask
• The only difference between Robinson and kirsch compass masks is that in
Robinson we have a standard mask but in Kirsch we change the mask
according to our own requirements.
• By applying the masks of all direction we will get edges in all the direction.
• Result is depends on the image. Suppose there is an image, which do not have any North
East direction edges so then that mask will be ineffective.
-3 -3 5 -3 5 5
-3 0 5 -3 0 5
-3 -3 5 -3 -3 -3
49
Laplacian Operator
• Laplacian Operator is also a derivative operator which is used to find
edges in an image. The major difference between Laplacian and other
operators like Prewitt, Sobel, Robinson and Kirsch is that these all are first
order derivative masks but Laplacian is a second order derivative mask.
• In this mask we have two further classifications:
• Positive Laplacian Operator
• Negative Laplacian Operator.
• Another difference between Laplacian and other operators is that unlike
other operators Laplacian didn’t take out edges in any particular direction
but it take out edges in following classification.
• Inward Edges
• Outward Edges
50
How Laplacian Operator works?
• Laplacian is a derivative operator; its uses highlight gray level discontinuities in
an image and try to deemphasize regions with slowly varying gray levels. This
operation in result produces such images which have grayish edge lines and
other discontinuities on a dark background. This produces inward and outward
edges in an image
• The important thing is how to apply these filters onto image. Remember we can’t
apply both the positive and negative Laplacian operator on the same image. we
have to apply just one but the thing to remember is that
• if we apply positive Laplacian operator on the image then we subtract the resultant
image from the original image to get the sharpened image.
• Similarly if we apply negative Laplacian operator then we have to add the resultant
image onto original image to get the sharpened image.
51
Laplacian Operator Example
Positive Laplacian Operator Negative Laplacian Operator
0 1 0 0 1 0
1 -4 1 -1 4 -1
0 1 0 0 1 0
52
Convolution Theorem
• We consider images in spatial domain.
• Now consider the images in frequency domain. To get the frequency domain at first we
have to understand the relation between frequency and spatial domain. This
relationship can be explained by a theorem which is called as Convolution theorem.
• f(x, y)*h(x,y) F(u,v).H(u,v)
• f(x, y).h(x,y) F(u,v)*H(u,v)
• h(x,y) H(u,v)
53
Convolution Theorem
• It can be stated as the convolution in spatial domain is equal to filtering in
frequency domain and vice versa.
• The steps in filtering are given below.
• At first step we have to do some pre – processing an image in spatial domain, means
increase its contrast or brightness
• Then we will take discrete Fourier transform of the image
• Then we will center the discrete Fourier transform, as we will bring the discrete
Fourier transform in center from corners
• Then we will apply filtering, means we will multiply the Fourier transform by a filter
function
• Then we will again shift the DFT from center to the corners
• Last step would be take to inverse discrete Fourier transform, to bring the result
back from frequency domain to spatial domain
• And this step of post processing is optional, just like pre processing , in which we just
increase the appearance of image.
54
Image Filtering
Fourier Inverse Fourier
Image Filter Image
Transform Transform
• Filters
• The concept of filter in frequency domain is same as the concept of a mask
in convolution.
• After converting an image to frequency domain, some filters are applied in
filtering process to perform different kind of processing on an image. The
processing include blurring an image, sharpening an image e.t.c.
• The common type of filters for these purposes are:
• Ideal high pass filter
• Ideal low pass filter
• Gaussian high pass filter
• Gaussian low pass filter
55
Blurring masks vs derivative masks
• Blurring masks
• A blurring mask has the following properties.
• All the values in blurring masks are positive
• The sum of all the values is equal to 1
• The edge content is reduced by using a blurring mask
• As the size of the mask grow, more smoothing effect will take place
• Derivative masks
• A derivative mask has the following properties.
• A derivative mask have positive and as well as negative values
• The sum of all the values in a derivative mask is equal to zero
• The edge content is increased by a derivative mask
• As the size of the mask grows , more edge content is increased
56
Mask VS Filtering
• Relationship between blurring mask and derivative mask with high pass filters and
low pass filters.
• Blurring masks are also called as low pass filter
• Derivative masks are also called as high pass filter
• High pass frequency components and Low pass frequency components
• The high pass frequency components denotes edges whereas the low pass frequency
components denotes smooth regions.
57
Thank You