0% found this document useful (0 votes)
157 views17 pages

Chapter-2 (Part-1)

This document discusses several intensity transformation functions and histogram processing techniques for spatial domain image processing. It describes basic intensity transformations including negatives, log transformations, power-law transformations, and piecewise linear transformations. These transformations map input pixel intensities to output intensities and can be used for operations like contrast stretching and intensity-level slicing. The document also discusses histogram processing and how the histogram represents the frequency distribution of intensity values in an image.

Uploaded by

Krithika K
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)
157 views17 pages

Chapter-2 (Part-1)

This document discusses several intensity transformation functions and histogram processing techniques for spatial domain image processing. It describes basic intensity transformations including negatives, log transformations, power-law transformations, and piecewise linear transformations. These transformations map input pixel intensities to output intensities and can be used for operations like contrast stretching and intensity-level slicing. The document also discusses histogram processing and how the histogram represents the frequency distribution of intensity values in an image.

Uploaded by

Krithika K
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/ 17

Module-2

Part-1
Spatial Domain: Some Basic Intensity Transformation Functions, Histogram Processing,
Fundamentals of Spatial Filtering, Smoothing Spatial Filters, Sharpening Spatial Filters.
Some Basic Intensity Transformation Functions: The spatial domain processes we discuss here, are based
on the expression

Where f(x, y) is an input image g(x, y) is the output image, and T is an operator on f defined over a
neighborhood of point (x, y) . The operator can be applied to the pixels of a single image to the pixels of a set
of images. Figure 3.1 shows the basic implementation of Eq. (3-1) on a single image.

The point (x0, y0) shown is an arbitrary location in the image, and the small region shown is a neighborhood
of (x0, y0). Typically, the neighborhood is rectangular, centered on (x0, y0) and much smaller in size than the
image. The process that Fig. 3.1 illustrates consists of moving the center of the neighborhood from pixel to
pixel, and applying the operator T to the pixels in the neighborhood to yield an output value at that location.
Thus, for any specific location (x0, y0) the value of the output image g at those coordinates is equal to the result
of applying T to the neighborhood with origin at (x0, y0) in f.
For example, suppose that the neighborhood is a square of size 3 x 3 and that operator T is defined as “Compute
the average intensity of the pixels in the neighborhood.” Typically, the process starts at the top left of the input
image and proceeds pixel by pixel in a horizontal (vertical) scan, one row (column) at a time. Chapter: Module-2 (1st Part)
The smallest possible neighborhood is of size 1×1. In this case, g depends only on the value of f at a single point
(x,y) and T in Eq. (3-1) becomes an intensity (also called a gray-level, or mapping) transformation function of
the form

Where, for simplicity in notation, we use s and r to denote, respectively, the intensity of g and f at any point
(x,y). For example, if T (r) has the form in Fig. 3.2(a), the result of applying the transformation to every pixel
in f to generate the corresponding pixels in g would be to produce an image of higher contrast than the original,

Digital Image Processing MARC-2020 1


by darkening the intensity levels below k and brightening the levels above k. In this technique, sometimes
called contrast stretching, values of r lower than k reduce (darken) the values of s, toward black. The opposite is
true for values of r higher than k.

Intensity transformation and spatial filtering methods span a broad range of applications, most of the examples
are applications to image enhancement.

Some Basic Intensity Transformation Functions:


Intensity transformations are among the simplest of all image processing techniques. We denote the values of
pixels, before and after processing, by r and s, respectively. These values are related by a transformation T, as
given in Eq. (3-2), that maps a pixel value r into a pixel value s. As an introduction to intensity transformations,
consider Fig. 3.3, which shows three basic types of functions used frequently in image processing:

Chapter: Module-2 (1st Part)

Digital Image Processing MARC-2020 2


IMAGE NEGATIVES:

The negative of an image with intensity levels in the range [0,L-1 ] is obtained by using the negative
transformation function shown in Fig. 3.3, which has the form:

