Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
86 views81 pages

Image Processing for Beginners

This document provides an introduction to image processing. It defines key terms like digital image and digital image processing. It discusses related fields like image analysis and computer vision. It also outlines different types of imaging systems that operate across the electromagnetic spectrum, including gamma ray, X-ray, ultraviolet, visible light, infrared, and microwave imaging. Examples are given for medical, industrial, and astronomical applications within each frequency band.

Uploaded by

Manish Sandilya
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)
86 views81 pages

Image Processing for Beginners

This document provides an introduction to image processing. It defines key terms like digital image and digital image processing. It discusses related fields like image analysis and computer vision. It also outlines different types of imaging systems that operate across the electromagnetic spectrum, including gamma ray, X-ray, ultraviolet, visible light, infrared, and microwave imaging. Examples are given for medical, industrial, and astronomical applications within each frequency band.

Uploaded by

Manish Sandilya
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/ 81

Image Processing Lecture 1

References:-
1. Rafael C. Gonzalez, Richard E. Woods, "Digital Image Processing", 2/E, Prentice
– Hall 2001.
2. Scott E Umbaugh, “Computer Vision and Image Processing”, Prentice – Hall
1998.
3. Nick Efford, “Digital Image Processing – a practical approach using Java”,
Pearson Education 2000.
4. John R Jensen, “Introductory Digital Image Processing”, 3/E. Prentice Hall, 2005.

1. Introduction
An image is a picture: a way of recording and presenting information
visually. Since vision is the most advanced of our senses, it is not
surprising that images play the single most important role in human
perception. The information that can be conveyed in images has been
known throughout the centuries to be extraordinary - one picture is worth
a thousand words.
However, unlike human beings, imaging machines can capture and
operate on images generated by sources that cannot be seen by humans.
These include X-ray, ultrasound, electron microscopy, and computer-
generated images. Thus, image processing has become an essential field
that encompasses a wide and varied range of applications.

2. Basic definitions
• Image processing is a general term for the wide range of
techniques that exist for manipulating and modifying images in
various ways.
• A digital image may be defined as a finite, discrete
representation of the original continuous image. A digital image
is composed of a finite number of elements called pixels, each
of which has a particular location and value.

©Asst. Lec. Wasseem Nahy Ibrahem Page 1


Image Processing Lecture 1

• The term digital image processing refers to processing digital


images by means of a digital computer.

3. Digital image processing and other related areas


There is no general agreement regarding where image processing
stops and other related areas, such as image analysis and computer vision,
start. Sometimes a distinction is made by the following paradigm:
• Image processing is a discipline in which both the input and output
of a process are images. For example, it involves primitive
operations such as image preprocessing to reduce noise and
contrast enhancement.
• Image analysis (also called image understanding) is in between
image processing and computer vision. In this area, the process is
characterized by the fact that its inputs generally are images, but its
outputs are attributes extracted from those images (e.g., edges,
contours, and the identity of individual objects). This area includes
tasks such as image segmentation (partitioning an image into
regions or objects), description of those objects to reduce them to a
form suitable for computer processing, and classification
(recognition) of individual objects.
• Finally, computer vision is a field whose ultimate goal is to use
computers to emulate human vision, including learning and being
able to make inferences of recognized objects and take actions
based on visual inputs. This area itself is a branch of artificial
intelligence (AI) whose objective is to emulate human intelligence.

©Asst. Lec. Wasseem Nahy Ibrahem Page 2


Image Processing Lecture 1

4. Types of Imaging Systems


Imaging systems are varying depending on their energy source (e.g.
visual, X-ray, and so on). The principal energy source for images in use
today is the electromagnetic (EM) spectrum illustrated in Figure 1.1.
Other important sources of energy include acoustic, ultrasonic, and
electronic (in the form of electron beams used in electron microscopy).
Synthetic images, used for modeling and visualization, are generated by
computer. In this section we discuss briefly how images are generated in
these various categories and the areas in which they are applied.

Figure 1.1 the electromagnetic spectrum arranged according to energy per photon.

4.1 Gamma-ray Imaging


Gamma rays are emitted as a result of collision of certain radioactive
isotopes (a positron and an electron). This occurs naturally around
exploding stars, and can be created easily. Images are produced from the
emissions collected by gamma ray detectors.
Major uses of gamma ray imaging include nuclear medicine and
astronomical observations. In nuclear medicine, a patient is injected with
a radioactive isotope that emits gamma rays as it decays. Figure 1.2(a)
shows a major modality of nuclear imaging called positron emission
tomography (PET) obtained by using gamma-ray imaging. The image in
this figure shows a tumor in the brain and one in the lung, easily visible
as small white masses.

©Asst. Lec. Wasseem Nahy Ibrahem Page 3


Image Processing Lecture 1

(b)

(a)
Figure 1.2 Examples of Gamma-Ray imaging a) PET image b) Star explosion 15,000 years
ago

Figure 1.2(b) shows a star exploded about 15,000 years ago, imaged in
the gamma-ray band. Unlike the previous example shown in Figure 1.2(a)
, this image was obtained using the natural radiation of the object being
imaged.

4.2 X-ray Imaging


X-rays are generated using an X-ray tube (a vacuum tube with a cathode
and anode). The cathode is heated, causing free electrons to be released
and flowing at high speed to the positively charged anode. When the
electrons strike a nucleus, a modified energy is released in the form of X-
ray radiation. Images are either generated by: 1) dropping the resulting
energy on a film, then digitizing it or 2) dropping directly onto devices
that convert X-rays to light. The light signal in turn is captured by a light-
sensitive digitizing system.

©Asst. Lec. Wasseem Nahy Ibrahem Page 4


Image Processing Lecture 1

X-rays are widely used for imaging in medicine, industry and astronomy.
In medicine, chest X-ray, illustrated in Figure 1.3(a), is widely used for
medical diagnostics.

(a) (b) (c)


Figure 1.3 Examples of X-Ray imaging. a) Chest X-ray. b) Circuit board. c) Star explosion

In industrial processes, X-rays are used to examine circuit boards, see


Figure 1.3(b), for flaws in manufacturing, such as missing components or
broken traces. Figure 1.3(c) shows an example of X-ray imaging in
astronomy. This image is the star explosion of Figure 1.2 (b), but imaged
this time in the X-ray band.

4.3 Ultraviolet Imaging


Applications of ultraviolet "light" are varied. They include industrial
inspection, fluorescence microscopy, lasers, biological imaging, and
astronomical observations. For example, Figure 1.4(a) shows a
fluorescence microscope image of normal corn, and Figure 1.4(b) shows
corn infected by "smut," a disease of corn. Figure 1.4(c) shows the entire
"oval" of the auroral emissions at Saturn's South Pole captured with
Cassini's ultraviolet imaging spectrograph.

©Asst. Lec. Wasseem Nahy Ibrahem Page 5


Image Processing Lecture 1

(a) (b) (c)


Figure 1.4
1. Examples of ultraviolet imaging (a) Normal corn (b) Smut corn (c) Emissions
missions at
Saturn's South Pole

