-
Notifications
You must be signed in to change notification settings - Fork 3
/
CubicInterpolation.m
136 lines (84 loc) · 2.66 KB
/
CubicInterpolation.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
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
128
129
130
131
132
133
134
135
136
function dImage = CubicInterpolation( bayerImage)
tic
global conGreen;
conGreen = [0 0 0 1 0 0 0;
0 0 -9 0 -9 0 0;
0 -9 0 81 0 -9 0;
1 0 81 256 81 0 1;
0 -9 0 81 0 -9 0;
0 0 -9 0 -9 0 0;
0 0 0 1 0 0 0];
global conRedBlue;
conRedBlue = [1 0 -9 -16 -9 0 1;
0 0 0 0 0 0 0;
-9 0 81 144 81 0 -9;
-16 0 144 256 144 0 -16;
-9 0 81 144 81 0 -9;
0 0 0 0 0 0 0;
1 0 -9 -16 -9 0 1];
dImage(:,:,1) = red(double(bayerImage(:,:,1)));
dImage(:,:,2) = green(double(bayerImage(:,:,2)));
dImage(:,:,3) = blue(double(bayerImage(:,:,3)));
toc
end
function r = red(bayerRed)
global conRedBlue;
temp1 = prepareForConv(bayerRed);
[y,x] = size(temp1);
r = zeros(y,x);
for i = 4:y-3
for j = 4:x-3
temp2 = temp1(i-3:i+3,j-3:j+3);
val = conRedBlue.*double(temp2);
div = val;
div(div ~= 0) = 1;
div = sum(sum(div.*conRedBlue));
r(i, j) = sum(sum(val/div));
end
end
r = uint8(resultOfConv(r));
end
function g = green(bayerGreen)
global conGreen;
temp1 = prepareForConv(bayerGreen);
[y,x] = size(temp1);
g = zeros(y,x);
for i = 4:y-3
for j = 4:x-3
temp2 = temp1(i-3:i+3,j-3:j+3);
val = conGreen.*double(temp2);
div = val;
div(div ~= 0) = 1;
div = sum(sum(div.*conGreen));
g(i, j) = sum(sum(val/div));
end
end
g = uint8(resultOfConv(g));
end
function b = blue(bayerBlue)
global conRedBlue;
temp1 = prepareForConv(bayerBlue);
[y,x] = size(temp1);
b = zeros(y,x);
for i = 4:y-3
for j = 4:x-3
temp2 = temp1(i-3:i+3,j-3:j+3);
val = conRedBlue.*double(temp2);
div = val;
div(div ~= 0) = 1;
div = sum(sum(div.*conRedBlue));
b(i, j) = sum(sum(val/div));
end
end
b = uint8(resultOfConv(b));
end
function cReady = prepareForConv( matrix)
[y,x] = size(matrix);
cReady = [zeros(3,x + 6);
zeros(y,3),matrix, zeros(y,3);
zeros(3,x + 6)];
end
function cEnd = resultOfConv( matrix)
[y,x] = size(matrix);
cEnd = matrix(4:y-3,4:x-3);
end