You are on page 1of 67

Yangon Technological University

Electronic Engineering Department


1

Digital Image Processing


BY

DR. WIN KAY KHAING


LECTURER
2

CH 3: Intensity Transformations and


Spatial Filtering
It makes all the difference whether one sees darkness
through the light or brightness through the shadows.
David Lindsay
Spatial Domain

The term spatial domain refers to the image plane itself, and image
processing methods in this category are based on direct manipulation of
pixels in an image.

Two principal categories of spatial processing are intensity


transformations and spatial filtering.

Intensity transformations operate on single pixels of an image,


principally for the purpose of contrast manipulation and image
thresholding.

Spatial filtering deals with performing operations, such as image


sharpening, by working in a neighborhood of every pixel in an image.
Neighborhood
Two Functions

(a) and (b)


Figure 3.2 Intensity transformation functions. (a) Contrast-stretching function.
(b) Thresholding function.
Single-pixel operations
3.2 Some Basic Intensity Transformation Functions

❑ Intensity transformations are among the simplest of all image


processing techniques. Here is the expression:
s = T(r)
where T is a transformation that maps a pixel value r into a pixel value s.

❑ Three basic types of functions used frequently for image enhancement


are:
➢ linear (negative and identity transformations),
➢ logarithmic (log and inverse-log transformations),
➢ power-law (nth power and nth root transformations).

❑ The identity function is the trivial case in which output intensities are
identical to input intensities.
3.2.1 Image Negatives

❑ The negative of an image with intensity levels in the range [0, L-1] is
obtained by using the negative transformation, which is given by the
expression:
s=L–1–r
❑ This type of processing is particularly suited for enhancing white or
gray detail embedded in dark regions of an image, especially when the
black areas are dominant in size.
3.2.2 Log and Inverse-log Transformations

❑ The general form of the log transformation is


s = c log (1 + r)
where c is a constant, and it is assumed that r ≥ 0.
❑ This transformation maps a narrow range of low intensity values in
the input into a wider range of output levels.
❑ The opposite is true of higher values of input levels.
❑ Transformation of this type is used to expand the values of dark pixels
in an image while compressing the higher-level values.
❑ The opposite is true of the inverse-log transformation.
❑ Note: The log function has the important characteristic that it
compresses the dynamic range of images with large variations in pixel
values.
Some Basic Intensity Transformation Functions
3.2.3 Power-Law (Gamma) Transformations

Power-law transformations have the basic form


s = c rγ

where c and γ are positive constants.


Continued:

Plots of s versus r for


various values of γ are
shown in Fig.
Gamma Correction

❑ A variety of devices used for image capture, printing, and display


respond according to a power law.

❑ By convention, the exponent in the power-law equation is referred to as


gamma.

❑ The process used to correct these power-law response phenomena is


called gamma correction.

❑ For example, cathode ray tube (CRT) devices have an


intensity-to-voltage response that is a power function, with exponents
varying from approximately 1.8 to 2.5.

❑ With reference to the curve, such display systems would tend to produce
images that are darker than intended.
Continued:

Gamma Original Image Original Image as viewed on monitor


Correction

Gamma-corrected Image Gamma-corrected Image as viewed


on the same monitor
Continued:

❑ A similar analysis would apply to other imaging devices such as scanners


and printers. The only difference would be the device-dependent value of
Gamma.

❑ Gamma correction has become increasingly important in the past few


years, as the use of digital images for commercial purposes over the
Internet has increased.

❑ It is not unusual that images created for a popular Web site will be
viewed by millions of people, the majority of whom will have different
monitors and/or monitor settings.

❑ Some computer systems even have partial gamma correction built in.
Contrast Manipulation

❑ Power-law transformations are useful for general-purpose contrast


manipulation.

❑ When the given image is predominantly dark, an expansion of intensity


levels is desirable.

❑ This can be accomplished with a power-law transformation with a


fractional exponent.
Contrast Manipulation (Continued:)

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

Figure 3.8: (a) Magnetic resonance image (MRI) of a fractured human


spine. (b)-(d) Results of applying the transformation with c = 1 and γ = 0.6,
0.4, and 0.3, respectively.
Contrast Manipulation (Continued:)

❑ When the image to be processed has a washed-out appearance, it is


indicating that a compression of intensity levels is desirable.