4.4 Imaging
Imaging in the Visible and Infrared bands
The visual band of the EM spectrum is the most familiar in all activities
and has the widest scope of application. The infrared band often is used in
conjunction with visual imaging (Multispectral
(Multispectral Imaging). Applications
include light microscopy, astronomy, remote sensing, industry, and law
enforcement. Figure 1.5(a)
5(a) shows a microprocessor image magnified 60
times with a light microscop
microscope,
e, and Figure 1.5(b)
5(b) illustrates infrared
satellite image of the Americas
Americas. Figure 1.5(c) shows a multispectral
ultispectral
image of a hurricane taken by a weather satellite
satellite.

(b)

(a) (c)
Figure 1.5
1.5 Examples of visible and infrared imaging
imaging. a) Microprocessor magnified 60 times.
times
b) Infrared satellite image of the US. c) Multispectral image of Hurricane

©Asst.. Lec. Wasseem Nahy


Nah Ibrahem Page 6
Image Processing Lecture 1

4.5 Imaging in the Microwave band


The dominant application of imaging in the microwave band is radar.
Imaging radar works like a flash camera in that it provides its own
illumination (microwave pulses) to illuminate an area on the ground and
take a snapshot image. Instead of a camera lens, radar uses an antenna
and digital computer processing to record its images. In a radar image,
one can see only the microwave energy that was reflected back toward
the radar antenna. Figure 1.6 shows a radar image covering a rugged
mountainous area.

Figure 1.6 Radar image of mountainous region

4.6 Imaging in the Radio band


The major applications of imaging in the radio band are in medicine and
astronomy. In medicine radio waves are used in magnetic resonance
imaging (MRI). For MRI, a powerful magnet passes radio waves through
the patient body in short pulses. Patient’s tissues respond by emitting
pulses of radio waves. The location and strength of these signals are
determined by a computer, which produces a 2D picture of a section of
the patient. Figure 1.7 shows MRI images of a human knee and spine.

©Asst. Lec. Wasseem Nahy Ibrahem Page 7


Image Processing Lecture 1

(a) (b)
Figure 1.7 MRI images of a human (a) knee, and (b) spine.

4.7Other Imaging Modalities


There are a number of other imaging modalities that also are important.
Examples include acoustic imaging, electron microscopy, and synthetic
(computer-generated) imaging.
Imaging using "sound waves" finds application in medicine,
industry and geological exploration. In medicine, ultrasound imaging is
used in obstetrics where unborn babies are imaged to determine the health
of their development. A byproduct of this examination is determining the
sex of the baby. Figure 1.8 shows examples of ultrasound imaging.
The procedure of generating ultrasound images is as follows:
1. The ultrasound system (a computer, ultrasound probe consisting of
a source and receiver, and a display) transmits high-frequency (1 to
5 MHz) sound pulses into the body.
2. The sound waves travel into the body and hit a boundary between
tissues. Then, they are reflected back and picked up by the probe
and relayed to the computer.
3. The computer calculates the distance from the probe to the tissue or
organ boundaries, and then it displays the distances and intensities
of the echoes on the screen, forming a two-dimensional image.
©Asst. Lec. Wasseem Nahy Ibrahem Page 8
Image Processing Lecture 1

(a) (b)
Figure 1.8 Examples of ultrasound imaging. a) Baby b) another view of baby

Finally, Figure 1.9(a) shows an image of damaged integrated


circuit magnified 2500 times using an electron microscope. Figure 1.9(b)
shows a fractal image generated by a computer.

(a) (b)
Figure 1.9 (a) image of damaged integrated circuit magnified 2500 times (b) fractal image

©Asst. Lec. Wasseem Nahy Ibrahem Page 9


Image Processing Lecture 1

5. Digital image processing applications


Image processing is used in a wide range of applications for example:

• Security (e.g. face, fingerprint and iris recognition)

(a)

(b) (c)

Figure 1.10 (a) Face recognition system for PDA (b) Iris recognition (c) Fingerprint
recognition

• Surveillance (e.g. car number plate recognition)

Figure 1.11 Car number plate recognition

• Medical applications as shown in the previous sections

©Asst. Lec. Wasseem Nahy Ibrahem Page 10


Image Processing Lecture 1

6. Components of digital image processing system


The basic model of a digital image processing system assumes the
existence of a source of energy, a sensor devise to detect the
emitted/reflected energy, a coding system for the range of measurements,
and a display device. However, a modern DIP system requires powerful
computing hardware, specialized software, large storage systems and
communication devices. Figure 1.12 shows the basic components
comprising a typical general-purpose system used for digital image
processing.

Figure 1.12 Components of a general-purpose image processing system

7. Fundamental tasks in digital image processing


Image applications require a variety of techniques that can be divided into
two main categories: image processing techniques whose input and

©Asst. Lec. Wasseem Nahy Ibrahem Page 11


Image Processing Lecture 1

output are images, and image analysis techniques whose inputs are
images, but whose outputs are attributes extracted from those images.
1. Image processing techniques include:

§ Image Enhancement: brings out detail that is obscured, or simply


highlights certain features of interest in an image. A familiar
example of enhancement is increasing the contrast of an image.
§ Image Restoration: attempts to reconstruct or recover an image that
has been degraded by using a priori knowledge of the degradation
phenomenon.
§ Image Compression: deals with techniques for reducing the storage
required to save an image, or the bandwidth required to transmit it.
2. Image Analysis tasks include:

§ Image Segmentation: is concerned with procedures that partition an


image into its constituent parts or objects.
§ Image Representation and Description: Image representation
converts the output of a segmentation stage to a form suitable for
computer processing. This form could be either the boundary of a
region or the whole region itself. Image description, also called
feature selection, deals with extracting attributes that result in some
quantitative information of interest or are basic for differentiating
one class of objects from another.
§ Image Recognition: is the process that assigns a label (e.g.,
"vehicle") to an object based on its descriptors.

©Asst. Lec. Wasseem Nahy Ibrahem Page 12


Image Processing Lecture 2

Types of Digital Images


The images types we will consider are: 1) binary, 2) gray-scale, 3) color,
and 4) multispectral.

1. Binary images
Binary images are the simplest type of images and can take on two
values, typically black and white, or 0 and 1. A binary image is referred
to as a 1-bit image because it takes only 1 binary digit to represent each
pixel. These types of images are frequently used in applications where the
only information required is general shape or outline, for example optical
character recognition (OCR).
Binary images are often created from the gray-scale images via a
threshold operation, where every pixel above the threshold value is turned
white (‘1’), and those below it are turned black (‘0’). In the figure below,
we see examples of binary images.

(a) (b)

Figure 2.1 Binary images. (a) Object outline. (b) Page of text used in OCR application.

2. Gray-scale images
Gray-scale images are referred to as monochrome (one-color) images.

©Asst. Lec. Wasseem Nahy Ibrahem Page 1


Image Processing Lecture 2

They contain gray-level information, no color information. The number


of bits used for each pixel determines the number of different gray levels
available. The typical gray-scale image contains 8bits/pixel data, which
allows us to have 256 different gray levels. The figure below shows
examples of gray-scale images.

Figure 2.2 Examples of gray-scale images

In applications like medical imaging and astronomy, 12 or 16 bits/pixel


images are used. These extra gray levels become useful when a small
section of the image is made much larger to discern details.

3. Color images
Color images can be modeled as three-band monochrome image data,
where each band of data corresponds to a different color. The actual
information stored in the digital image data is the gray-level information
in each spectral band.
Typical color images are represented as red, green, and blue (RGB
images). Using the 8-bit monochrome standard as a model, the
corresponding color image would have 24-bits/pixel (8-bits for each of
the three color bands red, green, and blue). The figure below illustrates a
representation of a typical RGB color image.

©Asst. Lec. Wasseem Nahy Ibrahem Page 2


