-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpolation.m
33 lines (29 loc) · 1.01 KB
/
interpolation.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
function Interpolated = interpolation(Image, x, y, method)
switch lower(method)
case 'replication'
interpolation_function = @interpolation_replication;
case 'bilinear'
interpolation_function = @interpolation_bilinear;
case 'bicubic'
interpolation_function = @interpolation_bicubic;
otherwise
error("Unknown interpolation method " + method + ".")
end
[num_lines, num_columns, num_channels] = size(Image);
% Retorna o valor na posição y, x, channel da imagem. Se as coordenadas
% não estão contidas na imagem, retorna 0.
function P = Image_extended(y, x, channel)
if x >= 1 && x <= num_columns ...
&& y >= 1 && y <= num_lines
P = Image(y, x, channel);
else
P = 0;
end
end
Interpolated = zeros(1, 1, num_channels);
% Interpola cada canal separadamente.
for channel = 1 : num_channels
Interpolated(channel) = ...
interpolation_function(@Image_extended, x, y, channel);
end
end