Faculty of Information Technology
Ton Duc Thang University
August 2023
Image Enhancement
Brightness and contrast
Histogram Equalization
Image histogram
Histogram equalization techniques
Python
Adaptive histogram equalization
OpenCV
Applications
Image fitering
Convolution
Noise removal
@2023 Pham Van Huy and Trinh Hung Cuong 2
Histogram
Histograms shows frequency.
An image histogram, shows frequency of pixels intensity values.
In an image histogram, the x-axis shows the gray level intensities and the y-axis
shows the frequency of these intensities.
The histogram of the above picture of the
@2023 Pham Van Huy and Trinh Hung Cuong Einstein would be something like this 3
Gray level histograms
To measure a histogram:
For B-bit image, initialize 2B counters with 0
Loop over all pixels x,y
When encountering gray level f [x,y]=i, increment counter #𝑖
Normalized histogram can be thought of as an estimate of the probability
distribution of the continuous signal amplitude
Use fewer, larger bins to trade off amplitude resolution against sample size
@2023 Pham Van Huy and Trinh Hung Cuong 4
Histogram calculation
@2023 Pham Van Huy and Trinh Hung Cuong 5
@2023 Pham Van Huy and Trinh Hung Cuong 6
How to read the histogram
Along the horizontal axis (x) and
from left to right you have:
First the black tones, with pure black
on the left edge.
Then come the shadows.
Then the midtones.
Followed by the highlights.
And finally, the white tones, with
pure white on the right edge.
@2023 Pham Van Huy and Trinh Hung Cuong 7
Gray level histograms
@2023 Pham Van Huy and Trinh Hung Cuong 8
Gray level histograms
@2023 Pham Van Huy and Trinh Hung Cuong 9
Histogram
Applications of Histograms:
We can predict about an image by just looking
at its histogram. Its like looking an x ray of a
bone of a body.
For brightness purposes.
To equalize an image used in adjusting
contrast of an image.
Histogram has wide use in thresholding an
image.
@2023 Pham Van Huy and Trinh Hung Cuong 10
Which is brighter?
@2023 Pham Van Huy and Trinh Hung Cuong 11
Brightness
Brightness can be defined as the amount of energy output by a source of
light (Wiki)
Brightness is the perceived intensity of light coming from a source
Brightness is a relative term. It depends on your visual perception.
@2023 Pham Van Huy and Trinh Hung Cuong 12
Brightness enhancement
+ 50
Sliding histogram
@2023 Pham Van Huy and Trinh Hung Cuong 13 13
+ 50
@2023 Pham Van Huy and Trinh Hung Cuong 14 14
- 80
@2023 Pham Van Huy and Trinh Hung Cuong 15 15
Brightness enhancement
Exposure problem
Over-exposed photo
Under-exposed photo
Flash
RAW image
HDR technology
High-dynamic-range photographs
are generally achieved by capturing
multiple standard-exposure images,
often using exposure bracketing, and
then later merging them into a single
HDR image, usually within a photo
manipulation program.
@2023 Pham Van Huy and Trinh Hung Cuong 16
Contrast
the difference between maximum and minimum pixel intensity in an image.
@2023 Pham Van Huy and Trinh Hung Cuong 17
Contrast enhancement
Digital Image Processing (Graduate
4/5/2020 Pham Van Huy and Trinh Hung Cuong
@2023 18
18
Course)
Histogram equalization example
Original ... after histogram
image Bay equalization
@2023 Pham Van Huy and Trinh Hung Cuong 19
@2023 Pham Van Huy and Trinh Hung Cuong 20
@2023 Pham Van Huy and Trinh Hung Cuong 21
Contrast enhancement
Histogram Stretching
Increasing the contrast of an image
@2023 Pham Van Huy and Trinh Hung Cuong 22
Contrast enhancement
Histogram Stretching
𝑓 𝑥, 𝑦 − 𝑓𝑚𝑖𝑛
𝑔 𝑥, 𝑦 = × 2𝑏𝑝𝑝 − 1
𝑓𝑚𝑎𝑥 − 𝑓𝑚𝑖𝑛
f(x,y) denotes the intensity value of each pixel
fmin and fmax are the minimum and maximum pixel intensity, respec.
𝑏𝑝𝑝 is the number of bits per pixel. In our case, the image is 8bpp, 𝑏𝑝𝑝 = 8.
@2023 Pham Van Huy and Trinh Hung Cuong 23
Contrast enhancement
Histogram Stretching - example
Contrast = 225
The minimum value is 0 and the maximum value is 225. So the formula in our case
is
@2023 Pham Van Huy and Trinh Hung Cuong 24
Contrast enhancement
Histogram Stretching - example
Contrast = 255
@2023 Pham Van Huy and Trinh Hung Cuong 25
Contrast enhancement
Histogram Equalization
a technique to adjust contrast levels and expand
the intensity range in a digital image.
Thus, it enhances the image which makes
information extraction and further image
processing easier.
@2023 Pham Van Huy and Trinh Hung Cuong 26
Histogram equalization example
Original ... after histogram
image Bay equalization
@2023 Pham Van Huy and Trinh Hung Cuong 27
Histogram equalization example
@2023 Pham Van Huy and Trinh Hung Cuong 28
Histogram equalization example
Original image ... after histogram
Brain equalization
@2023 Pham Van Huy and Trinh Hung Cuong 29
Histogram equalization example
@2023 Pham Van Huy and Trinh Hung Cuong 30
Histogram equalization example
Original image ... after histogram
Moon equalization
@2023 Pham Van Huy and Trinh Hung Cuong 31
Histogram equalization example
@2023 Pham Van Huy and Trinh Hung Cuong 32
Histogram Equalization - An algorithm
@2023 Pham Van Huy and Trinh Hung Cuong 33
PMF – Probability mass function
CDF = Cumulative density function
Gray Level CDF * (Levels-1)
1 2 7 5 6 CDF
Value = CDF*7
7 2 3 4 5
0 0.11 0
0 1 5 7 3
1 0.22 1
1 2 5 6 7
Pixel Count PMF 2 0.55 3
6 1 0 3 4
0 2 2/25 3 0.66 4
Image pixel values 1 4 4/25 4 0.77 5
2 3 3/25 5 0.88 6
PMF 3 3 3/25 6 0.99 6
4 2 2/25 7 1 7
5 4 4/25
6 3 3/25
CDF
7 4 4/25
@2023 Pham Van Huy and Trinh Hung Cuong 34
EXAMPLE
@2023 Pham Van Huy and Trinh Hung Cuong 35
Example
8 Bit?
N Bit?
@2023 Pham Van Huy and Trinh Hung Cuong 36
Histogram Equalization
Ex. 1
- Write a pseudo code to equalize histogram of a grayscale image.
- Manually do histogram equalization for the following image:
3-bit image
@2023 Pham Van Huy and Trinh Hung Cuong 37
Contrast-limited histogram equalization
If any histogram bin is above the specified contrast limit, those pixels are
clipped and distributed uniformly to other bins before computing the
cumulative distribution function
limit the overamplification of noise
[Link]
[Link]
@2023 Pham Van Huy and Trinh Hung Cuong 38
Contrast-limited
histogram equalization
[Link]
al-Time-Processing-of-Contrast-Limited-
Adaptive-Kokufuta-
Maruyama/787ce60813fde958e6a3f21ad5
072afc587c4241
@2023 Pham Van Huy and Trinh Hung Cuong 39
Contrast-limited
histogram equalization
@2023 Pham Van Huy and Trinh Hung Cuong 40
Contrast-limited Histogram Equalization
Ex. 2
Given the specified contrast limit is 6.
Manually do contrast-limited histogram equalization for the following image:
3-bit image
@2023 Pham Van Huy and Trinh Hung Cuong 41
Adaptive (local) histogram equalization
The global approach is suitable for overall enhancement, but generally fails
when the objective is to enhance details over small areas in an image.
Rafael C. Gonzalez, Richard E. Woods, [2018], Digital image processing, 4th edition, Pearson.
@2023 Pham Van Huy and Trinh Hung Cuong 42
Adaptive (local) histogram equalization
Histogram is not confined to a particular region
After Local Histogram Equalization
[Link]
@2023 Pham Van Huy and Trinh Hung Cuong 43
Adaptive histogram equalization
Histogram equalization based on a histogram obtained from a portion of the image
Sliding window approach: different Tiling approach: image is divided into small blocks
histogram (and mapping) for every pixel called "tiles" (size is 8x8 in OpenCV). Then each of
these blocks are histogram equalized as usual.
Limit contrast expansion in flat regions of the image, e.g., by clipping histogram values
(“Contrast-limited adaptive histogram equalization”) [Pizer, Amburn et al. 1987]
@2023 Pham Van Huy and Trinh Hung Cuong 44
CLAHE (Contrast-Limited Adaptive Histogram
Equalization)
Image is divided into small blocks called "tiles" (size is 8x8 in OpenCV)
Then each of these blocks are histogram equalized as usual.
In a tile, histogram would confine to a small region (unless there is noise). If noise
is there, it will be amplified.
To avoid this, contrast limiting is applied. If any histogram bin is above the specified
contrast limit (by default 40 in OpenCV), those pixels are clipped and distributed uniformly
to other bins before applying histogram equalization.
After equalization, to remove artifacts in tile borders, bilinear interpolation is
applied.
@2023 Pham Van Huy and Trinh Hung Cuong 45
CLAHE
[Link]
[Link]/
@2023 Pham Van Huy and Trinh Hung Cuong 46
Adaptive histogram equalization
Original Global
image histogram
Parrot equalization
Adaptive Adaptive
histogram histogram
equalization, equalization,
8x8 tiles 16x16 tiles
@2023 Pham Van Huy and Trinh Hung Cuong 47
Adaptive histogram equalization
Original Global
image histogram
Dental equalization
Xray
Adaptive Adaptive
histogram histogram
equalization, equalization,
8x8 tiles 16x16 tiles
@2023 Pham Van Huy and Trinh Hung Cuong 48
Adaptive histogram equalization
Original Global
image histogram
Skull Xray equalization
Adaptive Adaptive
histogram histogram
equalization, equalization,
8x8 tiles 16x16 tiles
@2023 Pham Van Huy and Trinh Hung Cuong 49
References
[Link]
[Link]
ned_Slides/[Link]
[Link]
[Link]
[Link]
[Link]
@2023 Pham Van Huy and Trinh Hung Cuong 50
References (ct)
[Link]
@2023 Pham Van Huy and Trinh Hung Cuong 51