Image Processing Lecture 2

Figure 2.3 Representation of a typical RGB color image

4. Multispectral images
Multispectral images typically contain information outside the normal
human perceptual range. This may include infrared, ultraviolet, X-ray,
acoustic, or radar data. These are not images in the usual sense because
the information represented is not directly visible by the human system.
However, the information is often represented in visual form by mapping
the different spectral bands to RGB components.

Digital Image File Formats


Types of image data are divided into two primary categories: bitmap and
vector.
• Bitmap images (also called raster images) can be represented as 2-
dimensional functions f(x,y), where they have pixel data and the
corresponding gray-level values stored in some file format.
• Vector images refer to methods of representing lines, curves, and
shapes by storing only the key points. These key points are
sufficient to define the shapes. The process of turning these into an

©Asst. Lec. Wasseem Nahy Ibrahem Page 3


Image Processing Lecture 2

image is called rendering. After the image has been rendered, it


can be thought of as being in bitmap format, where each pixel has
specific values associated with it.

Most of the types of file formats fall into the category of bitmap images,
for example:
§ PPM (Portable Pix Map) format
§ TIFF (Tagged Image File Format)
§ GIF (Graphics Interchange Format)
§ JPEG (Joint Photographic Experts Group) format
§ BMP (Windows Bitmap)
§ PNG (Portable Network Graphics)
§ XWD (X Window Dump)

A simple image formation model


• In a mathematical view, a monochromatic image is a two-
dimensional function, f(x, y), where x and y are spatial (plane)
coordinates, and the amplitude of f at any pair of coordinates (x,
y) is called the intensity or gray level of the image at that point.
• The values of a monochromatic image (i.e. intensities) are said to
span the gray scale.
• When x,y, and the amplitude value of f are all finite, discrete
quantities, the image is called a digital image.

The function f(x, y) must be nonzero and finite; that is,


0 < f(x, y) < ∞

©Asst. Lec. Wasseem Nahy Ibrahem Page 4


Image Processing Lecture 2

The function f(x, y) is the product of two components: 1) the amount of


source illumination incident on the scene i(x, y) and 2) the amount of
illumination reflected by the objects in the scene r(x, y):
f(x, y)= i(x, y)r(x, y)
where 0<i(x, y)<∞ and 0<r(x, y)<1.
Note that the equation 0<r(x, y)<1 indicates that reflectance is bounded
by 0 (total absorption) and 1 (total reflectance).
The nature of i(x, y) is determined by the illumination source, and r(x, y)
is determined by the characteristics of the imaged objects.
As mentioned earlier, we call the intensity of a monochrome image at any
coordinates (xa, yb) the gray level ( l ) of the image at that point. That is,

l = f(xa ,yb)
From the above equations, it is evident that l lies in the range

Lmin ≤ l ≤ Lmax
Where Lmin is positive, and Lmax is finite.
The interval [Lmin , Lmax] is called the gray scale. Common practice is to
shift this interval numerically to the interval [0, L-1], where l = 0 is
considered black and l = L-1 is considered white on the gray scale. All
intermediate values are shades of gray varying from black to white.

Image Sampling and Quantization


To convert the continuous function f(x,y) to digital form, we need to
sample the function in both coordinates and in amplitude.
• Digitizing the coordinate values is called sampling.
• Digitizing the amplitude values is called quantization.

©Asst. Lec. Wasseem Nahy Ibrahem Page 5


Image Processing Lecture 2

In the figure below, we show how to convert the continuous image in


Figure 2.1(a) to the digital form using the sampling and quantization
processes. The one-dimensional function shown in Figure 2.1(b) is a plot
of amplitude (gray level) values of the continuous image along the line
segment AB in Figure 2.1(a).
To sample this function, we take equally spaced samples along line
AB, as shown in Figure 2.1(c). The samples are shown as small white
squares superimposed on the function. The set of these discrete locations
gives the sampled function.
In order to form a digital function, the gray-level values also must be
converted (quantized) into discrete quantities. The right side of Figure
2.1(c) shows the gray-level scale divided into eight discrete levels,
ranging from black to white. The continuous gray levels are quantized
simply by assigning one of the eight discrete gray levels to each sample.

©Asst. Lec. Wasseem Nahy Ibrahem Page 6


Image Processing Lecture 2

Figure 2.1 Generating a digital image. (a) Continuous image, (b) A scan line from A to B in
the continuous image (c) Sampling and quantization, (d) Digital scan line.

The digital samples resulting from both sampling and quantization are
shown in Figure 2.1(d). Starting at the top of the image and carrying out
this procedure line by line produces a two-dimensional digital image as
shown in Figure 2.3.

©Asst. Lec. Wasseem Nahy Ibrahem Page 7


Image Processing Lecture 2

Figure 2.3 Digital image resulted from sampling and quantization

Note that:
• The number of selected values in the sampling process is known as
the image spatial resolution. This is simply the number of pixels
relative to the given image area.
• The number of selected values in the quantization process is called
the grey-level (color level) resolution. This is expressed in terms
of the number of bits allocated to the color levels.
• The quality of a digitized image depends on the resolution
parameters on both processes.

Digital Image Representation


The monochrome digital image f(x,y) resulted from sampling and
quantization has finite discrete coordinates (x,y) and intensities (gray
levels). We shall use integer values for these discrete coordinates and
gray levels. Thus, a monochrome digital image can be represented as a 2-
dimensional array (matrix) that has M rows and N columns:

©Asst. Lec. Wasseem Nahy Ibrahem Page 8


Image Processing Lecture 2

Each element of this matrix array is called pixel. The spatial resolution
(number of pixels) of the digital image is M * N. The gray level
resolution (number of gray levels) L is
k
L= 2
Where k is the number of bits used to represent the gray levels of the
k
digital image. When an image can have 2 gray levels, we can refer to the
image as a “k-bit image”. For example, an image with 256 possible gray-
level values is called an 8-bit image.
The gray levels are integers in the interval [0, L-1]. This interval is called
the gray scale.
The number, b, of bits required to store a digitized image is
b= M* N*k

Example:
For an 8-bit image of size 512×512, determine its gray-scale and storage
size.
Solution k = 8 , M = N = 512
k
Number of gray levels L = 2 = 28 = 256
The gray scale is [0 , 255]
Storage size (b) = M * N * k = 512 * 512 * 8 = 2,097,152 bits

©Asst. Lec. Wasseem Nahy Ibrahem Page 9


Image Processing Lecture 2

Spatial and Gray-level Resolution


Spatial resolution is the smallest discernible detail in an image. It is
determined by the sampling process. The spatial resolution of a digital
image reflects the amount of details that one can see in the image (i.e. the
ratio of pixel “area” to the area of the image display). If an image is
spatially sampled at M×N pixels, then the larger M×N the finer the
observed details.
Gray-level resolution refers to the smallest discernible change in gray
level. It is determined by the quantization process. As mentioned earlier,
the number of gray levels is usually an integer power of 2. The most
common number is 8 bits, however, 16 bits is used in some applications
where enhancement of specific gray-level ranges is necessary.

Effect of reducing the spatial resolution


Decreasing spatial resolution of a digital image, within the same area,
may result in what is known as checkerboard pattern. Also image details
are lost when the spatial resolution is reduced.
To demonstrate the checkerboard pattern effect, we subsample the
1024× 1024 image shown in the figure below to obtain the image of size
512×512 pixels. The 512×512 is then subampled to 256×256 image, and
so on until 32×32 image. The subsampling process means deleting the
appropriate number of rows and columns from the original image. The
number of allowed gray levels was kept at 256 in all the images.

