-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprob1.m
92 lines (71 loc) · 1.44 KB
/
prob1.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
clear;
%Importing image
img = imread('2.JPG');
[m, n, k] = size(img);
MN = m*n;
%Computing Histogram Equalization for three channels
hImg = histEqu(img(:,:,1), m, n, MN);
hImg(:,:,2) = histEqu(img(:,:,2), m, n, MN);
hImg(:,:,3) = histEqu(img(:,:,3), m, n, MN);
%Displaying the result for three channel
figure,
subplot(2,3,1),
imshow(hImg(:,:,1));
title('Red Image');
subplot(2,3,2),
imshow(hImg(:,:,2));
title('Green Image');
subplot(2,3,3),
imshow(hImg(:,:,3));
title('Blue Image');
subplot(2,3,4),
histogram(hImg(:,:,1));
title('Red Image');
subplot(2,3,5),
histogram(hImg(:,:,2));
title('Green Image');
subplot(2,3,6),
histogram(hImg(:,:,3));
title('Blue Image');
%Displaying the Histogram Equalized image
figure,
subplot(2,2,1),
imshow(img);
title('Original Image');
subplot(2,2,2),
histogram(img);
title('Original Image');
subplot(2,2,3),
imshow(hImg);
title('Equalized Image');
subplot(2,2,4),
histogram(hImg);
title('Equalized Image');
function hImg = histEqu(Img, m, n, MN)
hImg=uint8(zeros(m, n));
freq=zeros(256,1);
probf=zeros(256,1);
probc=zeros(256,1);
cum=zeros(256,1);
output=zeros(256,1);
for i=1:m
for j=1:n
value=Img(i,j);
freq(value+1)=freq(value+1)+1;
end
end
probf=freq/MN;
sum=0;
no_bins=255;
for i=1:size(probf)
sum=sum+freq(i);
cum(i)=sum;
probc(i)=cum(i)/MN;
output(i)=round(probc(i)*no_bins);
end
for i=1:m
for j=1:n
hImg(i,j)=output(Img(i,j)+1);
end
end
end