Histogram Processing
Histogram
Dark:
h(rk ) nk
Light:
Normalized histogram
p(rk ) nk / MN
Low 255
contrast:
p(r ) 1
k
k 0
High
contrast:
Transformation Function
s T (r) 0 r L 1
A valid transformation function must satisfy two conditions:
(a) T (r) is monotonically increasing, i.e., T(r1 ) T(r2 ) if r1 r2
(b) 0 T (r) L 1 The same range as input
Intensity Transformation Function
Histogram Equalization – Discrete Case
pr (rk ) nk / MN, k 0,1,2,..., L 1
k
L 1k
sk T (rk ) (L 1) pr (r j ) nj
j 0 MN j0
Example
Histogram Equalization – Discrete Case
Histogram equalization is not guaranteed to result in a uniform histogram.
Examples
Histogram Matching Algorithm – Discrete
Image
Histogram Matching Algorithm – Discrete Image
A Discrete Example
s G(z) z
S0=1 G(z0)=0 z0=0
S1=3 G(z1)=0 z1=1
S2=5 G(z2)=0 z2=2
S3=6 G(z3)=1 z3=3
S4=6 G(z4)=2 z4=4
S5=7 G(z5)=5 z5=5
S6=7 G(z6)=6 z6=6
S7=7 G(z7)=7 z7=7
𝑟0 → 𝑧 3
𝑟1 → 𝑧 4
𝑟2 → 𝑧 5
𝑟3, 𝑟4 → 𝑧 6
𝑟5, 𝑟6, 𝑟7 →
𝑧7
Histogram Matching, Example-2
20 3
A Real Example
A Real Example – Histogram Equalization Result
A Real Example – Histogram Matching Result
Original
HE result
Local Histogram Processing
Fundamentals of Spatial Filtering
Fundamentals of Spatial Filtering
Modifying the pixels in an image based on some function of a
local neighborhood of the pixels
p(x,y)
10 30 10
𝑔 𝑝
20 11 20 5.7
11 9 1
N(p)
g(p):
• Linear function
• Correlation
• Convolution
• Nonlinear function
• Order statistic (median)
Linear Filtering
0 0 0
* 0 1 0
0 0 0
Spatial Correlation and Convolution: 1D Signal
Extend to 2D Image
a b
w(s,t) f (x s, y t)
sat b
• Full correlation result has the size
of (𝑀 + 2𝑎, 𝑁 + 2𝑏)
• Cropped result has the size of
(𝑀, 𝑁 ) – the size of the original
image
Linear Filters
General process: Example: smoothing by
• Form new image whose averaging
pixels are a weighted sum • form the average of pixels in
of original pixel values, a neighborhood
using the same set of
weights at each point. Example: smoothing with a
Gaussian
Properties • form a weighted average of
• Output is a linear function of pixels in a neighborhood
the input
Example: finding an edge
• Output is a shift-invariant
function of the input (i.e.
shift the input image two
pixels to the left, the output
is shifted two pixels to the
left)
Smoothing Spatial Filter – Low Pass Filters
Weighted average
a b
w(s,t) f (x s, y t)
• Noise deduction
• reduction of “irrelevant details”
g(x, y) sat b
a b
• edge blurred
w(s, t)
sat b
Normalization factor
Smoothing Spatial Filter
9 1/9 1/9 1/9
Image averaging R zi
1 1/9 1/9 1/9
9 i1 1/9 1/9 1/9
1 1 1
1
* 1 1 1
9
1 1 1
Smoothing Spatial Filter
x2 y 2
1
2D Gaussian filter h(x, y) e 2σ 2
2πσ 2
*
Comparison using Different Smoothing
Filters – Different Kernels
Average Gaussian
Comparison using Different Smoothing
Filters: Different Size
Filter size: 3, 5, 9, 15, 35
Image Smoothing and Thresholding
removed
Sharpening Spatial Filters
Sharpening – highlight the transitions in intensity
by differentiation
Compared to smoothing – blur the transitions by summation
Sharpening Spatial Filters
smooth sharpen
http://www.bythom.com/
sharpening.htm
Sharpening – highlight the transitions in intensity by differentiation
Smoothing – blur the transitions by summation
Sharpening Spatial Filters
Original image
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑐 ∗ 𝑒(𝑥, 𝑦)
Sharpened image Magnifying factor Edge map
We will briefly introduce edge detection here and will have
a more comprehensive discussion when we discuss
image segmentation.
Spatial Filters for Edge Detection
First-order Second-order
First-order VS Second-order Derivative for
Edge Detection
• First-order derivative produces thick edge along
the direction of transition
• Second-order derivative produces thinner edges
Gradient for Image Sharpening
Direction of change 𝜕𝑓
𝑔𝑥 𝜕𝑥
∇𝑓 = grad(𝑓) = 𝑔 =
𝑦 𝜕𝑓
𝜕𝑦
Magnitude of change (gradient image)
𝑀(𝑥, 𝑦) = 𝑚𝑎𝑔(∇𝑓)
= 𝑔2 + 𝑔2 http://en.wikipedia.org/wiki/Image_gradient
𝑥 𝑦
𝑀(𝑥, 𝑦) ≈ |𝑔𝑥 | + |𝑔𝑦 |
Gradient for Image Sharpening
Sum of the coefficients is 0 –
the response of a constant
region is 0
Edge detectors:
•Roberts cross – fast
while sensitive to noise
• Sobel - smooth
Laplacian for Image Sharpening
Laplacian for Image Sharpening
Image Sharpening
Scale the Laplacian by
shifting the intensity
range to [0, L-1]