©Asst. Lec. Wasseem Nahy Ibrahem Page 10


Image Processing Lecture 2

Figure 2.4 A 1024×1024, 8-bit image subsampled down to size 32×32 pixels.

To see the effects resulting from the reduction in the number of samples,
we bring all the subsampled images up to size 1024×1024 by row and
column pixel replication. The resulted images are shown in the figure
below.

Figure 2.5 (a) 1024×1024, 8-bit image. (b) through (f) 512×512, 256×256, 128×128, 64×64,
and 32×32 images resampled into 1024×1024 pixels by row and column duplication

©Asst. Lec. Wasseem Nahy Ibrahem Page 11


Image Processing Lecture 2

Compare Figure 2.5(a) with the 512×512 image in Figure 2.5(b), we find
that the level of detail lost is simply too fine to be seen on the printed
page at the scale in which these images are shown. Next, the 256×256
image in Figure 2.5(c) shows a very slight fine checkerboard pattern in
the borders between flower petals and the black background. A slightly
more pronounced graininess throughout the image also is beginning to
appear. These effects are much more visible in the 128×128 image in
Figure 2.5(d), and they become pronounced in the 64×64 and 32×32
images in Figures 2.5(e) and (f), respectively.

Effect of reducing the gray-level resolution


Decreasing the gray-level resolution of a digital image may result in what
is known as false contouring. This effect is caused by the use of an
insufficient number of gray levels in smooth areas of a digital image.
To illustrate the false contouring effect, we reduce the number of
gray levels of the 256-level image shown in Figure 2.6(a) from 256 to 2.
The resulted images are shown in the figures 2.6(b) through (h). This can
be achieved by reducing the number of bits from k = 7 to k = 1 while
keeping the spatial resolution constant at 452×374 pixels.
We can clearly see that the 256-, 128-, and 64-level images are
visually identical. However, the 32-level image shown in Figure 2.6(d)
has an almost imperceptible set of very fine ridgelike structures in areas
of smooth gray levels (particularly in the skull).False contouring
generally is quite visible in images displayed using 16 or less uniformly
spaced gray levels, as the images in Figures 2.6(e) through (h) show.

©Asst. Lec. Wasseem Nahy Ibrahem Page 12


Image Processing Lecture 2

(a) (b) (c) (d)

(e) (f) (g) (h)


Figure 2.6 (a) 452×374, 256-level image. (b)-(h) Image displayed in 128, 64, 32, 16, 8, 4, and
2 gray levels, while keeping the spatial resolution constant.

©Asst. Lec. Wasseem Nahy Ibrahem Page 13


Image Processing Lecture 3

Example
The pixel values of the following 5×5 image are represented by 8-bit
integers:

k
Determine f with a gray-level resolution of 2 for (i) k=5 and (ii) k=3.

Solution:
Dividing the image by 2 will reduce its gray level resolution by 1 bit.
Hence to reduce the gray level resolution from 8-bit to 5-bit,
8 bits – 5 bits = 3 bits will be reduced
3
Thus, we divide the 8-bit image by 8 (2 ) to get the following 5-bit
image:

Similarly, to obtain 3-bit image, we divide the 8-bit image by 25 (32) to


get:

©Asst. Lec. Wasseem Nahy Ibrahem Page 1


Image Processing Lecture 3

Basic relationships between pixels


1. Neighbors of a Pixel
A pixel p at coordinates (x ,y) has the following neighbors:
• 4-neighbors
§ four horizontal and vertical neighbors whose coordinates are
(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)
§ denoted by N4(p)
• diagonal neighbors
§ (x + l , y + l),(x+ l , y- l),(x-l , y + l),(x- l , y -1)
§ denoted by ND(p)
• 8-neighbors
§ both 4-neighbors and diagonal neighbors
§ denoted by N8(p)
Note: some of the neighbors of p lie outside the digital image if (x, y) is
on the border of the image.

2. Distance Measures
For pixels p, q, and z, with coordinates (x, y), (s, t), and (v, w),
respectively, D is a distance function or metric if
a) D(p, q) > = 0 ( D(p,q)= 0 iff p = q ),
b) D(p,q) = D(q,p), and
c) D(p,z) < = D(p,q) + D(q,z).
• Euclidean distance between p and q is defined as

• City-block distance between p and q is defined as

©Asst. Lec. Wasseem Nahy Ibrahem Page 2


Image Processing Lecture 3

• Chessboard distance between p and q is defined as

Zooming and Shrinking Digital Images


A) Zooming
Zooming may be viewed as oversampling. It is the scaling of an image
area A of w×h pixels by a factor s while maintaining spatial resolution
(i.e. output has sw×sh pixels). Zooming requires two steps:
• creation of new pixel locations
• assignment of gray levels to those new locations
There are many methods of gray-level assignments, for example nearest
neighbor interpolation and bilinear interpolation.

Nearest neighbor interpolation (Zero-order hold)


is performed by repeating pixel values, thus creating a checkerboard
effect. Pixel replication (a special case of nearest neighbor interpolation)
is used to increase the size of an image an integer number of times. The
example below shows 8-bit image zooming by 2x (2 times) using nearest
neighbor interpolation:

= =

Original image image with rows expanded image with rows and
columns expanded

©Asst. Lec. Wasseem Nahy Ibrahem Page 3


Image Processing Lecture 3

Bilinear interpolation (First-order hold)


is performed by finding linear interpolation between adjacent pixels, thus
creating a blurring effect. This can be done by finding the average gray
value between two pixels and use that as the pixel value between those
two. We can do this for the rows first, and then we take that result and
expand the columns in the same way. The example below shows 8-bit
image zooming by 2x (2 times) using bilinear interpolation:

= =

Original image image with rows expanded image with rows and
columns expanded

Note that the zoomed image has size 2M-1 × 2N-1. However, we can use
techniques such as padding which means adding new columns and/or
rows to the original image in order to perform bilinear interpolation to get
zoomed image of size 2M × 2N.

The figure below shows image zooming using nearest neighbor


interpolation and bilinear interpolation. We can clearly see the
checkerboard and blurring effects. However, the improvements using
bilinear interpolation in overall appearance are clear, especially in the
128×128 and 64×64 cases. The bilinear interpolated images are smoother
than those resulted from nearest neighbor interpolation.

©Asst. Lec. Wasseem Nahy Ibrahem Page 4


Image Processing Lecture 3

Figure 3.1 Top row: images zoomed from 128×128, 64×64, and 32×32 pixels to 1024×1024
pixels susing nearest neighbor interpolation. Bottom row, same sequence, but using bilinear
interpolation

B) Shrinking
Shrinking may be viewed as undersampling. Image shrinking is
performed by row-column deletion. For example, to shrink an image by
one-half, we delete every other row and column.

Original image image with rows deleted image with rows


and columns deleted

©Asst. Lec. Wasseem Nahy Ibrahem Page 5


Image Processing Lecture 3

Image algebra
There are two categories of algebraic operations applied to images:
• Arithmetic
• Logic
These operations are performed on a pixel-by-pixel basis between two or
more images, except for the NOT logic operation which requires only one
image. For example, to add images I1 and I2 to create I3:
I3(x,y) = I1(x,y) + I2(x,y)

• Addition is used to combine the information in two images.


