L6
Image enhancement
Histogram Processing
Introduction
• Histogram
– Discrete Function
– number
of pixels of gray level
– Normalization of histogram: where n :
total number of pixels
– : probability of grey level , k=0,1…..L-1
– Histogram plots : : vs or vs
Histogram
Gr No.of
ey pixels
Le
vel
0 30 0.3
1 20 0.2
2 10 0.1
)
3 15 0.15
4 10 0.1
5 3 0.03
6 2 0.02
7 10 0.1
Images with Histograms
• Dark Image
– Concentration of gray
levels at Low side of gray
scale
• Bright Image
– Concentration of gray
levels at high side of
histogram
• Low contrast
– Concentration of gray
levels at center of gray
scale
• High contrast
– Occupy Broad range of
gray scale
– Pixels distribution is
uniform
Linear Stretching
• Dynamic range of gray levels is
obtain by linear stretching of
histogram
• Shape of histogram is not altered
•
• As shape remains the same, flat
histogram cannot achieve by this
method
• This enhances the contrast in the
image with light toned areas
appearing lighter and dark areas
appearing darker, making visual
interpretation much easier.
19x10=190
Example
• Do Histogram stretching
to have grey level range[0,7]
0 1 2 3 4 5 6 7
0 0 40 50 70 20 10 0
19x10=190
Example
• Do Histogram stretching
to have grey level range[0,7]
0 1 2 3 4 5 6 7
0 0 40 50 70 20 10 0
• Solution:
r=2: s=0, r=3: s=1.75=2, r=4: s=3.5=4,
r=5: s=5.2=5, r=6: s=7
Modified Histogram
0 1 2 3 4 5 6 7
40 0 50 0 70 20 0 10 Note X-axis 0…….7
Example
0 1 2 3 4 5 6 7
100 90 80 60 0 0 0 0
r=0: s=0, r=1: s=2.3=2,
r=2: s=4.67=5 , r=3: s=7
Modified Histogram
0 1 2 3 4 5 6 7
100 0 90 0 0 80 0 60
Note X-axis 0…….7
Code : Linear Stretching
Rmin=43
• %linear stretching
• clear all; Rmax=244
• clc;
• b=imread('C:\Users\AnupaSabnis\Desktop\Anupa\
Anupa_Courses\2020-2021\Course
Even\IP\lenalow.png');
• rmax=max(b(:))
• rmin=min(b(:))
• a=double(b);
•
• [row col]=size(a);
•
• for x=1:1:row Smin=0
• for y=1:1:col
• c=b(x,y); Smax=255
• a(x,y)=(255/(rmax-rmin))*(c-rmin)+0;
• end
• end
•
• figure(1)
• imshow(b)
• figure(2)
• imshow(uint8(a))