Image Processing and Machine Learning Volume 1 Foundations of Image Processing 1st Edition Cuevas Instant Download
Image Processing and Machine Learning Volume 1 Foundations of Image Processing 1st Edition Cuevas Instant Download
https://ebookbell.com/product/image-processing-and-machine-
learning-volume-1-foundations-of-image-processing-1st-edition-
cuevas-54734782
https://ebookbell.com/product/image-processing-and-machine-learning-
volume-2-advanced-topics-in-image-analysis-and-machine-learning-1st-
edition-erik-cuevas-54730812
https://ebookbell.com/product/artificial-intelligence-and-machine-
learning-techniques-in-image-processing-and-computer-vision-karm-veer-
arya-ciro-rodriguez-rodriguez-saurabh-singh-abhishek-singhal-55754878
https://ebookbell.com/product/applications-of-optimization-and-
machine-learning-in-image-processing-and-iot-nidhi-gupta-52601230
https://ebookbell.com/product/python-for-computer-vision-unlocking-
image-processing-and-machine-learning-with-python-mark-
jackson-147611288
Artificial Intelligence And Machine Learning In 2d3d Medical Image
Processing 1st Edition Rohit Raja Editor
https://ebookbell.com/product/artificial-intelligence-and-machine-
learning-in-2d3d-medical-image-processing-1st-edition-rohit-raja-
editor-34710588
https://ebookbell.com/product/advances-in-soft-computing-and-machine-
learning-in-image-processing-1st-edition-aboul-ella-hassanien-6789716
https://ebookbell.com/product/fusion-of-artificial-intelligence-and-
machine-learning-for-advanced-image-processing-data-analysis-and-
cyber-security-arun-kumar-rana-59788584
Reasonable efforts have been made to publish reliable data and information, but the author and
publisher cannot assume responsibility for the validity of all materials or the consequences of
their use. The authors and publishers have attempted to trace the copyright holders of all material
reproduced in this publication and apologize to copyright holders if permission to publish in this
form has not been obtained. If any copyright material has not been acknowledged please write and
let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known
or hereafter invented, including photocopying, microfilming, and recording, or in any information
storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.
com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA
01923, 978-750-8400. For works that are not available on CCC please contact mpkbookspermissions@
tandf.co.uk
Trademark notice: Product or corporate names may be trademarks or registered trademarks and are
used only for identification and explanation without intent to infringe.
DOI: 10.1201/9781003287414
Typeset in Palatino
by codeMantra
Contents
1. Pixel Operations..............................................................................................1
1.1 Introduction............................................................................................1
1.2 Changing the Pixel Intensity Value.....................................................2
1.2.1 Contrast and Illumination or Brightness..............................2
1.2.2 Delimitation of Results by Pixel Operations.........................3
1.2.3 Image Complement..................................................................4
1.2.4 Segmentation by Threshold....................................................5
1.3 Histogram and Pixel Operations.........................................................7
1.3.1 Histogram..................................................................................7
1.3.2 Image Acquisition Characteristics.........................................8
1.3.3 Calculating the Histogram of an Image with MATLAB..... 11
1.3.4 Color Image Histograms........................................................ 12
1.3.5 Effects of Pixel Operations on Histograms......................... 13
1.3.6 Automatic Contrast Adjustment........................................... 15
1.3.7 Cumulative Histogram.......................................................... 18
1.3.8 Histogram Linear Equalization............................................ 19
1.4 Gamma Correction..............................................................................22
1.4.1 The Gamma Function............................................................ 23
1.4.2 Use of Gamma Correction..................................................... 24
1.5 MATLAB Pixel Operations................................................................. 25
1.5.1 Changing Contrast and Illumination in MATLAB........... 25
1.5.2 Segmenting an Image by Thresholding
Using MATLAB....................................................................... 25
1.5.3 Contrast Adjustment with MATLAB................................... 26
1.5.4 Histogram Equalization Using MATLAB........................... 29
1.6 Multi-Source Pixel Operations........................................................... 31
1.6.1 Logical and Arithmetic Operations..................................... 32
1.6.2 Alpha Blending Operation.................................................... 35
References........................................................................................................ 35
2. Spatial Filtering............................................................................................. 36
2.1 Introduction.......................................................................................... 36
2.2 What Is a Filter?.................................................................................... 36
2.3 Spatial Linear Filters............................................................................ 38
2.3.1 The Filter Matrix..................................................................... 39
2.3.2 Filter Operation....................................................................... 39
2.4 Calculation of Filter Operations in MATLAB.................................. 41
2.5 Types of Linear Filters.........................................................................43
v
vi Contents
3. Edge Detection............................................................................................... 89
3.1 Borders and Contours......................................................................... 89
3.2 Edge Detection Using Gradient-Based Techniques........................90
3.2.1 Partial Derivative and Gradient............................................ 91
3.2.2 Derived Filter........................................................................... 92
3.3 Filters for Edge Detection................................................................... 92
3.3.1 Prewitt and Sobel Operators................................................. 93
3.3.2 The Roberts Operator............................................................. 96
3.3.3 Compass Operators................................................................ 96
3.3.4 Edge Detection with MATLAB............................................. 98
3.3.5 MATLAB Functions for Edge Detection........................... 101
3.4 Operators Based on the Second Derivative.................................... 104
3.4.1 Edge Detection Using the Second-Derivative
Technique............................................................................... 105
3.4.2 Sharpness Enhancement in Images................................... 108
3.4.3 Use of MATLAB for the Implementation of the
Laplacian Filter and the Enhancement of Sharpness...... 109
3.4.4 The Canny Filter................................................................... 111
3.4.5 MATLAB Tools that Implement the Canny Filter............ 112
References...................................................................................................... 113
Contents vii
Index...................................................................................................................... 205
Preface Volume 1
ix
x Preface Volume 1
Erik Cuevas
Alma Nayeli Rodriguez
Guadalajara, Jalisco, Mexico
1
Pixel Operations
1.1 Introduction
Pixel operations refer to those operations performed on images where only
the pixel value of interest p = I ( x , y ) from the image is considered [1]. Each
new pixel value calculated p ′ = I ′ ( x , y ) is dependent on the value of the origi-
nal pixel p = I ( x , y ) at the same position. Thus, it is independent of the values
of other pixels, such as its closest neighbors. The new pixel value is deter-
mined through a function f I ( x , y ) , so that:
f I ( x , y ) → I ′ ( x , y ) (1.1)
Figure 1.1 shows a representation of this type of operation. If, as in the previ-
ous case, the function f (⋅) is independent of the image coordinates, its values
do not depend on the pixel position, so the function is called homogeneous.
Examples of typical homogeneous operations are:
FIGURE 1.1
Representation of pixel operations, in which the resulting pixel depends only on the value of
the function operating on the original pixel.
DOI: 10.1201/9781003287414-1 1
2 Image Processing and Machine Learning, Volume 1
On the other hand, non-homogeneous pixel operations consider not only the
value of the pixel in question but also its relative position in the image, that
is I ′ ( x , y ) .
g I ( x , y ) , x , y → I ′ ( x , y ) (1.2)
( )
fc I ( x , y ) = I ( x , y ) ⋅ 1.5 (1.3)
( )
f h I ( x , y ) = I ( x , y ) + 100 (1.4)
Pixel Operations 3
(a) (b)
FIGURE 1.2
Graphical representation of the mapping generated for the resulting pixel I′(x, y): (a) when
changing the value of c in Equation 1.5 with b = 0, and (b) when changing the value of b in
Equation 1.5 with c = 1.
The generic operator f (⋅), which is used to modify the contrast or illumina-
tion in an image, can be formulated as follows:
I ( x, y ) = f ( x, y ) = c ⋅ I ( x, y ) + b ; (1.5)
where c modifies the contrast value and b changes the brightness or illumi-
nation value, Figure 1.2 shows graphically the different effects produced by
distinct values of c and b.
Figure 1.3 shows the result of applying the above homogeneous operations
on an image.
The previous operation will have the effect of eliminating any excess pro-
duced by the application of the homogeneous operation on the image. This
effect is often referred to in the literature as “clamping.” Another problem
in the use of homogeneous operations performed on pixels occurs when the
4 Image Processing and Machine Learning, Volume 1
(a) (b)
(c)
FIGURE 1.3
Examples of applying homogeneous pixel operations. (a) Original image, (b) image with 50%
contrast increment, and (c) image with illumination decreased by 100 levels.
calculated value of the new pixel is less than the lower limit defined for an
8-bit grayscale image. This can happen when the value of the illumination is
reduced to some levels, producing negative values. This problem, as well as
the previous one, is avoided if the program is protected with the following
instructions:
If (Ixy < 0)
Ixy = 0;
1.2.3 Image Complement
Image complement or inversion is considered a pixel operation in which
the pixel value is altered in the opposite direction (by multiplying the pixel
value by −1), while on the other hand, a constant intensity value is added.
Under this operation, the result falls within the allowed range of values. For
one pixel p = I ( x , y ) on range of values 0, pmax the complement or inversion
operation is defined as:
(a) (b)
FIGURE 1.4
Result of applying the complement pixel operation to an image. (a) Original grayscale image
and (b) complement.
I=imread(‘extension’);
Ig=rgb2gray(I);
IC=255-Ig;
1.2.4 Segmentation by Threshold
Segmentation by thresholding can be considered a special form of quanti-
fication in which the image pixels are divided into two classes depending
on their relationship with a predefined threshold value pth. All pixels in the
image assume two different values p0 or p1 depending on their relationship
to the threshold, formally defined as:
p0 si p < pth
fth ( p ) = (1.7)
p1 si p ≥ pth
where 0 < pth < pmax. A frequent application of this operation is the bina-
rization of a grayscale image by considering a p0 = 0 y p1 = 1. An example
of applying segmentation by using thresholding on an image is shown in
Figure 1.5. The effect of binarization can be clearly seen in the resulting his-
togram of the image, where the whole distribution is divided into only two
parts p0 y p1 as shown in Figure 1.6.
6 Image Processing and Machine Learning, Volume 1
(a) (b)
107 10
5
2.5
2.5
2 2
Frequency
Frequency
1.5 1.5
1 1
0.5 0.5
0 0
(c) (d)
FIGURE 1.5
Example showing the application of segmentation by using thresholding on an image, consid-
ering p0 = 0, p1 = 1 y pth = 80. In addition, (c) and (d) show the respective histograms of (a) and (b).
FIGURE 1.6
The effect of the binarization operation on the histogram. The threshold value is pth.
(left) Original histogram and (right) histogram resulting from the operation, concentrating
their values at two different points. p0 y p1.
Pixel Operations 7
1.3.1 Histogram
Histograms are elements that describe the frequency at which the intensity
values (pixels) of the image are distributed. In the simplest case, histograms
are best understood when they describe the distribution of grayscale images.
An example is shown in Figure 1.7. For a grayscale image I ( u, v ) with inten-
sities in the range [ 0, K − 1] generate a histogram H with exactly K different
values. Therefore, for a typical 8-bit grayscale image, a histogram will use
H = 2 8 = 256. Each element of the histogram is defined as h ( i ) , correspond-
ing to the number of pixels in the image with an intensity value i, for all
values of 0 ≤ i < K . This can be expressed as follows:
{
h ( i ) = card1 ( u, v ) I ( u, v ) = i } (1.8)
h ( 0 ) is then the number of pixels with the value 0, h ( 1) the number of pix-
els that have the value of 1, and so on, while finally h ( 255 ) represents the
number of white pixels (with the maximum intensity value) in the image.
10 4
12
10
Frequency
(a) (b)
FIGURE 1.7
(a) 8-bit intensity (grayscale) image and (b) its histogram.
8 Image Processing and Machine Learning, Volume 1
6
h(i)
i
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
h(i) 0 2 9 0 0 0 5 7 3 9 1 6 3 6 3 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
FIGURE 1.8
The vector of a histogram with 16 possible intensity values. The index of the elements of the
vector i = 0…15 represents the intensity value. The value of 9 of intensity 2 means that in the
corresponding image, the intensity value 2 appears 9 times.
FIGURE 1.9
Three different images that produce the same histogram.
1.3.2.1 Lighting
Illumination errors are recognized in the histogram because there are no pix-
els in the final or initial region of the intensity scale, while the middle regions
of the histogram present a concentration of pixels with different intensity
values. Figure 1.10 shows an example of images with different types of illu-
mination. It is possible to observe that the pixels in image (a) cover the entire
dynamic (0–255) width of the histogram (b). On the other hand, images (c)
and (e) have histograms with intensity values concentrated in whiter colors
(values close to 255) and in the darker colors (values close to 0), histograms
(d) and (f), respectively.
1.3.2.2 Contrast
The definition of contrast is understood as the range of intensity values that
are used in a given image, or, in short, the difference between the maximum
and minimum intensity values of the pixels present in the image. A full con-
trast image uses the full range of intensity levels defined for the image from
0 to K − 1 (black to white). It is, therefore, easy to observe the contrast of an
image using a histogram. Figure 1.11 shows different contrast settings in
images from the histograms produced.
1.3.2.3 Dynamics
Under the term dynamics, we understand the number of different pixels
that are used in the image. The ideal case in an image is presented when
the full range of available intensity values K is used for the image in ques-
tion. In this case, the whole region of intensity values is covered completely.
An image that covers a region of intensity values smaller than the full one
( amin = 0, amax = K − 1) so that:
amin > 0 or amax < K − 1 (1.9)
5
10
3.5
2.5
Frequency
2
1.5
0.5
(a) (b)
5
10
2.5
Frequency
2
1.5
0.5
(c) (d)
5
10
3.5
2.5
Frequency
1.5
0.5
(e) (f)
FIGURE 1.10
The figures show how lighting errors are easily detected by the histogram. (a) Image with cor-
rect illumination, (c) with high illumination, and (e) with poor illumination. (b), (d), and (f) are
the histograms of (a), (c), and (e), respectively.
While the contrast of an image can be high as long as the maximum value
of the pixel intensity range is not exceeded, the dynamics of an image cannot
be high (except by interpolation of the pixel intensity values). High dynam-
ics represent an advantage for an image because the risk of losing image
quality through the following processing steps is reduced. For this reason,
digital cameras and professional scanners have a resolution higher than
8 bits, u
sually 12–14 bits, even if the image display elements have a normal
resolution of 256.
Pixel Operations 11
(a) (b)
5 5
10 10
5
4
4
3
Frequency
Frequency
3
2
2
1 1
0 0
(c) (d)
FIGURE 1.11
The figures show different contrasts in images and their respective effects on the histogram.
(a) Normal contrast and its histogram (c); and (b) low contrast and its histogram (d).
[counts,x]=imhist(I, n)
This function calculates and displays the histogram of the I image. The num-
ber of histogram values if n is not specified depends on the type of image
involved. If I corresponds to a grayscale image, the function will use 256
values for the calculation and display. If I represents a binary image, the
function will calculate the histogram with only two values.
If n is specified, the histogram is calculated and displayed using n intensity
values instead of those specified by the image type. The variable counts
symbolizes a vector that contains the number of pixels.
12 Image Processing and Machine Learning, Volume 1
10 5
5
Frequency
3
(a) (d)
6
10
2
1.5
Frequency
1
0.5
(b) (e)
10 6
5
4
Frequency
0
XLabel
0 50 100 150 200 255
Intensity
(c) (f)
FIGURE 1.12
Different dynamics in an image and their effects on the histogram. (a) High dynamics, (b) low
dynamics with 20 intensity levels, (c) very low dynamics with only 8 intensity levels, (d) histo-
gram of (a), (e) histogram of (b), and (f) histogram of (c).
1.3.4.1 Brightness Histograms
The brightness histogram of an image is nothing more than the histogram of
the corresponding grayscale version of the color image. Since the grayscale
Pixel Operations 13
(a) (b)
10 5
3.5
2.5
Frequency
1.5
0.5
(c)
FIGURE 1.13
Brightness histogram of a single plane from a color image. (a) Color image, (b) its grayscale ver-
sion (luminance image), and (c) the corresponding histogram of (b).
images are extracted from the color image, they represent the histograms of
the different planes that compose it. Figure 1.13 shows the luminosity histo-
gram of a color image.
5
10
3.5
2.5
Frequency
2
1.5
0.5
(a) (b)
4 4
10 10 4 10
12
12
12
10
10 10
8 8
Frequency
Frequency
Frequency
8
6 6
6
4 4 4
2 2 2
0 0 0
0 50 100 150 200 255 0 50 100 150 200 255 0 50 100 150 200 255
Intensity Intensity Intensity
FIGURE 1.14
Histograms of the components from a color image. (a) Original RGB image, (b) histogram of
Luminosity (hLUM), (c) histogram of the red channel (hR), (d) histogram of the green channel (hG),
and (e) histogram of the blue channel (hB),
the values will tend to approach the upper limit of the allowed dynamic
range (to intensity values of 255). On the other hand, an increase in the con-
trast of some images causes the respective histogram to extend its values
within the interval of intensities (0–255). The complement operation on an
image or inversion provokes the histogram to reflect itself, but in the oppo-
site direction from its original position. Although the above cases seem
straightforward (even trivial), it might be useful to discuss in detail the rela-
tionships between pixel operations and the histograms resulting from such
operations.
Figure 1.15 illustrates the way in which each region of the image with a
homogeneous intensity i belongs to element i in the histogram. This element
i corresponds to all pixels having an intensity value of i.
As a result of an operation such as those mentioned above, the histogram
value can shift, with the effect that all pixels belonging to this intensity value
change. However, what happens when two different intensity values coin-
cide as a result of an operation? In that case, both sets of pixels are merged,
and the full amount of both is added together to generate a single intensity
value for the histogram. Once different intensity levels have been merged
into one, it is not possible to differentiate the subsets of pixels. Consequently,
it is not possible to divide them. From the above, it is possible to conclude
Pixel Operations 15
FIGURE 1.15
Histogram values corresponding to a different set of pixels in the image. If a histogram element
is shifted as a consequence of an operation, then all pixels of the corresponding set will also be
modified in the same way. When two histogram elements h(p1) y h(p2) are joined together, their
corresponding sets of pixels are also added together and are now non-separable.
that this process or operation is associated with a loss in the dynamics and
information of the image.
FIGURE 1.16
The auto-contrast operation, in which from Equation 1.10, the pixel value p is linearly interpo-
lated from the interval [plow, phigh] to the interval [pmin, pmax].
16 Image Processing and Machine Learning, Volume 1
is considered as the smallest of the allowable range (zero for an 8-bit grayscale
image), and then the contrast (see Figure 1.16) is modified by the factor:
pmax − pmin
(1.10)
phigh − plow
pmax − pmin
f ac = ( p − plow ) + pmin (1.11)
phigh − plow
255
fac = ( p − plow ) ⋅ + pmin (1.12)
phigh − plow
The value of the interval pmin , pmax does not always mean that it is the maxi-
mum permissible range of image representation, but it can also represent
any range of interest for an image representation. Under such conditions,
(a) (b)
5
10 5 10
5 5
4 4
Frequency
Frequency
3 3
2 2
1 1
0 0
FIGURE 1.17
The effect of the auto contrast operation. (a) Original image with low contrast, (b) enhanced
image, (c) histogram of the original image, and (d) histogram of the enhanced image.
Pixel Operations 17
this method originally planned to increase the contrast can also be used
to represent the image within a particular permissible range plow and phigh .
Figure 1.17 shows the effect of the auto-contrast operation p′.
As can be seen from Figure 1.17, the self-adjustment of contrast performed
by using Equation. 1.11 can produce that the extreme pixel values contained
in the image change radically or very little the complete distribution of the
resulting histogram. This is because the values of plow and phigh from the
original histogram involve a very small number of pixels that do not signifi-
cantly represent the complete distribution. To avoid this problem, some fixed
( )
percentages slow , shigh are defined from which the distribution is considered
significant for both the starting point (dark pixels) and the end element (light
pixels) of the distribution. With these percentages, we calculate the new
FIGURE 1.18
Auto-contrast operation considers percentage values to generate new boundaries. They now
represent the significant values of the distribution. All values between 0 y alow as well as ahigh
and 255 are ignored in the adjustment so that the resulting image reflects an improvement in
contrast.
18 Image Processing and Machine Learning, Volume 1
boundaries of the distribution. For this purpose, the lower boundary alow is
considered the intensity value at which the number of pixels of lower intensi-
ties added together is greater than or equal to slow. Likewise, ahigh is the upper
boundary intensity value at which the number of pixels of higher intensities
added together is less than or equal to shigh . See Figure 1.18 for an illustration
of the process. The values alow y ahigh depend on the image content and can be
easily calculated from the cumulative histogram. H ( i ) of image I, such that:
{
alow = min i H ( i ) ≥ M ⋅ N ⋅ slow } (1.13)
{
ahigh = max i H ( i ) ≤ M ⋅ N ⋅ 1 − shigh( )} (1.14)
where M ⋅ N is the number of pixels in the image I. All values outside the
interval alow y ahigh are not considered for contrast enhancement, while val-
ues within this range are linearly scaled to occupy the permissible range
pmin , pmax . The pixel operation used to perform the auto-contrast operation
can be formulated as follows:
p si low min
fmac = ( p − alow ) si alow < p < ahigh (1.15)
p si high max
In practice, slow y shigh are assigned the same value. They typically assume
values within the interval [0.5, 1.5]. An example of this operation is provided
by the popular image-processing program Photoshop, where the value of s is
set to slow = 0.5 in order to perform auto-adjustment of the contrast in images.
1.3.7 Cumulative Histogram
The cumulative histogram is a variant of the normal histogram. It provides
important information for performing pixel-by-pixel operations on images
(point operations), for example, to balance a histogram. The cumulative his-
togram H ( i ) is defined as:
H (i) = ∑ h( j)
j= 0
para 0 ≤ i < K (1.16)
The value of H ( i ) is then the sum of all the elements below the specified
value i of the “classical” histogram h ( j ) with the values j = 0…i. or the value
obtained considering the immediately preceding value
Pixel Operations 19
h ( 0) para i = 0
H (i) = (1.17)
H ( i − 1) + h ( i ) para 0 ≤ i < K
H ( K − 1) = ∑h( j) = MN
j= 0
(1.18)
(a)
4
10 10 6
12
12
10
10
8
Frequency
Frequency
8
6
6
4 4
2 2
0
0
0 50 100 150 200 255
0 50 100 150 200 255
Intensity Intensity
(b) (c)
FIGURE 1.19
(a) Original image, (b) histogram of (a), and (c) the cumulative histogram of (a).
20 Image Processing and Machine Learning, Volume 1
FIGURE 1.20
Representation of the equalization process of a histogram. Using a pixel operation on an image
with the original histogram h(i), the idea is to obtain the histogram heq(i), the cumulative histo-
gram H(i) and the balanced version represented by Heq(i) as the effect of the operation.
as possible, distributed over all intensity levels (see Figure 1.20). Since we are
dealing with discrete distributions, this is only possible at the approximation
level because, as already discussed above, the homogeneous operations can
only shift or merge groups of pixels belonging to a certain intensity level.
However, once they are together, it is not possible to separate them. Therefore,
it is not possible to remove the histogram peaks from the distribution. Under
such conditions, it is not possible to produce, from the original histogram, an
ideal histogram heq, where all gray levels are equally distributed. Instead of
this, it is possible only to transform the image so that the histogram shows an
approximation to the balanced distribution of gray levels. Such an approxi-
mation can be achieved by the cumulative histogram H ( i ) . An important
feature of this transformation is that a version of the cumulative histogram
H eq represents a balanced (target) distribution. Obviously, as presented in the
previous statement, this is only an approximation. However, it is possible in
this way to use a pixel operation that shifts the histogram elements in such
a way that the cumulative histogram of the image shows at least approxi-
mately an increasing linear function, as exemplified in Figure 1.20.
The pixel operation feq ( p ) required to balance the histogram of an image
is calculated from its cumulative histogram. For an image with a resolution
M × N pixels in the range of [ 0...K − 1] the operation can be defined as follows:
K − 1
feq ( p ) = H ( p ) ⋅ (1.19)
MN
Pixel Operations 21
FIGURE 1.21
Through the use of the correct pixel operation feq the intensity value p is shifted to p′ in such a
way that it best approximates the cumulative target histogram Heq(i).
H (i) H (i) h( j)
i i
fdD ( i ) = =
H ( K − 1) Sum ( h )
= ∑ Sum ( h) = ∑hN ( i)
j= 0 j= 0
0≤i<K (1.20)
The function fdD ( i ) is, like the cumulative histogram, monotonically increas-
ing, so it follows that:
fdD ( 0 ) = hN ( 0 ) (1.21)
22 Image Processing and Machine Learning, Volume 1
K −1
fdD ( K − 1) = ∑ hN ( i) = 1
i= 0
(1.22)
1.4 Gamma Correction
So far, in this book, the word “intensity” has been used several times,
with the understanding that the pixel values of an image are somehow
related to these concepts. However, how does the value of a pixel actually
relate to the amount of light on a monitor or to the number of toner particles
that the laser printer needs to form a certain intensity value on the paper?
In general, the relationship between the intensity value of a pixel and its
respective p hysical measurements is complex and, in all cases, non-linear.
Therefore, it is important to know at least approximately the nature of these
relationships and thus to be able to predict the appearance of images on
different media.
Gamma correction is a pixel operation that compensates for the differ-
ent image acquisition conditions and allows the display of different char-
acteristics by using a general space of intensities [7]. The expression gamma
originally comes from classical photography, where there is an approxi-
mately logarithmic relationship between the amount of illumination and
density D
illumination B
FIGURE 1.22
Illumination function for photography. The function relates the logarithmic magnitude of the
illumination to the resulting photographic film density over a relatively large region. The slope
∆D
of the function is defined as gamma (γ) of the photographic film γ = .
∆B
Pixel Operations 23
b = fγ ( a ) = aγ
b = fγ ( a ) = aγ
(1.23)
a ∈ , γ > 0
where the parameter γ is the so-called gamma factor. The gamma function
is used only within the interval [0,1], and the function produces a value from
(0,0) to (1,1). As shown in Figure 1.23, when γ = 1, we have fγ ( a ) = a (iden-
tity), generating a line from (0,0) to (1,1). For values of γ < 1, the function is
displayed above the line. For the case γ = 1, if γ > 1, the function is below the
line, where the curvature of the function increases in both directions (above
and below the line) as long as γ is different from 1.
1
γ= 1
20 γ=
5
1
γ= γ =1 γ =2
2
γ =5
γ = 20
FIGURE 1.23
Gamma function b = aγ for different values of γ.
24 Image Processing and Machine Learning, Volume 1
FIGURE 1.24
Principle of gamma correction. To correct the distortion γ c presented by a camera, it is neces-
sary to apply the gamma correction γ c in such a way that the combination of both generates
the elimination of the distortion.
1
The same is applicable to the case of the gamma value with γ = .
γ
The specific values of γ for different devices are usually specified by the
manufacturer and obtained from measurements. For example, the nominal
values for γ of a standard cathode ray tube are between 1.8 and 2.8, with a
typical value of 2.4 for a standard LCD monitor.
s = Bγ c (1.25)
b = fγ c ( s ) = s1 γ c (1.26)
b=s 1/γ c
( )
= B γc 1γc
=B γc
= B1 = B (1.27)
The corrected signal b is identical to the light intensity. Under this opera-
tion, the distortion produced by the camera is eliminated. Figure 1.24 shows
an illustration of this process. The rule of thumb is to find the distortion γ D for
the device in question and compensate for it through gamma correction γ D.
Pixel Operations 25
Everything discussed above assumes that all values are in the interval [0,1].
Obviously, this is not always the case, particularly when dealing with digital
images in the range [0,255]. Considering this, for applying the gamma cor-
rection, the only thing to do is to scale the image interval to values between
0 and 1 and then apply the gamma correction as discussed in this section.
>>B=A*1.5;
>>B=A+10;
can be classified into two classes. Those above this value will be considered
as a particular class, while those below this value will be considered another
class.
>>B=A>128;
The resulting matrix B will be composed of ones and zeros. Ones at those
positions of A where the pixel values are greater than the threshold 128,
while zeros at those points of A where the pixels did not meet the condition.
J=imadjust (I)
J=imadjust(I,[low_in; high_in],[low_out; high_out])
(a) (b)
10 5 10 5
10 6
5
8
4
Frequency
Frequency
6
3
4
2
2 1
FIGURE 1.25
Result of applying the imadjust function. (a) Original image, (b) image resulting from applying
the imadjust function, (c) histogram of the original image, and (d) histogram of the contrast-
corrected image.
I are not considered. It is possible to delimit the boundaries with the empty
matrix [], which means defining the boundaries with the permissible values
for each type of image [0,1].
There are some additional variants of this function that, apart from con-
sidering the contrast enhancement, allow us to further scale the contrast by
means of a parameter (SP). Through this parameter, it is possible to represent
the way in which the images I and J are related when scaled. The structure
of the function is as follows:
This function transforms the values of I to obtain the values of J, as explained
above. However, if SP is less than 1, the mapping is scaled up (brighter) for the
J image values, while if SP is greater than 1, the scaling is done down (darker).
For the case where SP is one, the adjustment is simply linear. Figure 1.25 shows
the effect of applying the imadjust function to an image.
28 Image Processing and Machine Learning, Volume 1
img = imread(‘image.jpg’);
% The image is converted to a grayscale image
img = rgb2gray(img);
% The intensity image is displayed.
figure
imshow(img)
% Display the original histogram of the image
figure
imhist(img)
% Display the cumulative histogram
h = imhist(img);
H = cumsum(h);
figure
bar(H)
% Linear equalization
[m,n] = size(img);
for r = 1:m
for c = 1:n
ImgEq(r,c)=round(H(img(r,c)+1)*(255/(m*n)));
end
end
ImgEq = uint8(ImgEq);
% Enhanced image and histogram are shown
figure
imshow(ImgEq)
figure
imhist(ImgEq)
h2 = imhist(ImgEq);
H2 = cumsum(h2);
figure
bar(H2)
Pixel Operations 29
(a) (b)
5 5
10 10
10
8
8
6
Frequency
Frequency
6
4
4
2 2
0 0
2 2
Frequency
Frequency
1.5 1.5
1 1
0.5 0.5
0 0
0 50 100 150 200 255 0 50 100 150 200 255
Intensity Intensity
(e) (f)
FIGURE 1.26
Result of applying the code described in Program 1.1. (a) Original intensity image, (b) contrast-
enhanced image, (c) histogram of the original image, (d) histogram of the enhanced image, (e)
cumulative histogram of the original image, and (f) cumulative histogram of the enhanced
image.
J = histeq(I, hgram)
J = histeq(I, n)
∑H
i
fT ( fT ( i )) − H hgram ( i ) (1.28)
(a) (b)
105 105
6 6
5 5
4 4
Frequency
Frequency
3 3
2 2
1 1
0 0
10 10
8 8
Frequency
Frequency
6 6
4 4
2 2
0 0
0 50 100 150 200 255 0 50 100 150 200 255
Intensity Intensity
(e) (f)
FIGURE 1.27
Result of applying the function histeq. (a) Source image, (b) result image, (c) histogram
of the source image, (d) flattened histogram resulting from the operation performed by
histeq, (e) cumulative histogram of the source image, and (f) cumulative histogram of the
resulting image.
FIGURE 1.28
Representation of pixel operations, in which the resulting pixel depends on the value of pixels
from different images, keeping the same position.
an image but also on other pixels in different images. Figure 1.28 shows a
representation of such operations.
As can be seen from Figure 1.28, the resulting pixel is obtained from
the application of a function that operates on the two pixels from two dif-
ferent images. It is also considered that all the pixels participating in the
function are from two different images with the same position. The value
from this operation represents the result, which is in the same position as
its sources.
1.6.1.1 Sum
The sum of the two images I A and I B is defined as:
I ′ ( x, y ) = I A ( x, y ) + IB ( x, y ) (1.29)
(a) (b)
(c)
FIGURE 1.29
Superposition of images by applying the sum operator between two images. (a) Image 1,
(b) image 2, (c) superposition of images 1 and 2.
1.6.1.2 Subtract
The difference between the two images I A and I B is defined as:
I ′ ( x, y ) = I A ( x, y ) − IB ( x, y ) (1.30)
1.6.1.3 AND and OR
These operations are performed between binary images using the truth table
for both logic functions. Therefore, in the case of AND, both pixels must be
34 Image Processing and Machine Learning, Volume 1
(a) (b)
(c)
FIGURE 1.30
Movement detection by subtracting images taken at different time instants. (a) Image 1 taken at
instant 1, (b) image 2 taken at instant 2, and (c) subtraction of image 1 and 2.
(a) (b)
(c) (d)
FIGURE 1.31
Effect of applying the Alpha Blending operation. (a) Image IB, (b) image IA, (c) result image IR
with α = 0.3, and (d) result image IR with α = 0.7.
Pixel Operations 35
one in order to generate a pixel one in the resulting image, while in the case
of the OR function with one of the pixels of the image being one is sufficient
reason to generate one in the output image. For any other combination in
both cases, the pixel will be zero in the output image. These functions have
their main activity in block processing, where only those pixels considered
in a certain region will be considered in the processing, while the others will
be set to zero or simply not taken into account.
IR ( x, y ) = (1 − α ) ⋅ I A ( x, y ) + α ⋅ IB ( x, y ) (1.31)
References
[1] Gonzalez, R. C., & Woods, R. E. (2008). Digital image processing (3rd ed.). Prentice
Hall.
[2] Jain, A. K. (1989). Fundamentals of digital image processing. Prentice Hall.
[3] Woods, R. E. (2015). Digital image processing (4th ed.). Pearson.
[4] Gonzalez, R. C., & Wintz, P. (1977). Digital image processing. Addison-Wesley.
[5] Gonzalez, R. C., Woods, R. E., & Eddins, S. L. (2004). Digital image processing
using MATLAB. Prentice Hall.
[6] Burger, W., & Burge, M. J. (2016). Digital image processing: An algorithmic introduc-
tion using Java. Springer.
[7] Szeliski, R. (2010). Computer vision: algorithms and applications. Springer.
[8] Milanfar, P. (2013). A tour of modern image processing: From fundamentals to applica-
tions. CRC Press.
Random documents with unrelated
content Scribd suggests to you:
—Êtes-vous fou de voyager par un temps pareil, monsieur?
—J'ai hâte de rejoindre quelqu'un que j'ai perdu et dont je suis la
trace, répondit l'inconnu.
—Quelle est votre profession? cria le juif.
—Je suis un poète.
XVI
Persécution
À
À Paris, quelques jeunes poètes de la rive gauche épargnés à cause
de leur manque de notoriété organisèrent une manifestation qui
partit de la Closerie des Lilas vers la Conciergerie, où était enfermé
le prince des poètes.
La troupe arriva pour disperser les manifestants. La cavalerie
chargea. Les poètes sortirent des armes et se défendirent, mais le
peuple à cette vue se mêla à la bagarre. On étrangla les poètes et
quiconque se proclamait leur défenseur.
Ainsi commença la persécution qui s'étendit rapidement dans le
monde entier. En Amérique, après l'électrocution des poètes
célèbres, on lyncha tous les chansonniers nègres et même beaucoup
qui de leur vie n'avaient fait de chansons; ensuite on tomba sur les
blancs de la bohème littéraire. On apprit aussi que Tograth, après
avoir dirigé lui-même la persécution en Australie, s'était embarqué à
Melbourne.
XVII
Assassinat
Mais les yeux de Togralh avaient brillé; il avait avisé, pliées, quelques
chansons parisiennes rimées sur des airs viennois, Il prit ces papiers
et après les avoir regardés:
—Ce ne sont que des chansons, dit-il, n'as-tu pas de poésies?
—J'en ai une bien jolie, dit la fille, c'est le pisteur de l'hôtel Victoria
qui me l'a faite avant de partir pour la Suisse. Mais je ne l'ai pas
montrée à Sossi.
Et la foule cria:
«Qui es-tu, qui es-tu?»
Tograth accueillit d'un éclat de rire terrible ces dernières paroles. Les
premiers rangs de la foule ayant vu rire Tograth rirent aussi, et le
rire en éclats, en roulades, en trilles se communiqua bientôt à la
populace tout entière, à Paponat et à Tristouse Ballerinette. Toutes
les bouches ouvertes faisaient face à Croniamantal qui perdait
contenance. On cria parmi les rires:
«À l'eau, le poète!... Au feu, Croniamantal!... Aux chiens, l'amant du
laurier!»
XVIII
Apothéose
Cueillons la marjolaine
La nuit
À
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com