❑ This can be accomplished with a power-law transformation using the


exponent values of greater than 1.
Contrast Manipulation (Continued:)

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

Figure 3.9: (a) Aerial


image. (b)-(d) Results
of applying the
transformation with c
= 1 and γ = 3.0, 4.0,
and 5.0, respectively.
3.2.4 Piecewise-Linear Transformation Functions
3.3 Histogram Processing
Histogram Processing

❑ The histogram of a digital image with intensity levels in the range


[0,L-1] is a discrete function
where rk is the kth intensity value and nk is the number of pixels in the
image with intensity rk.

❑ A normalized histogram is given by


for k = 0, 1,2,…,L-1.

❑ Loosely speaking, is an estimate of the probability of occurrence


of intensity level rk in an image.

❑ The sum of all components of a normalized histogram is equal to 1.


Continued:

❑ The information inherent in histograms also is quite useful in other


image processing applications, such as image enhancement, image
compression and segmentation.
Dark Image and Its Corresponding Histogram
Light Image and Its Corresponding Histogram
Low Contrast Image and Its Corresponding Histogram
High Contrast Image and Its Corresponding Histogram
Two Main Types of Histogram Processing

✓ Histogram Equalization
✓ Histogram Specification
3.3.1 Histogram Equalization

Figure 3.17 (a) Monotonically increasing function, showing how multiple values can map to a single value.
(b) Strictly monotonically increasing function. This is a one-to-one mapping, both ways.
Continued:

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,


nk is the number of pixels that have intensity rk
and L is the number of possible intensity levels in the image (e.g., 256
for an 8-bit image).
Continued:

Intensity transformations formula is s = T(r).

The histogram equalization transformation function is

A processed (output) image is obtained by mapping each pixel in the input


image with intensity rk into a corresponding pixel with level sk in the output
image, using the above equation.
The transformation (mapping) T(rk) in this equation is called a histogram
equalization or histogram linearization transformation.
Example 3.5 A simple illustration of histogram
equalization

Q: Suppose that a 3-bit image (L=8) of size 64×64 pixels (MN=4096) has
the intensity distribution shown in the following table, where the intensity
levels are integers in the range [0, L-1]=[0,7]. Draw the histogram
corresponding to these intensity levels. And then, Perform the histogram
equalization and draw the resulting histogram.
Example 3.5 Solution

For a 3-bit image (L=8) of size 64×64 pixels, the total number of pixels is
MN=4096.
Example 3.5 Solution

Values of the histogram equalization transformation function are:


Example 3.5 Solution (Continued:)

Rounded Values are:


Example 3.8 Solution (Continued:)

Matching Table between r (original image pixel) and s (image pixel after
processing histogram equalization )

r s
0 1
1 3
2 5
3 6
4 6
5 7
6 7
7 7
Example 3.5 Solution (Continued:)

Calculation of Equalized Histogram:

rk nk sk nk (for sk ) ps (sk)=nk/(MN)
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
r6 =6 122 s6 =7 448 0.11
r7 =7 81 s7 =7
Example 3.5 Solution (Continued:)

Calculation of Equalized Histogram:


Example 3.6 Histogram Equalization
Original Image Histogram Equalized Image Histogram
Example 3.6 Histogram Equalization (Continued:)
Original Image Histogram Equalized Image Histogram
Conclusion about Histogram Equalization

❑ Histogram equalization automatically determines a transformation


function that seeks to produce an output image that has a uniform
histogram.

❑ When automatic enhancement is desired, this is a good approach


because the results from this technique are predictable and the method
is simple to implement.
Problems

1. The following table gives the number of pixels at each of the grey levels 0-7
in an image with those grey values only:

0 1 2 3 4 5 6 7
3244 3899 4559 2573 1428 530 101 50
Draw the histogram corresponding to these grey levels, and then perform a
histogram equalization and draw the resulting histogram.

2. The following table gives the number of pixels at each of the grey levels 0-15
in an image with those grey values only. In each case draw the histogram
corresponding to these grey levels, and then perform a histogram equalization
and draw the resulting histogram.
Problems
(a)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

20 40 60 75 80 75 65 55 50 45 40 35 30 25 20 30

(b)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 0 40 80 45 110 70 0 0 0 0 0 0 0 0 15
Problems