Reversing the intensity levels of a digital image in this manner produces the equivalent of a photographic
negative. This type of processing is used, for example, in enhancing white or gray detail embedded in dark
regions of an image, especially when the black areas are dominant in size. Example: Digital mammogram
showing a small lesion can be analyzed in the formed Negative Image.

LOG TRANSFORMATIONS:

The general form of the log transformation in Fig. 3.3 is

Where c is a constant and it is assumed that r ≥ 0. The shape of the log curve in Fig. 3.3 shows that this
transformation maps a narrow range of low intensity values in the input into a wider range of output levels. For
example, note how input levels in the range [0, L/4] map to output levels to the range [0, 3L/4 ].
We use a transformation of this type to expand the values of dark pixels in an image, while compressing the
higher-level values. The opposite is true of the inverse log (exponential) transformation.

POWER-LAW (GAMMA) TRANSFORMATIONS:

Power-law transformations have the form

are positive constants. Sometimes Eq. (3-5) is written as

Chapter: Module-2 (1st Part)

Digital Image Processing MARC-2020 3


Figure 3.6 shows plots of s as a function of r for various values of gamma and transformations can be obtained
simply by varying gamma. Curves generated with values of
Have exactly the opposite effect as those generated with values of
Reduces to the identity transformation.

The response of many devices used for image capture, printing, and display obey a power law. By convention,
the exponent in a power-law equation is referred to as gamma .The process used to correct these power-law
response phenomena is called gamma correction or gamma encoding.

PIECEWISE LINEAR TRANSFORMATION FUNCTIONS:

Piecewise Linear Functions & piecewise functions can be arbitrarily complex. The main disadvantage of these
functions is that their specification requires considerable user input.

Contrast Stretching: Contrast stretching expands the range of intensity levels in an image so that it spans the
ideal full intensity range of the recording medium or display device.

FIGURE 3.10
Contrast stretching.
(a) Piecewise linear
transformation
function.

Figure 3.10(a) shows a typical transformation used for contrast stretching. The locations of points (r1, s1) and
(r2, s2 ) control the shape of the transformation function. If r1 = s1 and r2 = s2 the transformation is a linear
function that produces no changes in intensity. If r1 = r2, and s1=0, and s2=L-1 the transformation becomes a
thresholding function that creates a binary image.
Intermediate values of (r1, s1) and (r2, s2 ) produce various degrees of spread in the intensity levels of the
output image, thus affecting its contrast. In general, r1 ≤ r2 and s1 ≤ s2 is assumed so that the function is single
valued and monotonically increasing. This preserves the order of intensity levels, thus preventing the creation of
intensity artifacts. Chapter: Module-2 (1st Part)

Intensity-Level Slicing:
Enhancing features in satellite imagery, such as masses of water, and enhancing flaws in X-ray images.
Intensity-level slicing, can be implemented in several ways, but most are variations of two basic themes.
One approach is to display in one value (say, white) all the values in the range of interest and in another (say,
black) all other intensities.

Digital Image Processing MARC-2020 4


This transformation, shown in Fig. 3.11(a), produces a binary image. The second approach, based on the
transformation in Fig. 3.11(b), brightens (or darkens) the desired range of intensities, but leaves all other
intensity levels in the image unchanged.
.
(a) And (b)
FIGURE 3.11
(a) This transformation
function highlights range
[A,B] and reduces all other
intensities to a lower level.

(b) This function highlights


range [A,B] and leaves other
intensities unchanged

Bit-Plane Slicing:
Pixel values are integers composed of bits. For example, values in a 256-level grayscale image are composed of
8 bits (one byte). Instead of highlighting intensity-level ranges, we could highlight the contribution made to
total image appearance by specific bits. As Fig. 3.13 illustrates, an 8-bit image may be considered as being
composed of eight one-bit planes, with plane 1 containing the lowest-order bit of all pixels in the image, and
plane 8 all the highest-order bits.

FIGURE 3.13
Bit-planes of an 8-bit image.

Thus, we conclude that, storing the four highest-order bit planes would allow us to reconstruct the original
image in acceptable detail. Storing these four planes instead of the original image requires 50% less storage.

Histogram Processing: Chapter: Module-2 (1st Part)


