-
Notifications
You must be signed in to change notification settings - Fork 0
/
Histogram Equalization Enhance.m
57 lines (48 loc) · 1.14 KB
/
Histogram Equalization Enhance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
% Histogram_Equal_Enhance
% 14 - Oct - 2018
% Gourav Siddhad
function Histogram_Equal_Enhance()
RGB = imread('sample.png', 'png');
GRAY = rgb2gray(RGB);
GRAYeq = GRAY;
% Calculating Intensity Array
bins = 256;
X = zeros(bins);
[p,q] = size(GRAY);
bin = 256/(bins-1);
for i=1:p
for j=1:q
X(GRAY(i,j)/bin+1) = X(GRAY(i,j)/bin+1)+1;
end
end
% Computing Cumulative Frequency
CuFreq = zeros(bins);
CuFreq(1) = X(1);
for i=2:bins
CuFreq(i) = CuFreq(i-1) + X(i);
end
% Calculating the Relative Intensity to be Used
pixels = CuFreq(bins);
for i=1:bins
CuFreq(i) = bins*CuFreq(i)/pixels;
end
% Reconstructing Enhanced Image using New Intensity Values
for i=1:p
for j=1:q
GRAYeq(i,j) = CuFreq(GRAY(i,j));
end
end
figure;
subplot(2,2,1);
imshow(GRAY);
title('Original');
subplot(2,2,2);
imshow(GRAYeq);
title('Equalized');
subplot(2,2,3);
imhist(GRAY);
title('Original');
subplot(2,2,4);
imhist(GRAYeq);
title('Equalized');
end