-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab4.asv
130 lines (104 loc) · 3.77 KB
/
Lab4.asv
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
%1
[A,map] = imread('lenaG.bmp');
[row_n, col_n] = size(A);
B = imread('NaturalView.jpg');
total_pixel = row_n * col_n;
figure(1),
subplot(1,4,1), imhist(A,10); title('hist 10 bins');
subplot(1,4,2), imhist(A,20); title('hist 20 bins');
subplot(1,4,3), imhist(A,100); title('hist 100 bins');
subplot(1,4,4), imhist(A,256); title('hist 256 bins');
range_2_52 = find(A<=52);
range_2_181 = find(A<=181);
range_2_232 = find(A<=232);
%2
figure(2),
normalized_A = im2double(A);
subplot(1,2,1), imhist(A); title('initial');
subplot(1,2,2), imhist(normalized_A); title('rescale x-range');
%3
figure(3),
subplot(1,2,1), histogram(A,'Normalization','probability'); title('AOC = 1');
subplot(1,2,2), histogram(normalized_A,'Normalization','probability'); title('AOC = 1');
p_2_52 = find(A<=52)/total_pixel;
p_2_181 = find(A<=181)/total_pixel ;
p_2_232 = find(A<=232)/total_pixel;
%4
double_A =double(A);
mu = 0;
sigma = 20;
array_gaussian_noise=mu+randn(row_n,col_n)*sigma;
A_wnoise_20 = double_A + array_gaussian_noise;
min_A_wnoise_20 = min(A_wnoise_20(:));
max_A_wnoise_20 = max(A_wnoise_20(:));
figure(4),
bias = abs(min_A_wnoise_20) +100;
slope = 1.5;
%Linear scaling
A_Lineamin_A_wnoise_20r_scaling = l_scale(A_wnoise_20, slope, bias);
%Linear scaling with clipping
%clip range from min value to -10
A_Linear_clipping = l_scale(A_wnoise_20, slope, bias);
%Abosolute value scaling
A_abs_scaling = abs(A_wnoise_20);
% subplot(2,3,1), histogram(A,'Normalization','probability'); title('AOC = 1');
% subplot(2,3,2), histogram(normalized_A,'Normalization','probability'); title('AOC = 1');
% subplot(2,3,3), histogram(normalized_A,'Normalization','probability'); title('AOC = 1');
% subplot(2,3,4), histogram(normalized_A,'Normalization','probability'); title('AOC = 1');
% subplot(2,3,5), histogram(normalized_A,'Normalization','probability'); title('AOC = 1');
% subplot(2,3,6), histogram(normalized_A,'Normalization','probability'); title('AOC = 1');
%5
B_lscale = l_scale(double(B), slope, bias);
figure(5),
subplot(2,2,1), imshow(B); title('og = 1');
subplot(2,2,2), imshow(B_lscale,[]); title('linear scale, slope =1.5, bias = 100 ');
subplot(2,2,3), histogram(B,'Normalization','probability'); title('AOC = 1');
subplot(2,2,4), histogram(B_lscale ,'Normalization','probability'); title('AOC = 1');
%6
gamma_1=1/2;
gamma_2=1/3;
gamma_3=1/5;
c=1;
p_img_1 = ones(row_n, col_n);
p_img_2 = ones(row_n, col_n);
p_img_3 = ones(row_n, col_n);
for i=1:row_n
for j=1:col_n
p_img_1(i,j) = c*(double_A(i,j)^gamma_1);
p_img_2(i,j) = c*(double_A(i,j)^gamma_2);
p_img_3(i,j) = c*(double_A(i,j)^gamma_3);
end
end
figure(6),
subplot(1,4,1), imshow(A); title('og = 1');
subplot(1,4,2), imshow(p_img_1,[]); title('linear scale, slope =1.5, bias = 100 ');
subplot(1,4,3), imshow(p_img_2,[]); title('linear scale, slope =1.5, bias = 100 ');
subplot(1,4,4), imshow(p_img_3,[]); title('linear scale, slope =1.5, bias = 100 ');
%7
figure(7),
imshow(-double_A,[]); title('negative images');
% subplot(1,4,1), imshow(A); title('og = 1');
% subplot(1,4,2), imshow(p_img_1,[]); title('linear scale, slope =1.5, bias = 100 ');
%8
figure(8),
imshow(double_A/255,[]); title('inverse of image');
%9
[img_eql, ]= histeq(B);
figure(9),
subplot(2,2,1), imshow(B); title('og');
subplot(2,2,2), imhist(B); title('histogram og');
subplot(2,2,3), imshow(img_eql); title('og = 1');
subplot(2,2,4), imhist(img_eql); title('histogram equalisation');
counts = histcounts(B);
min_temp = min(B(:));
max_temp = max(B(:));
counts = [(0:min_temp-1),counts,(max_temp:255)];
cdf = cumsum(counts)/sum(counts);
B(1,1) = 0;
B(1,2) = 255;
J = histeq(B, 255);
% counts_j = histcounts(J);
% cdf_j = cumsum(counts_j)/sum(counts_j);
figure(10),
subplot(2,2,1), plot((0:255),cdf); title('cdf og');
subplot(2,2,2), plot((0:255),cdf_j); title('cdf euqlization');