3. The following small image has grey values in the range 0 to 19. Compute the
grey level histogram and the mapping that will equalize this histogram.
Produce an 8×8 grid containing the grey values for the new
histogram-equalized image.

12 6 5 13 14 14 16 15
11 10 8 5 8 11 14 14
9 8 3 4 7 12 18 19
10 7 4 2 10 12 13 17
16 9 13 13 16 19 19 17
12 10 14 15 18 18 16 14
11 8 10 12 14 13 14 15
8 6 3 7 9 11 12 12
3.3.2 Histogram Matching (Specification)
Histogram Matching (Histogram Specification)

The method used to generate a processed image that has a specified


histogram (not the uniform histogram) is called histogram matching or
histogram specification.
Example 3.8 A simple example of histogram
specification
Q: Suppose that a 3-bit image (L=8) of size 64×64 pixels (MN=4096) has
the intensity distribution shown in the following left table, where the
intensity levels are integers in the range [0, L-1]=[0,7]. Transform the
histogram of the given image so that it will have the specified value in the
given right table.
Example 3.8 Solution
Step 1
For a 3-bit image (L=8) of size 64×64 pixels, the total number of pixels is
MN=4096.
Example 3.8 Solution

Values of the histogram equalization transformation function are:


Example 3.8 Solution (Continued:)

Rounded Values are:


Example 3.8 Solution (Continued:)

Matching Table between r (original image pixel) and s (image pixel after
processing histogram equalization )

r s
0 1
1 3
2 5
3 6
4 6
5 7
6 7
7 7
Example 3.8 Solution (Continued:)

Calculation of Equalized Histogram:

rk nk sk nk (for sk ) ps (sk)=nk/(MN)
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
r6 =6 122 s6 =7 448 0.11
r7 =7 81 s7 =7
Example 3.8 Solution (Continued:)

Step 2
Calculation of all possible values of transformation function G:

Where q= 0,1,2,…,L-1
Example 3.8 Solution (Continued:)

Rounded Values are:


Example 3.8 Solution (Continued:)

Step 3
Matching Table between s (image pixel after processing histogram
equalization ) and z (the image pixel we specified).

s z
1 3
3 4
5 5 or
6 6
6 6
7 7
7 7
7 7
Example 3.8 Solution (Continued:)
Step 4
Calculation of Specified Histogram:

rk nk sk nk (for sk ) zq nk (for zq ) pz (zq)= nk/(MN)

r0 =0 790 s0 =1 790 3 790 0.19


r1 =1 1023 s1 =3 1023 4 1023 0.25
r2 =2 850 s2 =5 850 5 850 0.21
r3 =3 656 s3 =6
985 6 985 0.24
r4 =4 329 s4 =6
r5 =5 245 s5 =7
r6 =6 122 s6 =7 448 7 448 0.11
r7 =7 81 s7 =7
Example 3.8 Solution (Continued:)
3.3.3 Local Histogram Processing
3.3.4 Using Histogram Statistics for Image
Enhancement
Statistics (Mean and Variance)

❑ Statistics (mean value and variance value) obtained directly from an


image histogram can be used for image enhancement.

❑ Mean is a measure of average intensity.

❑ Variance (or standard deviation) is a measure of contrast in an image.


Example 3.11 Computing Histogram Statistics

Q: Consider the following 2-bit image of size 5 × 5.

0 0 1 1 2
1 2 3 0 1
3 3 2 2 0
2 3 1 0 0
1 1 3 2 2
Compute the histogram statistics values: mean and variance.
Example 3.11 Solution

The pixels are represented by 2 bits; therefore, L = 4 and the intensity levels
are in the range [0, 3]. The total number of pixels is 25.
Example 3.11 Solution
Two uses of Mean and Variance

❑ There are two uses of the mean and variance for enhancement purposes.

❑ The global mean and variance are computed over an entire image and are
useful for gross adjustments in overall intensity and contrast.

❑ A more powerful use of these parameters is in local enhancement, where


the local mean and variance are used as the basis for making changes
that depend on image characteristics in a neighborhood about each pixel
in an image.
Matlab Built-in Functions

>> p=imread('Fig0320(4)(bottom_left).tif');
>> imshow(p)
>> imhist(p)
>> ph=histeq(p);
>> imshow(ph)
>> imhist(ph)
Any Questions!!!

You might also like