Applications include development of image restoration algorithms
for modeling additive noise and special effects such as image
morphing in motion pictures as shown in the figures below.

(a) Original image (b) Gaussian noise (c) Addition of images


(a) and (b)
Figure 3.2 Image addition (adding noise to the image)

©Asst. Lec. Wasseem Nahy Ibrahem Page 6


Image Processing Lecture 3

(a) First Original (b) Second Original (c) Addition of images


(a) and (b)
Figure 3.3 Image addition (image morphing example)

• Subtraction of two images is often used to detect motion. For


example, in a scene when nothing has changed, the image resulting
from the subtraction is filled with zeros(black image). If something
has changed in the scene, subtraction produces a nonzero result at
the location of movement as shown in the figure below.

(a) Original scene (b) Same scene at a later time

(c) Subtracting image (b) from (a). Only moving objects appear in the resulting image

Figure 3.4 Image subtraction

©Asst. Lec. Wasseem Nahy Ibrahem Page 7


Image Processing Lecture 3

• Multiplication and division are used to adjust the brightness of an


image. Multiplying the pixel values by a number greater than one
will brighten the image, and dividing the pixel values by a factor
greater than one will darken the image. An example of brightness
adjustment is shown in the figure below.

(a) Original image (b) Image multiplied by 2

(c) Image divided by 2

Figure 3.5 Image multiplication and division

The logic operations AND, OR, and NOT form a complete set, meaning
that any other logic operation (XOR, NOR, NAND) can be created by a
combination of these basic elements. They operate in a bit-wise fashion
on pixel data.

©Asst. Lec. Wasseem Nahy Ibrahem Page 8


Image Processing Lecture 3

The AND and OR operations are used to perform masking operation; that
is; for selecting subimages in an image, as shown in the figure below.
Masking is also called Region of Interest (ROI) processing.

(a) Original image (b) AND image mask (c) Resulting image, (a)
AND (b)

(d) Original image (e) OR image mask (f) Resulting image, (d)
OR (e)
Figure 3.6 Image masking

The NOT operation creates a negative of the original image ,as shown in
the figure below, by inverting each bit within each pixel value.

©Asst. Lec. Wasseem Nahy Ibrahem Page 9


Image Processing Lecture 3

(a) Original image (b) NOT operator applied to image (a)


Figure 3.7 Complement image

Image Histogram
The histogram of a digital image is a plot that records the frequency
distribution of gray levels in that image. In other words, the histogram is
a plot of the gray-level values versus the number of pixels at each gray
value. The shape of the histogram provides us with useful information
about the nature of the image content.
The histogram of a digital image f of size M× N and gray levels
in the range [0, L-1] is a discrete function

where is the kth gray level and is the number of pixels in the image
having gray level .
The next figure shows an image and its histogram.

©Asst. Lec. Wasseem Nahy Ibrahem Page 10


Image Processing Lecture 3

(a) 8-bit image

(b) Histogram of image (a)

Figure 3.8 Image histogram

Note that the horizontal axis of the histogram plot (Figure 3.8(b))
represents gray level values, , from 0 to 255. The vertical axis represents
the values of i.e. the number of pixels which have the gray level .
The next figure shows another image and its histogram.

©Asst. Lec. Wasseem Nahy Ibrahem Page 11


Image Processing Lecture 3

(a) 8-bit image

(b) Histogram of image (a)

Figure 3.9 Another image histogram

It is customary to “normalize” a histogram by dividing each of its values


by the total number of pixels in the image, i.e. use the probability
distribution:

©Asst. Lec. Wasseem Nahy Ibrahem Page 12


Image Processing Lecture 3

Thus, represents the probability of occurrence of gray level .


As with any probability distribution:
• all the values of a normalized histogram are less than or equal
to 1
• the sum of all values is equal to 1
Histograms are used in numerous image processing techniques, such as
image enhancement, compression and segmentation.

©Asst. Lec. Wasseem Nahy Ibrahem Page 13


Image Processing Lecture 4

Image Enhancement
Image enhancement aims to process an image so that the output image is
“more suitable” than the original. It is used to solve some computer
imaging problems, or to improve “image quality”. Image enhancement
techniques include smoothing, sharpening, highlighting features, or
normalizing illumination for display and/or analysis.

Image Enhancement Approaches


Image enhancement approaches are classified into two categories:
• Spatial domain methods: are based on direct manipulation of pixels
in an image.
• Frequency domain methods: are based on modifying the Fourier
transform of an image.

Image Enhancement in the Spatial Domain


The term spatial domain refers to the image plane itself, i.e. the total
number of pixels composing an image. To enhance an image in the
spatial domain we transform an image by changing pixel values or
moving them around. A spatial domain process is denoted by the
expression:

where r is the input image, s is the processed image, and T is an


operator on r . The operator T is applied at each location (x, y) in r to
yield the output, s, at that location.

©Asst. Lec. Wasseem Nahy Ibrahem Page 1


Image Processing Lecture 4

Enhancement using basic gray level transformations


Basic gray level transformation functions can be divided into:
• Linear: e.g. image negatives and piecewise-linear transformation
• Non-linear: e.g. logarithm and power-law transformations

Image negatives
The negative of an image with gray levels in the range [0, L-1] is
obtained by using the following expression

This type of processing is useful for enhancing white or gray detail


embedded in dark regions of an image, especially when the black areas
are dominant in size. An example of using negative transformation is
analyzing digital mammograms as shown in the figure below.
Note how much easier it is to analyze the breast tissue in the negative
image.

(a) (b)
Figure 4.1 (a) Original digital mammogram. (b) Negative image obtained by negative
transformation

©Asst. Lec. Wasseem Nahy Ibrahem Page 2


Image Processing Lecture 4

Piecewise-linear transformation
The form of piecewise linear functions can be arbitrarily complex. Some
important transformations can be formulated only as piecewise functions,
for example thresholding:
For any 0 < t < 255 the threshold transform can be defined as:

Thresholding Transform
255
Output Gray Level, s

204
153
102
51
0
0 51 102 153 204 255
Input Gray Level, r

Figure 4.2 Form of thresholding transform


The figure below shows an example of thresholding an image by 80.

(a) Original image (b) Result of thresholding


Figure 4.3 Thresholding by 80

©Asst. Lec. Wasseem Nahy Ibrahem Page 3


Image Processing Lecture 4

Thresholding has another form used to generate binary images from the
gray-scale images, i.e.:

Thresholding Transform
255
Output Gray Level, s

204
153
102
51
0
0 51 102 153 204 255
Input Gray Level, r

Figure 4.4 Form of thresholding transform to produce binary images

The figure below shows a gray-scale image and its binary image resulted
from thresholding the original by 120:

(a) (b)
Figure 4.5 Thresholding. (a) Gray-scale image. (b) Result of thresholding (a) by 120

Another more complex piecewise linear function can be defined as:

©Asst. Lec. Wasseem Nahy Ibrahem Page 4


Image Processing Lecture 4

Piecewise Linear Transform


255
240
225
210
Output Gray Level, s

195
180
165
150
135
120
105
90
75
60
45
30
15
0
0
15
30
45
60
75
90
105
120
135
150
165
180
195
210
225
240
255
Input Gray Level, r

Figure 4.6 Form of previous piecewise linear transform

By applying this transform on the original image in Figure 4.3(a) we get


the following output image:

Figure 4.7 Result of thresholding


Piecewise linear functions are commonly used for contrast enhancement
and gray-level slicing as we will see in this lecture.

