Image Enhancement Lesson6 20thFeb2024
Image Enhancement Lesson6 20thFeb2024
1
Piecewise-Linear Transformation
Contrast Stretching
Goal:
– Increase the dynamic range of the gray levels for low
contrast images
2
Contrast Stretching Example
3
Piecewise-Linear Transformation: Gray-level slicing
4
Piecewise-Linear Transformation: Bit Plane slicing
6
• we can display an image that only shows the
contribution of a specific bit plane
3/18/2025 7
8 bit planes
Bit-plane 8 Bit-plane 7
Bit- Bit- Bit-
plane 6 plane 5 plane 4
Bit- Bit- Bit-
plane 3 plane 2 plane 1
8
Histograms
A histogram is a graphical representation of the brightness
values that comprise an image i.e. their brightness values (x-
axis) against their frequencies (y-axis)
Histogram of an image with gray levels in the range (0, L-1):
A discrete function ℎ(𝑟𝑘 ) = 𝑛𝑘
Where:
𝑟𝑘 is the kth intensity value, and
𝑛𝑘 is the number of pixels in f with intensity 𝑟𝑘
9
Need for histogram normalization: equalization
3/18/2025 10
Histogram Examples
11
Normalizing the histogram
– Divide the components by the total number of pixels in the image
– Assuming an M x N image, this yields
𝑛𝑘 𝑛𝑘
𝑠𝑘 = 𝑝 𝑟𝑘 = 𝑜𝑟 𝑓𝑜𝑟 𝑘 = 0, 1, 2, … . , 𝐿 − 1
𝑛 𝑀×𝑁
– rk: input intensity
– sk: processed intensity
– k: the intensity range (e.g. 0.0 – 1.0)
– nk: the frequency of intensity k
– n: the sum of all frequencies
– 𝑝(𝑟𝑘 ) is, basically, an estimate of the probability of occurrence of intensity level
𝑟𝑘 in an image 𝛴 𝑝 𝑟𝑘 = 1
15
Histogram Equalization
•Idea: To find a non-linear transformation S= T(r) to be applied
to each pixel of the input image f(x,y), such that a uniform
distribution of gray levels in the entire range results for the
output image g(x,y).
16
Histogram Equalization
A function T(r) is monotonically
increasing
if T(𝑟1 ) < T(𝑟2 ) for 𝑟1 < 𝑟2 ,
and
monotonically decreasing
if T(𝑟1 ) > T(𝑟2 ) for 𝑟1 < 𝑟2 ,
𝑠𝑘 = 𝑇 𝑟𝑘 = 𝑝𝑟 𝑟𝑗 𝑓𝑜𝑟 0 ≤ 𝑘 ≤ 𝐿 − 1
𝑗=0
Where:
𝑛𝑗
𝑝𝑟 𝑟𝑗 = , 𝑗 = 0, … … . . 𝐿 − 1 𝑎𝑛𝑑 𝑛 = σ𝐿−1
𝑗=𝑜 𝑛𝑗 ,
𝑛
𝑛𝑗 : number of pixels with gray level 𝑟𝑗
n : total number of pixels
NB: For digital images, gray level pdf cannot be exactly uniform after
histogram equalization. 18
Histogram Equalization: Example
19
Histogram Equalization: Example
No. of pixels
6
2 3 3 2 5
4 2 4 3 4
3
3 2 3 5
2
2 4 2 4
1
Gray level
4x4 image = 16 pixels, 3 bit image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,7]
histogram
20
Histogram Equalization: Example
Gray
0 1 2 3 4 5 6 7 8 9
Level(j)
No. of
0 0 6 5 4 1 0 0 0 0
pixels
k
n
j 0
j 0 0 6 11 15 16 16 16 16 16
k nj 6 11 15 16 16 16 16 16
s 0 0 / / / / / / / /
j 0 n
16 16 16 16 16 16 16 16
2.6 4.8 6.6
sx7 0 0 7 7 7 7 7
3 5 7
21
Histogram Equalization: Example
No. of pixels
6
3 5 5 3 5
7 3 7 5 4
5 3 5 7 3
2
3 7 3 7
1
Output image
0 1 2 3 4 5 6 7
Gray scale = [0,7] Gray level
Histogram equalization22
Histogram Equalization:
Assignment
a)
24
Histogram Equalization: Example
Notice that the minimum value (52) is now 0 and the maximum value (154) is now 255.
25
Histogram matching
• Histogram matching is a process where a time series, image, or higher
dimension scalar data is modified such that its histogram matches that of another
(reference) dataset.
• A common application of this is to match the images from two sensors with
slightly different responses, or from a sensor whose response changes over time.
The algorithm is as follows.
-The cumulative histogram is computed for each dataset
26
For any particular value (xi) in the data to be adjusted has a cumulative histogram value given by G(xi).
This in turn is the cumulative distribution value in the reference dataset, namely H(xj).
The input data value xi is replaced by xj.
3/18/2025 27
Uses of Histogram processing
• Image enhancements – applications of contrast stretching
• Image statistics
• Image compression
• Image segmentation
• Simple to calculate in software
• Economic hardware implementations
• – Popular tool in real-time image processing
• A plot of this function for all values of k provides a global description
of the appearance of the image (gives useful information for contrast
enhancement)
3/18/2025 28
Contrast Stretching through Histogram
If rmax and rmin are the maximum and minimum gray level of the input image, and
L is the total gray levels of output image, the transformation function for contrast
stretching will be:
𝐿
𝑠 = 𝑇 𝑟 = 𝑟 − 𝑟𝑚𝑖𝑛
𝑟𝑚𝑎𝑥 − 𝑟𝑚𝑖𝑛
29
Arithmetic and Logic Operators
• Arithmetic and logic operations are often applied as
preprocessing steps in image analysis in order to
combine images in various ways.
• Addition, subtraction, division and multiplication
comprise the arithmetic operation, while AND, OR,
and NOT make up the logic operations.
• These operations performed on two images, except
the NOT logic operation which require only one
image, and are done on a pixel by pixel basis
3/18/2025 30
Mathematical/Logical Operations on Images
Addition
–Averaging images for noise removal
Subtraction
–Removal of background from images
–Image enhancement
–Image matching
–Moving/displaced object tracking
Multiplication
–Superimposing of texture on an image
–Convolution and correlation of images
AND and OR operations
–To remove the unnecessary area of an image through
mask operations
3/18/2025 31
Image Averaging for Noise Reduction
A noisy image can be represented by:
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝜂 𝑥, 𝑦
Since the noise is random and the content f(x,y) is fixed, the
noise can be removed by taking more noisy images of the
same object and averaging them out
𝐾
1
𝑔ҧ 𝑥, 𝑦 = 𝑔𝑖 (𝑥, 𝑦)
𝐾
𝑖=1
3/18/2025 32
Image Averaging for Noise Reduction
3/18/2025 33
Image Averaging for Noise Reduction
3/18/2025 34
Image Subtraction
3/18/2025 35
Image Subtraction
3/18/2025 36
Image Subtraction
3/18/2025 37
Image Subtraction
• How to solve problem of negative pixels?
• Assuming we have an 8 bit Grayscale image (Value Range= 0 to
255)
• The result of image subtraction may come in the range of -255 to
+255
• One scheme can be to add 255 to every pixel and then divide by
2
• Method is easy and fast
• Limitations
– Truncation errors can cause loss of accuracy
– Full range of display may not be utilized
3/18/2025 38
Image Subtraction
3/18/2025 39
Examples of Image Subtraction
3/18/2025 40
Examples of Image Subtraction
3/18/2025 41
Example: Background Removal Using Image Subtraction
3/18/2025 42
Example: Background Removal Using Image Subtraction
3/18/2025 43
Image Subtraction
• Condition: images must be geometrically registered
– Obtain the difference in the two images
– Scale the resulting product by adding a constant (say 127 for an 8 bit gray level
image) to the output values will result in a suitable 'difference' image
– areas with little or no change (A) between the original images, will have
resultant brightness values around 127, while those areas where significant
change has occurred (B) will have values higher or lower than 127 - brighter or
darker depending on the 'direction' of change in reflectance between the two
images.
Image Multiplication
• Like other image arithmetic operators, multiplication comes in
two main forms.
– The first form takes two input images and produces an output
image in which the pixel values are just those of the first image,
multiplied by the values of the corresponding values in the
second image.
The multiplication of two images is performed in the obvious way in a single
pass using the formula:
– The second form takes a single input image and produces output in which
each pixel value is multiplied by a specified constant. This latter form is
probably the more widely used and is generally called scaling.
3/18/2025 45
Image Multiplication
Guidelines for Use
3/18/2025 46
Image Multiplication
For instance,
o Image (a) shows a picture of model robot that was taken under low
lighting conditions.
o Image (b) shows a the scaled image of (a) by a factor of 3 – it is
much clearer
o NB: When using pixel multiplication, make sure that the calculated pixel
values don't exceed the maximum possible value.
o Image (c) obtained by scaling image (a) by a factor of 5 using a 8-
bit representation
o
o All the pixels which, in the original image, have a value greater than
51 exceed the maximum value and are (in this implementation)
wrapped around from 255 back to 0.
3/18/2025 47
Examples of Image Multiplication
3/18/2025 48
Examples of Image Multiplication
• Multiplication also provides a good way of "shading" artwork.
You can use it to introduce a sense of diffuse lighting into your
paintings or 3D Colour Graphics objects.
Notice in the example below how the warm and cool grays not only
darken the final 3D rendering, but also influence its color
temperature
3/18/2025 49
Examples of Image Multiplication
• Here you can really see the "black times anything is black, white
times anything is that thing unchanged" rule in action.
3/18/2025 50
An Example of Image Multiplication
Weeks 1 & 2 51
Band Ratios
• It is a method which works by enhancing minor differences
between materials so as to define the slope of spectral curve
between two bands.
• Image ratioing serves to highlight subtle variations in the
spectral responses of various surface covers.
• By ratioing the data from two different spectral bands, the
resultant image enhances variations in the slopes of the
spectral reflectance curves between the two different spectral
ranges that may otherwise be masked by the pixel brightness
variations in each of the bands.
Uses of Band ratio
• 1) reduce environmental conditions such as:
topographic slope and aspect, shadows, or seasonal
changes, sunlight illumination angle and intensity.
–These conditions can cause differences in brightness
values from identical surface materials, hence
hamper the ability of an interpreter or classification
algorithm to identify correctly surface materials or
land use in a remotely sensed image
Band ratios are relative values instead of absolute brightness
values; hence variations in scene illumination as a result of
topographic effects are reduced.
Thus, although the absolute reflectances for forest covered
slopes may vary depending on their orientation relative to the
sun's illumination, the ratio of their reflectances between the two
bands should always be very similar
• 2) Band ratios provide unique information not available
in any single band that is useful for discriminating
between features e.g. soils and vegetation
• E.g. healthy vegetation reflects strongly in the NIR
portion of the spectrum while absorbing strongly in the
visible red. Other surface types, such as soil and water,
show near equal reflectance in both the NIR and red
portions.
• Thus, a ratio image of Landsat NIR divided by Red
band would result in ratios much greater than 1.0 for
vegetation, and ratios around 1.0 for soil and water.
–Thus the discrimination of vegetation from other
surface cover types is significantly enhanced.
• Areas of unhealthy or stressed vegetation, would
show low NIR reflectance, as the ratios would be
lower than for healthy green vegetation.
• 3) Monitoring vegetation conditions using spectral indices
developed involving sums and differences between spectral
bands for various sensors e.g. Normalized Difference
Vegetation Index (NDVI)
𝑵𝑰𝑹 + 𝑹𝒆𝒅
𝑵𝑫𝑽𝑰 =
𝑵𝑰𝑹 − 𝑹𝒆𝒅
• spectral indices are formed by transforming spectral data
using ratios between bands to reduce the data into
meaningful information
• Explore spectral indices and their uses; e.g.
–Normalized Difference Water Index (NDWI), is
highly related to water bodies
–Normalized Burnt Ratio (NBR) - Burnt areas
–normalized difference built-up index (NDBI)- Built
environment, e.t.c.
Applications of arithmetic operations in image
transformation