1
Lecture 3
Image Enhancement
Instructor: Dr. Yaser Esmaeili
Email:
[email protected] Department of Computer Science and Software Engineering
Concordia University
Slides modified from materials provided by Drs. Yiming Xiao & Tien Bui
2
Image Enhancement: improving the quality of images
(make it better) or modifying image to bring out hidden
features. Two kinds: spatial domain and frequency
domain.
Image Restoration: correcting images subjected to
noise, blurs, distortions, atmospheric effects, etc
Digital Image
Enhancement
In Spatial domain
(Transform on pixels) In Frequency domain
(Fourier transforms)
Intensity Spatial Filtering
Transformation (asked & decided by
(Pixel Processing) neighbor pixels)
Image Smoothing Sharpening
Negative Filters
Etc. Filters
Linear- Log-
Transform Transform
ation ation
Laplacian-
Median Etc. based Filters
Histogram filter (2nd derivative)
Equalization Average Gradient-
filter based Filters
(1st derivative)
4
Enhancement
equalization
Histogram
https://pyimagesearch.com/
Denoising
Restoration
J. V. Manjon, et al. Journal of Magnetic Resonance Imaging, 2010.
5
Image Enhancement I:
Pixel-wise Operations
6
Image Enhancement: Operating on the Pixels
• Make image “better” for a specific application
– The idea of “better” is somewhat subjective
• We distinguish two domains:
– Spatial or Pixel domain:
– Frequency Domain:
• For this section: Pixel Domain
– Operations on single pixel at a time
– Operations on groups of pixels (neighborhoods)
Pixel
4-Neighbors 8-Neighbors
7
Simplest form of processing: Point Processing
Pixel
T
255
No change
S=T(r)
Image “negative”: s=L-1-r
Thresholding
Black 0 r 255
8
Negative of an image
Original Negative
9
Intensity Transformation: Contrast Stretching
8-bit image, low contrast
(r2,s2)
(r1,s1)
original [rmin, rmax]
(r1, s1) = (rmin, 0)
(r2, s2)=(rmax, L-1)
rmin = rmin of original image
(r1, s1) = (m, 0)
(r2, s2)=(m, L-1)
stretching thresholding
10
The locations of and control the shape of the
transformation function.
a) If and the transformation is a linear
function: no change in intensity.
b) If = m, and the transformation is
a thresholding function: a binary image.
c) In general, (why?)
m
11
Intensity Transformation: Intensity Slicing
The aim is to highlight specific range of intensity of interest.
original processed
12
Simplest form of processing: Point Processing
Pixel
T
255 Common Examples:
• Dynamic Range Compression
s
Gamma Correction
Narrow range of “dark” gets
mapped to broad range of “gray”
0 Black r 255
13
Origins of gamma correction:
• Nonlinear response of CRT’s and imagers
• To correct for this in image display, the images or
commands to the CRT are “pre-distorted”
Luminance
0 Applied/Measured Voltage (U)
14
Gamma Correction
15
16
Fracture
original γ=0.6
γ=0.4 γ=0.3
17
original γ=3
γ=4 γ=5
18
Intensity Transformation: Bit-plane Slicing
Ex. In 8-bit image, grey level 194 is (1 1 0 0 0 0 1 0).
Grey levels (0-127) have the 8th bit = 0, and levels
(128-255) have the 8th bit = 1 (counting bits from right to left)
1
1
0
0
0
0
1
0
194
19
Intensity Transformation: Bit-plane Slicing
Bit-8 Bit-7
Bit-6 Bit-5 Bit-4
Bit-3 Bit-2 Bit-1
20
Histogram Processing
• Distribution of gray-levels can be judged by
measuring a Histogram
15
9
7
5
Histogram:
Graylevel
21
Histogram Processing
22
Histogram Processing:
For B-bit image,
• Initialize 2B counters with 0
• Loop over all pixels x,y
• When encountering gray level f(x,y)=i, increment the
counter number i
• With proper normalization, the histogram can be interpreted
as an estimate of the probability density function (pdf) of the
underlying random variable (the gray-level)
• You can also use fewer, larger bins to trade off amplitude
23
Histogram Processing
One-to-one mapping: no information destruction
24
Example:
25
Take a break!
26
27
Histogram Equalization
• The general idea: map the histogram of the
given image to a flat histogram by performing
a nonlinear operation on the gray value at
each pixel.
• Nonlinear Transformation: s = T(r)
• Questions:
– What is the right transformation?
– How do we find it, given a particular image.
• Analysis for the continuous grayscale first
28
Histogram Equalization
• Consider the histogram of the given (continuous grayscale)
image as a pdf p(r), where r is in the interval [0,L-1].eg L=256
– Recall that as a pdf we have
– Any pixel operation T(r) should map [0,L-1] to [0,L-1]
• Desired properties of T(r):
– Keep the black/white order (T(r) should be monotonic increasing)
– T(r) should be single valued (one-to-one), hence invertible.
• Question: Given image with histogram p(r), what does
histogram of s=T(r) look like in general?
29
Histogram Equalization
• Consider continuous values of intensity
• r = gray level of image to be equalized in the range [0, L-1]
0 : black
L-1: white
Goal is to design a transformation
Assumption about T(r) :
(a)T(r) is single valued and monotonically increasing in the
interval
(b)
Condition (a) assures that
30
• From Probability theory: (See Review Slides p. 36)
• We consider Cumulative Distribution Function (CDF) as a
Transformation
• If T(r) is just a CDF or the integral of the input pdf
then applying results in an image whose pdf is uniform.
(For PDF and CDF see pages 32-34 of the Review Slides)
31
Discrete Case
max intensity
new value input value
32
Example
s0 = 1
s1 = 3
s2 = 5
s3 = 6
s4 = 6 8 grey levels
s5 = 7 n = MxN
s6 = 7
s7 = 7
Example: 3-bit image, L= 8, image size = n = 64x64 = 4096, intensity levels [0,7].
Therefore, p0(r0) = 790/4096 = 0.19, etc…
Note that the gray levels are integers so the values of the equalized histogram
are: s0 = 1, s1 = 3, s2 = 5, s3 = s4 = 6, s5 = s6 = s7 = 7.
33
34
Histogram Equalization (examples)
35
36
Generalizations
• Adaptive Histogram Equalization
• Histogram Matching
– Instead of flattening the histogram, we
want to make the histogram of A look like
the histogram of another image B.
– Procedure (given two images):
• Find transformation (T and U) that flatten
images A, B
• Required transformation is U-1(T(A))
37
Histogram Matching
• Rather than uniform we want to match as closely as
possible to a desired, given pdf.
• r = pixel value before matching
• z = pixel value after matching
• We can compute from the given image, and is given.
What is the Transformation from r to z ?
• In the continuous case:
• Can form Look-up table
38
Approach
Method:
39
Approach
(L-1)
original target
transform Result
40
original target
Approach
transform Result
Method:
s0 = 1, s1 = 3, s2 = 5, s3 = s4 = 6, s5 = s6 = s7 = 7.
G0 = G1 = G2 = 0, G3 = 1 (round-off), G4 = 2, G5 = 5, G6 = 6, G7 =7.
41
Histogram Matching (example)
target
original
transform Result
42
Histogram Matching (example)
43
Comparison of Histogram Equalization and Histogram Matching
Histogram
Equalization
More details
44
Histogram Matching (example)
target
histogram
Transform
Original
histogram
Result
original
45
Local Enhancement using Local Histogram
• Define a “window” as a rectangle neighborhood.
• Move centre of windows across the image. At each
location, compute histogram in the window and do
histogram equalization.
scikit-image.org
46
Local Enhancement using Local Histogram
https://www.geeksforgeeks.org/adaptive-histogram-equalization-in-
image-processing-using-matlab/
• Ridge artifacts due to window selection
• Some constraints may be needed to ensure results
Local Enhancement using Local Histogram
Using histogram statistics for image enhancement
49
Multi-Image “Averaging”
• It may be possible to obtain multiple noise-
corrupted images of a scene and average them
to obtain a less noisy result.
• It is important that there be no motion between
the frames, or that the frames be aligned first.
Given:
Compute:
50
Simple Averaging
Example: Additive noise =
Gaussian with zero
mean & standard
deviation of 64 grey
Original add noise levels
k=8 k=16
Averaging k times
k=64 k=128
51
Character of image noise via averaging
Large N for averaging is desirable but costly
52
Optimal Multi-image “Averaging”
Given:
Compute:
Given the noise statistics of the measured images, what should these
coefficients be to yield the “best” results?
Inversely proportional to the variance of noise in each image
53
MRI scan reconstruction from multiple sensor data
Adaptive averaging for image reconstruction
weights
(Hamilton et al. Europe PMC, 2017 )
54
Summary
• Point processing
✓ Contrast stretching
✓ Intensity slicing
✓ Gamma correction
✓ Bit-plane slicing
• Histogram processing
✓ Histogram equalization (global & local)
✓ Histogram matching
• Multi-image averaging
✓ Simple averaging
✓ Optimal/adaptive averaging
55
Reading from textbook
Chapter 3: Page 120-153
56
Food for thought
• For the bit map, how will the image histogram change if we
remove the lowest-order bit?
• When we preform histogram equalization, why it is very rare that a
perfectly flat histogram can be obtained for the resulting image?
• Why histogram matching often won’t result in the exact histogram
as the template image?
• In what scenario is local histogram equalization beneficial?
• If we want to improve image contrast, will gamma correction be a
good choice? compared to histogram equalization?
• When using averaging of N images to reduce noise, if the standard
deviation of the Gaussian noise is S, what is the standard deviation
of the noise in the noise-reduced image?
https://www.youtube.com/watch?v=-RDYHXwJ1LY