-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormal.m
49 lines (45 loc) · 858 Bytes
/
normal.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
clc;
clear;
close all;
% Load Image
imgFile = 'cameraman.tif';
img = imread(imgFile);
xres = size(img, 1);
yres = size(img, 2);
figure;
imshow(img);
title('Original image');
% Find Histogram
imgHist = zeros(1, 256);
for i = 1 : xres
for j = 1 : yres
pix = 1 + img(i, j);
imgHist(1, pix) = imgHist(1, pix) + 1;
end
end
imgHist = imgHist / (xres * yres);
figure;
plot(imgHist);
title('Original histogram');
% Histogram equalization
imgCum = imgHist;
for i = 2 : 256
imgCum(1, i) = imgCum(1, i-1) + imgCum(1, i);
end
figure;
plot(imgCum);
title('Cumulative probability');
imgEq = zeros(xres, yres);
for i = 1 : xres
for j = 1 : yres
pix = img(i, j);
imgEq(i, j) = imgCum(1, 1 + pix);
end
end
figure;
imshow(imgEq);
title('Equalized image');
imwrite(imgEq, 'HistEqu.png');
figure;
plot(imhist(imgEq));
title('Equalized histogram');