©Asst. Lec. Wasseem Nahy Ibrahem Page 5


Image Processing Lecture 4

Example:
For the following piecewise linear chart determine the equation of
the corresponding grey-level transforms:

Piecewise Linear Transform


255
240
225
210
Output Gray Level, s

195
180
165
150
135
120
105
90
75
60
45
30
15
0
0
15
30
45
60
75
90
105
120
135
150
165
180
195
210
225
240
255
Input Gray Level, r

Solution
We use the straight line formula to compute the equation of each line
segment using two points.

Points of line segment 1: Points of line segment 2:


(0,0) , (89,89) (90,30) , (180,210)

Points of line segment 3:


(181,255),(255,255)

©Asst. Lec. Wasseem Nahy Ibrahem Page 6


Image Processing Lecture 4

The piecewise linear


function is:

Log transformation
The general form of the log transformation is

where c is a constant, and it is assumed that . This transformation is


used to expand the values of dark pixels in an image while compressing
the higher-level values as shown in the figure below.

Log Transform
10
Output Gray Level, s

9
8
7
6
5
4
3
2
1
0
0

105
120
135
150
165
180
195
210
225
240
255
15
30
45
60
75
90

Input Gray Level, r

Figure 4.8 Form of Log transform


The figure below shows an example of applying Log transform.

(a) Original image (b) Result of Log transform with c = 1


Figure 4.9 Applying log transformation
©Asst. Lec. Wasseem Nahy Ibrahem Page 7
Image Processing Lecture 4

Note the wealth of detail visible in transformed image in comparison with


the original.

Power-law transformation
Power-law transformations have the basic form:

where c and y are positive constants. The power y is known as gamma,


hence this transform is also called Gamma transformation. The figure
below shows the form of a power-law transform with different gamma (y)
values.

Figure 4.10 Form of power-law transform with


various gamma values (c = 1 in all cases)

Power-law transformations are useful for contrast enhancement. The next


figure shows the use of power-law transform with gamma values less
than 1 to enhance a dark image.
©Asst. Lec. Wasseem Nahy Ibrahem Page 8
Image Processing Lecture 4

(a) (b)

(c) (d)
Figure 4.11 (a) Original MRI image of a human spine. (b)-(d) Results of applying power-law
transformation with c = 1 and y = 0.6,0.4, and 0.3, respectively.

We note that, as gamma decreased from 0.6 to 0.4, more detail became
visible. A further decrease of gamma to 0.3 enhanced a little more detail
in the background, but began to reduce contrast ("washed-out" image).

The next figure shows another example of power-law transform with


gamma values greater than 1, used to enhance a bright image.

©Asst. Lec. Wasseem Nahy Ibrahem Page 9


Image Processing Lecture 4

(a) (b)

(c) (d)
Figure 4.12 (a) Original bright image. (b)-(d) Results of applying power-law transformation
with c = 1 and y = 3, 4, and 5, respectively.

We note that, suitable results were obtained with gamma values of 3.0
and 4.0. The result obtained with y = 5.0 has areas that are too dark, in
which some detail is lost.

From the two examples, we note that:


• Dark areas become brighter and very bright areas become slightly
darker.
• Faint (bright) images can be improved with y >1, and dark images
benefit from using y <1.
©Asst. Lec. Wasseem Nahy Ibrahem Page 10
Image Processing Lecture 4

Image Dynamic range, Brightness and Contrast


The dynamic range of an image is the exact subset of gray values
{0,1,…,L-1} that are present in the image. The image histogram gives a
clear indication on its dynamic range.

• When the dynamic range of an image is concentrated on the low


side of the gray scale, the image will be a dark image.

• When the dynamic range of an image is biased toward the high


side of the gray scale, the image will be a bright (light) image.

• An image with low contrast has a dynamic range that will be


narrow and will be centered toward the middle of the gray scale.
Low-contrast images tend to have a dull, washed-out gray look,
and they can result from 1) poor illumination, 2) lack of dynamic
range in the imaging sensor, or 3) wrong setting of lens aperture at
the image capturing stage.

• When the dynamic range of an image contains a significant


proportion (i.e. covers a broad range) of the gray scale, the image is
said to have a high dynamic range, and the image will have a high
contrast. In high-contrast images, the distribution of pixels is not
too far from uniform, with very few vertical lines being much
higher than the others.

The figure below illustrates a gray image shown in four basic gray-level
characteristics: dark, light, low-contrast, and high-contrast. The right side
of the figure shows the histograms corresponding to these images.

©Asst. Lec. Wasseem Nahy Ibrahem Page 11


Image Processing Lecture 4

Dark
image

Light
image

Low-
contrast
image

High-
contrast
image

Figure 4.13 Four basic image types: dark, light, low-contrast, high-contrast, and their
corresponding histograms.

©Asst. Lec. Wasseem Nahy Ibrahem Page 12


Image Processing Lecture 4

Contrast stretching
aims to increase (expand) the dynamic range of an image. It transforms
the gray levels in the range {0,1,…, L-1} by a piecewise linear function.
The figure below shows a typical transformation used for contrast
stretching.
The locations of points
(r1, s1) and (r2, s2)
control the shape of the
transformation function.

Figure 4.14 Form of transformation function

For example the following piecewise linear function

Contrast Stretching
255
240
225
Output Gray Level, s

210
195
180
165
150
135
120
105
90
75
60
45
30
15
0
15
30
45
60
75
90
0

105
120
135
150
165
180
195
210
225
240
255

Input Gray Level, r

Figure 4.15 Plot of above piecewise linear function

©Asst. Lec. Wasseem Nahy Ibrahem Page 13


Image Processing Lecture 4

will be used to increase the contrast of the image shown in the figure
below:

(a) (b)

(c) (d)
Figure 4.16 Contrast stretching. (a) Original image. (b) Histogram of (a). (c) Result of
contrast stretching. (d) Histogram of (c).

For a given plot, we use the equation of a straight line to compute the
piecewise linear function for each line:

©Asst. Lec. Wasseem Nahy Ibrahem Page 14


Image Processing Lecture 4

For example the plot in Figure 4.15, for the input gray values in the
interval [28 to 75] we get:

Similarly, we compute the equations of the other lines.

Another form of contrast stretching is with clipping at both ends as shown


in the example below:

255
Output Gray Level, s

204

153

102

51

0
0
15
30
45
60
75
90
105
120
135
150
165
180
195
210
225
240
255

Input Gray Level, r

Figure 4.17 Contrast-stretching with clipping at both ends

This transform produces a high-contrast image from the low-contrast


image shown in the next figure.

©Asst. Lec. Wasseem Nahy Ibrahem Page 15


Image Processing Lecture 4

(a) (b)

(c) (d)
Figure 4.18 (a) Low-contrast image. (b) Histogram of (a). (c) High-contrast image resulted
from applying contrast-stretching in Figure 4.17 on (a). (d) Histogram of (c)

Gray-level slicing
Gray-level slicing aims to highlight a specific range [A…B] of gray
levels. It simply maps all gray levels in the chosen range to a high value.
Other gray levels are either mapped to a low value (Figure 4.19(a)) or left
unchanged (Figure 4.19(b)). Gray-level slicing is used for enhancing
features such as masses of water in satellite imagery. Thus it is useful for
feature extraction.

©Asst. Lec. Wasseem Nahy Ibrahem Page 16


Image Processing Lecture 4

(a) (b)
Figure 4.19 Gray-level slicing

The next figure shows an example of gray level slicing:

(a) Original image

(b) Operation intensifies desired gray level (c) Result of applying (b) on (a)
range, while preserving other values (background unchanged)

©Asst. Lec. Wasseem Nahy Ibrahem Page 17


Image Processing Lecture 4

(d) Operation intensifies desired gray level (e) Result of applying (d) on (a) (background
range, while changing other values to black changed to black)

Figure 4.20 Example of gray level slicing

Enhancement through Histogram Manipulation


Histogram manipulation aims to determine a gray-level transform that
produces an enhanced image that has a histogram with desired properties.
An example of histogram manipulation techniques is Histogram
Equalization (HE).

Histogram Equalization
is an automatic enhancement technique which produces an output
(enhanced) image that has a near uniformly distributed histogram.
For continuous functions, the intensity (gray level) in an image
may be viewed as a random variable with its probability density function
(PDF). The PDF at a gray level r represents the expected proportion
(likelihood) of occurrence of gray level r in the image. A transformation
function has the form

©Asst. Lec. Wasseem Nahy Ibrahem Page 18


Image Processing Lecture 4

where w is a variable of integration. The right side of this equation is


called the cumulative distribution function (CDF) of random variable r.
For discrete gray level values, we deal with probabilities (histogram
values) and summations instead of probability density functions and
integrals. Thus, the transform will be:

The right side of this equation is known as the cumulative histogram for
the input image. This transformation is called histogram equalization or
histogram linearization.
Because a histogram is an approximation to a continuous PDF, perfectly
flat histograms are rare in applications of histogram equalization. Thus,
the histogram equalization results in a near uniform histogram. It spreads
the histogram of the input image so that the gray levels of the equalized
(enhanced) image span a wider range of the gray scale. The net result is
contrast enhancement.

©Asst. Lec. Wasseem Nahy Ibrahem Page 19


Image Processing Lecture 4

Example:
Suppose that a 3-bit image (L = 8) of size 64 × 64 pixels has the gray
level (intensity) distribution shown in the table below.

r0 = 0 790
r1 = 1 1023
r2 = 2 850
r3 = 3 656
r4 = 4 329
r5 = 5 245
r6 = 6 122
r7 = 7 81

Perform histogram equalization on this image, and draw its normalized


histogram, transformation function, and the histogram of the equalized
image.

Solution:
M × N = 4096
We compute the normalized histogram:

r0 = 0 790 0.19
r1 = 1 1023 0.25
r2 = 2 850 0.21
r3 = 3 656 0.16
r4 = 4 329 0.08
r5 = 5 245 0.06
r6 = 6 122 0.03
r7 = 7 81 0.02

©Asst. Lec. Wasseem Nahy Ibrahem Page 20


Image Processing Lecture 4

Normalized histogram

Then we find the transformation function:

and , , , , ,

Transformation function
We round the values of s to the nearest integer:

©Asst. Lec. Wasseem Nahy Ibrahem Page 21


Image Processing Lecture 4

These are the values of the equalized histogram. Note that there are only
five gray levels.

r0 = 0 790 s0 = 1 790 0.19


r1 = 1 1023 s1 = 3 1023 0.25
r2 = 2 850 s2 = 5 850 0.21
r3 = 3 656 s3 = 6 985 0.24
r4 = 4 329 s4 = 6
r5 = 5 245 s5 = 7 448 0.11
r6 = 6 122 s6 = 7
r7 = 7 81 s7 = 7
Thus, the histogram of the equalized image can be drawn as follows:

Histogram of equalized image

The figure below shows the results of performing histogram equalization


on dark, light, low-contrast, and high-contrast gray images.

©Asst. Lec. Wasseem Nahy Ibrahem Page 22


Image Processing Lecture 4

Figure 5.1 Left column original images. Center column corresponding histogram equalized
images. Right column histograms of the images in the center column.

©Asst. Lec. Wasseem Nahy Ibrahem Page 23


Image Processing Lecture 4

Although all the histograms of the equalized images are different, these
images themselves are visually very similar. This is because the
difference between the original images is simply one of contrast, not of
content.
However, in some cases histogram equalization may introduce noise and
other undesired effect to the output images as shown in the figure below.

(a) Original image (b) Result of applying HE on (a)

(c) Original image (d) Result of applying HE on (c)


Figure 5.2 Undesired effects caused by HE

These undesired effects are a consequence of digitization. When digitize


the continuous operations, rounding leads to approximations.
From the previous examples, we conclude that the effect of HE differs
from one image to another depending on global and local variation in the
brightness and in the dynamic range.

©Asst. Lec. Wasseem Nahy Ibrahem Page 24


Image Processing Lecture 5

Filtering in the spatial domain (Spatial Filtering)


refers to image operators that change the gray value at any pixel (x,y)
depending on the pixel values in a square neighborhood centered at (x,y)
using a fixed integer matrix of the same size. The integer matrix is called
a filter, mask, kernel or a window.
The mechanism of spatial filtering, shown below, consists simply
of moving the filter mask from pixel to pixel in an image. At each pixel
(x,y), the response of the filter at that pixel is calculated using a
predefined relationship (linear or nonlinear).

Figure 5.1 Spatial filtering

Note:
The size of mask must be odd (i.e. 3×3, 5×5, etc.) to ensure it has a
center. The smallest meaningful size is 3×3.

©Asst. Lec. Wasseem Nahy Ibrahem Page 1


Image Processing Lecture 5

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


The 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.

©Asst. Lec. Wasseem Nahy Ibrahem Page 2


Image Processing Lecture 5

Example:
Use the following 3×3mask to perform the convolution process on the
shaded pixels in the 5×5 image below. Write the filtered image.

0 1/6 0 30 40 50 70 90
1/6 1/3 1/6 40 50 80 60 100
0 1/6 0 35 255 70 0 120
3×3 mask 30 45 80 100 130
40 50 90 125 140
5×5 image

Solution:

and so on …

30 40 50 70 90
40 85 65 61 100
Filtered image = 35 118 92 58 120
30 84 77 89 130
40 50 90 125 140

©Asst. Lec. Wasseem Nahy Ibrahem Page 3


Image Processing Lecture 5

Spatial Filters
Spatial filters can be classified by effect into:
1. Smoothing Spatial Filters: also called lowpass filters. They include:
1.1 Averaging linear filters
1.2 Order-statistics nonlinear filters.
2. Sharpening Spatial Filters: also called highpass filters. For example,
the Laplacian linear filter.

Smoothing Spatial Filters


are 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.

©Asst. Lec. Wasseem Nahy Ibrahem Page 4


Image Processing Lecture 5

The figure below shows two 3×3 averaging filters.

1 1 1 1 2 1
1 1 1 2 4 2
1 1 1 1 2 1
Standard average filter Weighted average filter
Note:
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:

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.

Figure below shows an example of applying the standard averaging filter.

©Asst. Lec. Wasseem Nahy Ibrahem Page 5


Image Processing Lecture 5

(a) (b)

(c) (d)

(e) (f)
Figure 5.2 Effect of averaging filter. (a) Original image. (b)-(f) Results of smoothing with
square averaging filter masks of sizes n = 3,5,9,15, and 35, respectively.

©Asst. Lec. Wasseem Nahy Ibrahem Page 6


Image Processing Lecture 5

As shown in the figure, the effects of averaging linear filter are:


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

