-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNormaliseChannel.m
72 lines (62 loc) · 1.28 KB
/
NormaliseChannel.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
function noarmalisedx = NormaliseChannel(x, a, b, mins, maxs)
if nargin < 2
a = [];
b = [];
mins = [];
maxs = [];
end
[rows, cols, chns] = size(x);
OriginalMin = min(x(:));
OriginalMax = max(x(:));
if isempty(a)
if OriginalMin >= 0
a = 0.0;
else
a = -1.0;
end
end
if isempty(b)
if OriginalMax >= 0
b = 1.0;
else
b = 0.0;
end
end
if length(a) == 1
a(2:chns) = a(1);
end
if length(b) == 1
b(2:chns) = b(1);
end
if chns == 1 && cols == 3
x = reshape(x, rows, cols / 3, 3);
end
x = double(x);
a = double(a);
b = double(b);
noarmalisedx = zeros(size(x));
if isempty(mins)
mins = min(x(:));
end
if isempty(maxs)
maxs = max(x(:));
end
if length(mins) == 1
mins(2:chns) = mins(1);
end
if length(maxs) == 1
maxs(2:chns) = maxs(1);
end
for i = 1:chns
minv = mins(i);
maxv = maxs(i);
if a(i) == b(i)
noarmalisedx(:, :, i) = a(i);
else
noarmalisedx(:, :, i) = a(i) + (x(:, :, i) - minv) * (b(i) - a(i)) / (maxv - minv);
end
end
if chns == 1
noarmalisedx = reshape(noarmalisedx, rows, cols);
end
end