Let rk for k = 0,1,2,……L-1, denote the intensities of an L-level digital image, f(x,y). The unnormalized
histogram of f is defined as

Where nk is the number of pixels in f with intensity rk and the subdivisions of the intensity scale are called
histogram bins. Similarly, the normalized histogram of f is defined as

Digital Image Processing MARC-2020 5


Where, as usual, M and N are the number of image rows and columns, respectively. Mostly, we work with
normalized histograms, which we refer to simply as histograms or image histograms. The sum of p(rk) for all
values of k is always 1. The components of rk are estimates of the probabilities of intensity levels occurring in
an image.

Figure: The horizontal axis of the histograms are values of rk and the vertical axis are values of p(rk).

We see that the components of the histogram of the high-contrast image cover a wide range of the intensity
scale, and the distribution of pixels is not too far from uniform, with few bins being much higher than the
others. Intuitively, it is reasonable to conclude that an image whose pixels tend to occupy the entire range of
possible intensity levels and, in addition, tend to be distributed uniformly, will have an appearance of high
contrast and will exhibit a large variety of gray tones.

Let the variable r denote the intensities of an image to be processed and r is in the range [0, L-1], with r = 0
representing black and r = L − 1 representing white. We focus attention on transformations (intensity mappings)
of the form

that produce an output intensity value, s, for a given intensity value r in the input image. We assume that

(a) T (r) is a monotonically increasing function in the interval 0 ≤ r≤ L −1 ; and

(b) 0 ≤ T (r ) ≤ L −1 for 0 ≤ r ≤ L −1

In some formulations to be discussed shortly, we use the inverse transformation Chapter: Module-2 (1st Part)

In which case we change condition (a) to: (a’) T (r ) is a strictly monotonic increasing function in the interval

0 ≤ r ≤ L −1

The condition in (a) that T(r) be monotonically increasing guarantees that output intensity values will never be
less than corresponding input values, thus preventing artifacts created by reversals of intensity. Condition (b)
Digital Image Processing MARC-2020 6
guarantees that the range of output intensities is the same as the input. Finally, condition (a’ ) guarantees that
the mappings from s back to r will be one-to-one, thus preventing ambiguities.

That is, a monotonic transformation function performs a one-to-one or many-to-one mapping. This is perfectly
fine when mapping from r to s. However, Fig. 3.17(a) presents a problem if we wanted to recover the values of r
uniquely from the mapped values.

This would be possible for the inverse mapping of sk in Fig. 3.17(a), but the inverse mapping of sq is a range of
values, which, of course, prevents us in general from recovering the original value of r that resulted in sq. As
Fig. 3.17(b) shows, requiring that T(r) be strictly monotonic guarantees that the inverse mappings will be single
valued (i.e., the mapping is one-to-one in both directions).This is a theoretical requirement that will allow us to
derive some important histogram processing techniques.

A fundamental result from probability theory is that if pr(r) and T (r) are known, and T (r) is continuous and
differentiable over the range of values of interest, then the PDF of the transformed (mapped) variable s can be
obtained as

Thus, we see that the PDF of the output intensity variable, s, is determined by the PDF of the input intensities
and the transformation function used. A transformation function of particular importance in image processing is

Chapter: Module-2 (1st Part)

Digital Image Processing MARC-2020 7


Where w is a dummy variable of integration. The integral on the right side is the cumulative distribution
function (CDF) of random variable r. Because PDFs always are positive, and the integral of a function is the
area under the function, it follows that the transformation function of Eq. (3-11) satisfies condition (a). This is
because the area under the function cannot decrease as r increases. When the upper limit in this equation is
r=(L − 1) the integral evaluates to 1, as it must for a PDF. Thus, the maximum value of s is L − 1, and condition
(b) is satisfied also.

We know from Leibniz’s rule in calculus that the derivative of a definite integral with respect to its upper limit
is the integrand evaluated at the limit. That is,

Substituting this result for dr / ds in Eq. (3-10), and noting that all probability values are positive, gives the
result

Chapter: Module-2 (1st Part)