Order-statistics filters
are 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
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.
For example, suppose that a 3×3 neighborhood has gray levels (10,
20, 0, 20, 255, 20, 20, 25, 15). These values are sorted as
(0,10,15,20,20,20,20,25,255), which results in a median of 20 that
replaces the original pixel value 255 (salt noise).

©Asst. Lec. Wasseem Nahy Ibrahem Page 7


Image Processing Lecture 5

Example:
Consider the following 5×5 image:
20 30 50 80 100
30 20 80 100 110
25 255 70 0 120
30 30 80 100 130
40 50 90 125 140
Apply a 3×3 median filter on the shaded pixels, and write the filtered
image.

Solution
20 30 50 80 100 20 30 50 80 100
30 20 80 100 110 30 20 80 100 110
25 255 70 0 120 25 255 70 0 120
30 30 80 100 130 30 30 80 100 130
40 50 90 125 140 40 50 90 125 140
Sort: Sort
20, 25, 30, 30, 30, 70, 80, 80, 255 0, 20, 30, 70, 80, 80, 100, 100, 255

20 30 50 80 100
30 20 80 100 110
25 255 70 0 120
30 30 80 100 130
40 50 90 125 140
Sort
0, 70, 80, 80, 100, 100, 110, 120, 130

20 30 50 80 100
30 20 80 100 110
Filtered Image = 25 30 80 100 120
30 30 80 100 130
40 50 90 125 140

©Asst. Lec. Wasseem Nahy Ibrahem Page 8


Image Processing Lecture 5

Figure below shows an example of applying the median filter on an


image corrupted with salt-and-pepper noise.

(a) (b)

(c)
Figure 5.3 Effect of median filter. (a) Image corrupted by salt & pepper noise. (b) Result of
applying 3×3 standard averaging filter on (a). (c) Result of applying 3×3 median filter on (a).

As shown in the figure, the effects of median filter are:


1. Noise reduction
2. Less blurring than averaging linear filter

©Asst. Lec. Wasseem Nahy Ibrahem Page 9


Image Processing Lecture 5

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 order partial derivatives of the digital image f(x,y) are:

The first derivative must be:


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

The second order partial derivatives of the digital image f(x,y) are:

The second derivative must be:


1) zero along flat segments.
2) nonzero at the outset and end of a gray-level step or ramp;

©Asst. Lec. Wasseem Nahy Ibrahem Page 10


Image Processing Lecture 5

3) zero along ramps

Consider the example below:

Figure 5.4 Example of partial derivatives

We conclude that:
• 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 detail (thin
lines, edges, including noise) much more than a first-order derivative.

©Asst. Lec. Wasseem Nahy Ibrahem Page 11


Image Processing Lecture 5

The Laplacian Filter


The Laplacian operator of an image f(x,y) is:

This equation can be implemented using the 3×3 mask:

Since the Laplacian filter is a linear spatial filter, we can apply it 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 figure below shows an example of using Laplacian filter to sharpen


an image.

©Asst. Lec. Wasseem Nahy Ibrahem Page 12


Image Processing Lecture 5

(a) (b)

(c)

Figure 5.5 Example of applying Laplacian filter. (a) Original image. (b) Laplacian image.
(c) Sharpened image.

©Asst. Lec. Wasseem Nahy Ibrahem Page 13


Image Processing Lecture 6

Image Enhancement in the Frequency Domain


• The frequency content of an image refers to the rate at which the
gray levels change in the image.
• Rapidly changing brightness values correspond to high frequency
terms, slowly changing brightness values correspond to low
frequency terms.
• The Fourier transform is a mathematical tool that analyses a signal
(e.g. images) into its spectral components depending on its
wavelength (i.e. frequency content).

2D Discrete Fourier Transform


The DFT of a digitized function f(x,y) (i.e. an image) is defined as:

The domain of u and v values u = 0, 1, ..., M-1, v = 0,1,…, N-1 is called


the frequency domain of f(x,y).

The magnitude of F(u,v), |F(u,v)|= [R2(u,v)+I 2(u,v)]1/2 , is called the


Fourier spectrum of the transform.

©Asst. Lec. Wasseem Nahy Ibrahem Page 1


Image Processing Lecture 6

The phase angle (phase spectrum) of the transform is:

Note that, F(0,0) = the average value of f(x,y) and is referred to as the dc
component of the spectrum.
x+y
It is a common practice to multiply the image f(x,y) by (-1) . In this
x+y
case, the DFT of (f(x,y)(-1) ) has its origin located at the centre of the
image, i.e. at (u,v) = (M/2,N/2).

The figure below shows a gray image and its centered Fourier spectrum.

(a)

(b)
Figure 6.1 (a) Gray image. (b) Centered Fourier spectrum of (a)

©Asst. Lec. Wasseem Nahy Ibrahem Page 2


Image Processing Lecture 6

The original image contains two principal features: edges run


approximately at ±45°.
The Fourier spectrum shows prominent components in the same
directions.

Phase spectrum
Phase data contains information about where objects are in the image, i.e.
it holds spatial information as shown in the Figure below.

(a) Original image (b) Phase only image

(c) Contrast enhanced version of image (b) to show detail


Figure 6.2 Phase spectrum

Fourier transform does not provide simultaneously frequency as well as


spatial information.

©Asst. Lec. Wasseem Nahy Ibrahem Page 3


Image Processing Lecture 6

Inverse 2D-DFT
After performing the Fourier transform, if we want to convert the image
from the frequency domain back to the original spatial domain, we apply
the inverse transform. The inverse 2D-DFT is defined as:

where x = 0,1,…, M-1 and y = 0,1,…, N-1.

Frequency domain vs. Spatial domain


Frequency domain Spatial domain

1. is resulted from Fourier is resulted from sampling and


transform quantization

2. refers to the space defined by refers to the image plane itself,


values of the Fourier i.e. the total number of pixels
transform and its frequency composing an image, each has
variables (u,v). spatial coordinates (x,y)

3. has complex quantities has integer quantities

©Asst. Lec. Wasseem Nahy Ibrahem Page 4


Image Processing Lecture 6

Filtering in the Frequency Domain


Filtering in the frequency domain aims to enhance an image through
modifying its DFT. Thus, there is a need for an appropriate filter function
H(u,v).
The filtering of an image f(x,y) works in 4 steps:
1. Compute the centered DFT, ℑ
2. Compute .
3. Compute the inverse DFT of G(u,v), ℑ .
4. Obtain the real part of ℑ .
5. Compute the filtered image ℑ .

Generally, the inverse DFT is a complex-valued function. However, when


f(x,y) is real then the imaginary part of the inverse DFT vanishes. Thus,
for images step 4, above, does not apply.
The figure below illustrates the filtering in the frequency domain.

Figure 6.3 Basic steps for filtering in the frequency domain

©Asst. Lec. Wasseem Nahy Ibrahem Page 5


Image Processing Lecture 6

Low-pass and High-pass filtering


• Low frequencies in the DFT spectrum correspond to image values
over smooth areas, while high frequencies correspond to detailed
features such as edges & noise.
• A filter that suppresses high frequencies but allows low ones is
called Low-pass filter, while a filter that reduces low frequencies
and allows high ones is called High-pass filter.
• Examples of such filters are obtained from circular Gaussian
functions of 2 variables:

Low-pass filter

High-pass filter

The results of applying these two filters on the image in Figure 6.1(a) are
shown in the figure below.

(a) Low-pass filter function (b) Result of lowpass filtering

©Asst. Lec. Wasseem Nahy Ibrahem Page 6

You might also like