Professional Documents
Culture Documents
Hacettepe University
Department of Electrical and Electronics Engineering
Today
2
Illustration of Human Eye
The amount of light entering the eye is controlled by the pupil, which dilates and contracts
accordingly. The cornea and lens, whose shape is adjusted by the ciliary body, focus the
light on the retina, where receptors convert it into nerve signals that pass to the brain. A
mesh of blood vessels, the choroid, supplies the retina with oxygen and sugar.
http://psych.athabascau.ca/html/Psych402/Biotutorials/22/intro.shtml
3
Human Visual System (HVS)
Light passes through cornea, iris, lens and form image on retina.
Two types of photoreceptors on retina:
Cones cluster at Fovea, detect color at bright light - photopic vision
Rods spread at back of eye, general vision - scotopic vision
I I+ I
Perceived
Brightness
changes
around
strong
edges.
We do not know
everything about
the eye, for instance
how the optical
illusions are formed.
However, we can
use them in movies,
arts, graphics,
photorealism etc.
Goes through
sampling (spatial)
and quantization
(gray levels)
13
Sampling in 1D
15
Sampling and Quantization in 2D
16
Sampling and Quantization in 2D
17
Sampling
Take the average
within each square.
I C , I S ( r, c )
continuous image sampled image
I C , I S ( r, c )
continuous image sampled image
I C , I S ( r, c )
continuous image sampled image
I C , I S ( r, c )
continuous image sampled image
continuous colors
mapped to a finite,
discrete set of colors.
23
Digital Images
each square is
called a pixel (for
picture element)
24
Pixels
Pixel Location: p = (r , c)
Pixel : [ p, I(p)]
Pixel Value: I(p) = I(r , c)
26
Resampling (up a number of sizes)
27
Interpolation
Shrinking and zooming are image resampling methods.
Interpolation is the process of using known data to
estimate values at unknown locations
28
Nearest Neighbor Interpolation
29
Bilinear interpolation
(but not really linear!)
Uses the four neighbors to estimate the
intensity at a given location.
Let (x,y) be the coordinate at which we want
to assign a gray level value
Let u(x,y) be the intensity value of that
location.
u(x,y) = ax + by + cxy + d
The coefs. a, b, c, d are found from the 4
equations in 4 unknowns obtained from the 4
nearest neighbours of (x,y). 30
Bicubic interpolation
31
Image Enhancement
34
Using image averaging for noise
reduction
As K increases, variability of the pixel values
at each location (x, y) decreases.
g(x, y) approaches the noiseless image f (x, y)
In order to avoid blurring and other artifacts in
the output (average) image, it is necessary
that the images be registered (i.e., spatially
aligned).
35
36
Image Enhancement
37
Image Enhancement
38
Image Enhancement
Log Transformations: s = c log(1+r)
Where c is a constant and r≥0
39
Log transformations
Maps a narrow range of low intensity values
in the input to a wider range of output levels
40
Image Enhancement
Gamma transformation s = c rγ
where c and γ are positive constants
41
Gamma transformations
What can you say about the resulting image?
(darker, lighter etc?)
If γ = 1
If γ = 2.5
γ = 0.2
42
Gamma transformations
What can you say about the resulting image?
(darker, lighter etc?)
>1
Compresses dark values
Expands bright values
<1
Expandsdark values
Compresses bright values
43
Gamma
correction
44
Gamma correction
Many TV’s
have this
correction
now
45
Image Enhancement
Contrast stretching: expand the range of
intensity levels in an image so that it spans
the full intensity range of the display device.
46
Contrast stretching
47
Intensity level slicing
Two options
Do a black& white, highlight the regions of interest
Just brighten or darken the desired range of
intensities
48
Intensity level slicing
49
Bit plane slicing
50
Bit plane slicing
51
Bit plane slicing
52
The Image Histogram
Occurrence
(# of pixels)
Gray Level
10000
5000
Histogram
0
1 2 3 4 5 6 7 8 9 10
gray level
0.25
0.2
0.15
Normalized Histogram
0.1
0.05
0
1 2 3 4 5 6 7 8 9 10
gray level
0.8
0.6
Accumulated Histogram
0.4
0.2
0
1 2 3 4 5 6 7 8 9 10
gray level
Histogram processing
55
Histogram
56
P(I)
0.1
Original image
P(I)
Decreasing 0.1
contrast
P(I)
0.1
Increasing average
I
Histogram Equalization
0 1 2 3 4 5 6 7 8 9 10 11 old
0 0 0 1 1 1 3 5 8 9 9 11 new
Hist. Eq.
30 (30) 30
25 25
(22)
(20) (21)
20 20
Original15 15
Goal
10 10
(5)
5 (4) (4) (4) 5
(3) (3) (3)
(1)
0 0
0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 10 11
30
25
20
15 Result
0 1 2 3 4 5 6 7 8 9 10 11 old
10
0 0 0 1 1 1 3 5 8 9 9 11 new
5
0
0 1 2 3 4 5 6 7 8 9 10 11
Hist. Eq.: Example 1
3500 3500
3000 3000
2500 2500
2000 2000
1500 1500
1000 1000
500 500
0 0
0 50 100 150 200 250 0 50 100 150 200 250
Original Equalized
Hist. Eq.: Example 2
3000 3000
2500 2500
2000 2000
1500 1500
1000 1000
500 500
0 0
0 50 100 150 200 250 0 50 100 150 200 250
Original Equalized
Hist. Eq.: Example 3
Histogram Equalization
65
Histogram
h(rk ) nk
Example:
0 0 2 2
1 1 2 5
1 1 3 4
2 2 3 4
Normalized Histogram
Normally, we normalize h(rk) by n, where n is the total number of
pixels
h(rk ) nk
p(rk )
So, we have
n n
L 1 L 1
nk
k 0
p(rk )
k 0 n
1
Example: n=16
0 0 2 2
1 1 2 5
1 1 3 4
2 2 3 4
Histogram Equalization
dr
p s ( s ) pr ( r )
ds
r Leibniz rule: The
ds d d
T (r ) pr ( w)dw derivative of an integral
with respect to its upper
dr dr dr 0 limit is the integrand
evaluated at the limit
ds
pr ( r )
dr What does this tell us about
ps(s)?
Histogram Equalization
So,
dr 1
Then ds pr (r )
1
p s ( s ) pr ( r ) 1
pr ( r )
r
Which means that using the transformation T (r ) p (w)dw
r
the resulting probability is uniform independent 0
ps ( s ) 1
Histogram Equalization: in discrete form
Find the normalized image histogram pr(rk)
74
Example
75
Histogram Equalization
Transformation Functions
Ex: histogram values
77
Ex:
78
Ex:
79
Try
1. Compute the histogram for the following example
2. Obtain the histogram equalization curve
3. Perform Histogram Equalization
4. Plot the new image and the new histogram
5. What can you say about it?
0 0 2 2
1 1 2 5
1 1 3 4
2 2 3 4
Some examples from the web
82
Histogram Equalization
Is it always a good idea?
Histogram Equalization
Histogram Matching
85
Histogram Matching (specification)
86
Histogram matching
Transforms an image A so that its histogram will
match that of another image B.
Usage: before comparing two images of the same
scene (change detection) acquired under different
lighting conditions or different camera parameters.
G ( z ) T (r )
z G 1 ( s ) G 1 T (r )
An image with a specified pdf can be
obtained from an input image by using the
following procedure:
Obtain the transformation function T(r)
Obtain the transformation function G(z)
Obtain the inverse transfer function G-1
Obtain the output image by applying this
transformation to all of the pixels in the input
image
The result of this procedure will be an image
whose gray levels, z, have the specified pdf
pz(z).
The discrete formulation:
k k nj
sk T (rk ) pr (rj ) k 0,1,2,..., L 1
j 0 j 0 n
k
vk G ( z k ) p z ( z i ) s k k 0,1,2,..., L 1
i 0
z k G 1 T (rk ) k 0,1,2,..., L 1
z k G 1 sk k 0,1,2,..., L 1
vk s k
v=s
Example
hist. match
result
Slide credit: Y. Hel-Or
In cases where corresponding colors between
images are not “consistent” this mapping may fail:
97
Local Histogram Equalization
Histogram Statistics for Image
Enhancement
•Instead of using histogram directly, we can use instead some
statistical parameters obtainable directly from the histogram.
99
Histogram Statistics for Image
Enhancement
100
•The global mean and variance are measured over an entire
image and are useful for gross adjustments of overall intensity
and contrast.
mS xy r s ,t p(rs ,t ) S2xy
( s ,t )S xy
(rs ,t mS ) 2 p(rs ,t )
xy
( s ,t )S xy
mS xy k0 M G where 0 ≤ k0 ≤ 1.
Since we also need to enhance low contrast areas, candidate pixels
can be selected by
S k2 DG
xy where DG is the global standard deviation and k2
is a positive constant.
k1DG ≤ S xy
with k1 < k2
A pixel at (x,y) that meets all the conditions for local
enhancement is processed simply by multiplying it by a
specified constant E to increase the value of its gray level
relative to the rest of the image.
0.2
where E I 2 k 2 Pk
k
0.15
0.1
0.05
0
1 2 3 4 5 6 7 8 9 10
gray level
Image Entropy
EntropyI Pk log Pk
k
0.6
0.5
0.4
entropy(P)
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
P
Entropy of a 2 values variable
• An infrequent event provides more information than a
frequent event
• Entropy is a measure of histogram dispersion
1000
800
600
400
200
entropy=7.4635
10000
9000
8000
7000
6000
5000
4000
3000
2000
1000
entropy=0
Histogram Usage
• Digitizing parameters
• Measuring image properties:
– Average
– Variance
– Entropy
– Contrast
– Area (for a given gray-level range)
• Threshold selection
• Image distance
• Image Enhancement
– Histogram equalization
– Histogram stretching
– Histogram matching
Example: Auto-Focus
• In some optical equipment (e.g. slide projectors) inappropriate
lens position creates a blurred (“out-of-focus”) image
• We would like to automatically adjust the lens
• How can we measure the amount of blurring?
4000
3000
2000
1000
0
0 10 20 30 40 50 60
4000
3000
2000
1000
0
0 10 20 30 40 50 60
kold
255
Threshold value
Threshold Selection
Original Image Binary Image
1000
500
0
0 100 200
50 75
Threshold = 50 Threshold = 75
Segmentation using Thresholding
Original Histogram
1500
1000
500
0
0 100 200
21
Threshold = 21
Adaptive Thresholding
• Thresholding is space
variant.
• How can we choose
the the local threshold
values?
Adaptive Histogram
• In many cases histograms are needed for local areas in an
image
• Examples:
– Pattern detection
– adaptive enhancement
– adaptive thresholding
– tracking
Histogram based image distance
• Problem: Given two images A and B whose (normalized)
histogram are PA and PB define the distance D(A,B) between
the images.
• Example Usage:
– Tracking
– Image retrieval
– Registration
– Detection
– Many more ...
Porkili 05
Option 1: Minkowski Distance
1/ p
p
D p A, B PA (k ) PB (k )
k
<
Option 2: Kullback-Leibler (KL) Distance
PA k
DKL A || B PA k log
k PB k
>
Option 3: The Earth Mover Distance (EMD)
(amount moved)
DEMD ( A, B) min f ij d ij
F
i j
s.t. f ij 0 ; PB k f ik ; PA k f ki
i i
• Constraints:
– Move earth only from A to B
– After move PA will be equal to PB
– Cannot send more “earth” than there is
• Can be solved using Linear Programming
• Can be applied in high dim. histograms (color).
Special case: EMD in 1D
DEMD A, B C A k CB k
k
PA CA
PB CB
CA-
CB
What can you not do with histograms?
P(I) P(I)
1
1
0.5
I I
H(I) H(I)
0.1
0.1
I I
Pixel permutation of
the left image