We recognize the form of ps(s) in the last line of this equation as a uniform probability density function. Thus,
ps(s) in Eq. (3-13) will always be uniform, independently of the form of pr(r). Figure 3.18 and the below
example illustrate these concepts.

Illustration of Eqs. (3-11) and (3-13).

Suppose that the (continuous) intensity values in an image have the PDF
Digital Image Processing MARC-2020 8
From Eq. (3-11)

A new image with intensities, s, obtained using this transformation; that is, the s values are formed by squaring
the corresponding intensity values of the input image, then dividing them by L − 1.

We can verify that the PDF of the intensities in the new image, is uniform by substituting ps(s) into Eq. (3-13),
and using the fact that

That is,

The last step follows because r is nonnegative and L > 1. As expected, the result is a uniform PDF.
For discrete values, we work with probabilities and summations instead of probability density functions and
integrals, the probability of occurrence of intensity level rk in a digital image is approximated by

Where MN is the total number of pixels in the image, and nk denotes the number of pixels that have intensity r k.

is commonly referred to as a normalized image histogram. Chapter: Module-2 (1st Part)

The discrete form of the transformation in Eq. (3-11) is

Where, as before, L is the number of possible intensity levels in the image (e.g., 256 for an 8-bit image). Thus, a
processed (output) image is obtained by using Eq. (3-15) to map each pixel in the input image with intensity r k

Digital Image Processing MARC-2020 9


into a corresponding pixel with level sk in the output image, This is called a histogram equalization or histogram
linearization transformation.

Illustration of the mechanics of Histogram Equalization.

Suppose that a 3-bit image (L = 8) of size 64 x 64 pixels (MN = 4096) has the intensity distribution in
Table 3.1, where the intensity levels are integers in the range [0 , L-1] = [0 , 7].

The histogram of this image is sketched in Fig. 3.19(a). Values of the histogram equalization transformation
function are obtained using Eq. (3-15).

Similarly, s1 = T(r 1) = 3.08, s2 = 4.55, s3 = 5.67, s4 = 6.23, s5 = 6.65, s6 = 6.86 and s7 = 7.00 . . This
transformation function has the staircase shape shown in Fig. 3.19(b). At this point, the s values are fractional
because they were generated by summing probability values, so we round them to their nearest integer values in the
range [ 0, 7]:

These are the values of the equalized histogram. Observe that the transformation yielded only five distinct
intensity levels. Because r0 = 0 was mapped to s0 = 1, there are 790 pixels in the histogram equalized image
Chapter: Module-2 (1st Part)
with this value Also, there are 1023 pixels with a value of s1 = 3 and 850 pixels with a value of s2 = 5.
However, both r3 and r4 were mapped to the same value, 6, so there are ( 656 +329) = 985 pixels in the
equalized image with this value. Similarly, there are (245+122+81)=448 pixels with a value of 7 in the
histogram equalized image. Dividing these numbers by MN = 4096 yielded the equalized histogram in Fig.
3.19(c).

1
Digital Image Processing MARC-2020 0
(a), (b),(c)
FIGURE 3.19 Histogram equalization. (a) Original histogram. (b) Transformation function. (c) Equalized histogram
Because a histogram is an approximation to a PDF, and no new allowed intensity levels are created in the
process, perfectly flat histograms are rare in practical applications of histogram equalization. The process of
histogram equalization consists entirely of implementing Eq. (3-15), which is based on information that can be extracted
directly from a given image, without the need for any parameter specifications.

The inverse transformation from s back to r is denoted by

Inverse transformation satisfies conditions (a’) and (b) defined earlier only if all intensity levels are present in
the input image.

Histogram Equalization:

The left column in Fig. 3.20 shows the four images .The center column shows the result of performing
histogram equalization on each of these images. The first three results from top to bottom show significant
improvement. As expected, histogram equalization did not have much effect on the fourth image because its
intensities span almost the full scale already.

Figure 3.21 shows the transformation functions used to generate the equalized images in Fig. 3.20. These
functions were generated using Eq. (3-15). Observe that transformation (4) is nearly linear, indicating that the
inputs were mapped to nearly equal outputs.

