Lecture3 Contrast Enhancement PDF
Lecture3 Contrast Enhancement PDF
Yao Wang
Polytechnic University
University, Brooklyn
Brooklyn, NY 11201
f f f
800 800
600 600
400 400
200 200
0 0
g ( f ) ( f s1 ) * (t 2 t1 ) /( s2 s1 ) t1
a (t 2 t1 ) /( s2 s1 ), b t1 s1 * (t 2 t1 ) /( s2 s1 ) t1
s1 s2 f
• Example
– The original
g g
gray
y levels are [[100,, 150].
]
– The target gray levels are [0, 255].
– The
g ( f transformation
) (( f 100) /function
50) * 255, ffor 100 f 150.
255
f f g
100 150 100 150 255
Linear stretching
g1
g0 f
f0 f1 f2 f3 f4
g0 f T g0
g( f ) f
g1 f T T
g(f)
• Multilevel Slicing g2
g1
g0
g( f ) gk f k f f k 1 f
f0 f1 f2
H(f)
g
gmax
New histogram
fmax
H(g)
Original histogram
fmax f
Transformation function:
“log” function: g=c log (1+f)
Or gmax g
Power law: g= c f^r, 0<r<1
Yao Wang, NYU-Poly EL5123: Contrast Enhancement 20
Example of Log Transformation
Eq. (3.2-2)
“log” function:
g=c log (1+f)
Eq. (3.2-3)
Power law:
g= c f^r
H(f)
g
gmax
New histogram
fmax
H(g)
Original histogram
fmax f
Transformation function:
Power law: g=c f^r, r>1
gmax g
Eq. (3.2-3)
Power law:
g= c f^r
H(f)
g
gmax
New histogram
fmax
H(g)
Original histogram
fmax f
Transformation function
gmax g
– g is
i uniformly
if l di
distributed
t ib t d iin (0
(0, 1)
Histogram
Equalization
f
g( f ) f min
p F (t )dt ,
pF ( f )
pG ( g ) , g (0,1)
dg
df
dg
pF ( f )
df
pG ( g ) 1, g (0,1)
pG ( g ) 1, g (0,1)
pF(f) g(f) pG(g)
1
2
1/2
1
0 1/2 1 f 0 1/2 1 f 1 g
0
l l
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
We don’t get perfectly flat histogram
Yao Wang, NYU-Poly EL5123: with discrete implementation!
Contrast Enhancement 32
Sample Matlab Code
function histogram_eq(inimgname)
iimg=imread(imgname);
i d(i ) %perform
% f mapping
i
figure; imshow(img); for (i=1:M)
[M,N]=size(img); for (j=1:N)
f=double(img(i,j))+1;
histeqimg(i j)=C(f);
histeqimg(i,j)=C(f);
H=imhist(img);
end;
H=H/(M*N);
end;
figure; bar(H);
%note the above loop can be replaced by:
%Computing the mapping function %histeqimg=C(double(img)+1);
for (k=1:256) %this will be much faster!
C(k)=uint8(sum(H(1:k))*255);
end; g ;
figure;
% C = uint8(cumsum(H)*255); imshow(histeqimg);
figure;plot(C);
f Histogram Histogram z
g=s
pF(f) Equalization Equalization
pZ(z)
Specified
pG ( g ) 1 PS ( s ) 1 Histogram
g g( f ) s s( z )
f
pF ( f )df
z
pZ ( z )dz
0 0
z s 1 ( g ) s 1 ( g ( f ))
f 0 1 2 3 4 5 6 7 z 0 1 2 3 4 5 6 7
z 3 4 5 6 6 7 7 7 pZ(z)
( ) 0 0 0 .19
19 .25
25 .21
21 .24
24 .11
11
Equalize
intensity
Equalize and
intensity enhance
only saturation