Chapter: Module-2 (1st Part)


Shown is the mapping of an input value rk to a corresponding output value sk. In this case, the mapping was for
image 1 (on the top left of Fig. 3.21), and indicates that a dark value was mapped to a much lighter one, thus
contributing to the brightness of the output image

The third column in Fig. 3.20 shows the histograms of the equalized images. While all the histograms are
different, the histogram-equalized images themselves are visually very similar. This is not totally unexpected
because the basic difference between the images on the left column is one of contrast, not content. Because the
images have the same content, the increase in contrast resulting from histogram equalization was enough to
render any intensity differences between the equalized images visually indistinguishable. This example
illustrates the power of histogram equalization as an adaptive, autonomous contrast-enhancement tool. 1
Digital Image Processing MARC-2020 1
.

FIGURE 3.20
Left column:
Images from Fig.
3.16.
Center column:
Corresponding
histogram-equalized
images.
Right column:
histograms of the
images in
the center column
(compare with the
histograms
in Fig. 3.16).

Chapter: Module-2 (1st Part)

Histogram equalization produces a transformation function that seeks to generate an output image with a
uniform histogram. 1
Digital Image Processing MARC-2020 2
HISTOGRAM MATCHING (SPECIFICATION):

When automatic enhancement is desired, this is a good approach to consider because the results from this
technique are predictable and the method is simple to implement. However, there are applications in which
histogram equalization is not suitable. In particular, it is useful sometimes to be able to specify the shape of the
histogram that we wish the processed image to have. The method or technique used to generate images that
have a specified histogram is called histogram matching or histogram specification.

Consider for a moment continuous intensities r and z which, as before, we treat as random variables with PDFs
pr(r) and pz(z) respectively. Here, r and z denote the intensity levels of the input and output (processed) images,
respectively. We can estimate pr(r) from the given input image, pz(z) is the specified PDF that is output image.

Let s be a random variable with the property

Where w is dummy variable of integration. This is the same as Eq. (3-11)

Define a function G on variable z with the property

Where v is a dummy variable of integration. It follows from the preceding two equations that G(z) = s = T(r)
and, therefore, that z must satisfy the condition.

The transformation function T(r) can be obtained using Eq. (3-17) after pr(r) has been estimated using the input
image. Similarly, function G (z) can be obtained from Eq. (3-18) because pz(z) is given.

Equations (3-17) through (3-19) imply that an image whose intensity levels have a specified PDF can be
obtained using the following procedure:

Chapter: Module-2 (1st Part)


1. Obtain pr(r) from the input image to use in Eq. (3-17).

2. Use the specified PDF, pz(z) in Eq. (3-18) to obtain the function G(z).

3. Compute the inverse transformation this is a mapping from s to z, the latter

Beingng the values that have the specified PDF.

4. Obtain the output image by first equalizing the input image using Eq. (3-17); the pixel values in this 1
image are the s values. For each pixel with value s in the equalized image, perform the inverse mapping
Digital Image Processing MARC-2020 3
to obtain the corresponding pixel in the output image. When all pixels have been processed with this
transformation, the PDF of the output image, pz(z) will be equal to the specified PDF.

Because s is related to r by T (r), it is possible for the mapping that yields z from s to be expressed
directly in terms of r. In general, however, finding analytical expressions for Inverse of (G) is not a
trivial task. Fortunately, this is not a problem when working with discrete quantities.
We have to convert the continuous result just derived into a discrete form. This means that we work with
histograms instead of PDFs.
As in histogram equalization, we lose in the conversion the ability to be able to guarantee a result that
will have the exact specified histogram.
The discrete formulation of Eq. (3-17) is the histogram equalization transformation in Eq. (3-15), which
we repeat here for convenience:

Where the components of this equation are as before. Similarly, given a specific value of sk , the discrete
formulation of Eq. (3-18) involves computing the transformation function

for a value of q so that

Where pz(zi) is the ith value of the specified histogram.


Finally, we obtain the desired value zq from the inverse transformation:

When performed over all pixels, this is a mapping from the s values in the histogram equalized image to
the corresponding z values in the output image.
Given an input image, a specified histogram, pz(zi), i = 0,1,2,… L-1 and recalling that the sk‘s are the
values resulting from Eq. (3-20), we may summarize the procedure for discrete histogram specification
as follows:
1. Compute the histogram, pr(r), of the input image, and use it in Eq. (3-20) to map the intensities in the

Chapter: Module-2 (1st Part)


input image to the intensities in the histogram-equalized image. Round the resulting values, sk to the
integer range [0, L-1].
2. Compute all values of function
using the Eq. (3-21) for q = 0,1,2,…L-1 where pz(zi), are the values of the specified histogram. Round
the values of G to integers in the range [0, L-1 ].Store the rounded values of G in a lookup table.
3. For every value of sk, k = 0,1,2,…L-1 use the stored values of G from Step 2 to find the corresponding
value of zq so that is closest to Sk. Store these mappings from s to z. When more than one value of zq
gives the same match (i.e., the mapping is not unique), choose the smallest value by convention.
4. Form the histogram-specified image by mapping every equalized pixel with value sk to the 1
corresponding pixel with value zq in the histogram-specified image, using the mappings found in Step 3.
Digital Image Processing MARC-2020 4
In the continuous case, the intermediate step of equalizing the input image is conceptual. It can be
skipped by combining the two transformation functions, T and
Histogram equalization that, in addition to condition (b), inverse functions ( in the present discussion)
have to be strictly monotonic to satisfy condition (a’).

In terms of Eq. (3-21), this means that none of the values pz(zi) in the specified histogram can be zero.
When this condition is not satisfied, we use the “work-around” procedure in Step 3.

Illustration of the mechanics of histogram specification.

Consider the 64 x 64 hypothetical image from as seen in previous class whose histogram is repeated in Fig.
3.22(a). It is desired to transform this histogram so that it will have the values specified in the second
column of Table 3.2. Figure 3.22(b) shows this histogram.

The first step is to obtain the histogram-equalized values

Chapter: Module-2 (1st Part)


In the next step, we compute the values of G(zq) using the values of pz(zq) from Table 3.2 in Eq. (3-21):

These fractional values are rounded to integers in the range [0,7]:

1
Digital Image Processing MARC-2020 5
These results are summarized in Table 3.3. The transformation function, G(zq) is sketched in Fig. 3.23(c).
Because its first three values are equal, G is not strictly monotonic, so condition (a’) is violated. Therefore,
we use the approach outlined in Step 3 of the algorithm to handle this situation. According to this step, we
find the smallest value of z q so that the value G(zq) is the closest to sk.

For example, s0 = 1, and we see that G(z3) = 1 which is a perfect match in this case, so we have the
correspondence s0 →z3 . Every pixel whose value is 1 in the histogram equalized image would map to a
pixel valued 3 in the histogram-specified image. Continuing in this manner, we arrive at the mappings in
Table 3.4.

Chapter: Module-2 (1st Part)

1
Digital Image Processing MARC-2020 6
In the final step of the procedure, we use the mappings in Table 3.4 to map every pixel in the histogram
equalized image into a corresponding pixel in the newly created histogram-specified image. The values of
the resulting histogram are listed in the third column of Table 3.2, and the histogram is shown in Fig.
3.22(d). We see in Table 3.4 that sk = 1 maps to zq = 3, and there are 790 pixels in the histogram equalized
image with a value of 1. Therefore, pz(z3) = 790/4096 = 0.19

Although the final result in Fig. 3.22(d) does not match the specified histogram exactly, the general trend of
moving the intensities toward the high end of the intensity scale definitely was achieved. As mentioned
earlier, obtaining the histogram-equalized image as an intermediate step is useful for explaining the
procedure, but this is not necessary. Instead, we could list the mappings from the r’s to the s’s and from the
s’s to the z’s in a three-column table. Then, we would use those mappings to map the original pixels directly
into the pixels of the histogram-specified image.

Chapter: Module-2 (1st Part)

1
Digital Image Processing MARC-2020 7

You might also like