[1422d3]: / libraries / lib_1Shot-MaxPol / utilities / maxpol_downsample.m

Download this file

37 lines (33 with data), 1.0 kB

 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
function [down_sampled_image] = maxpol_downsample(scan_image, scale, h)
%%
if scale > 1
warning('down-sampling scale should be less than one, returning the same input image')
return
end
max_skip = 2;
if 1/scale > max_skip
N = log(1/scale) / log(max_skip);
N = round(N);
skip = (1/scale)^(1/N);
else
skip = 1/scale;
N = 1;
end
if strcmp(class(scan_image), 'uint8')
scan_image = single(scan_image);
end
down_sampled_image = scan_image;
for iteration = 1: N
%%
[m, n, q] = size(down_sampled_image);
indx_i = round([1: skip: m]);
indx_j = round([1: skip: n]);
%% lowpass filter
down_sampled_image = imfilter(down_sampled_image, h(:), 'conv', 'symmetric');
down_sampled_image = imfilter(down_sampled_image, h(:)', 'conv', 'symmetric');
%% down-sampling
down_sampled_image = down_sampled_image(indx_i, indx_j, :);
%%
down_sampled_image(down_sampled_image>255) = 255;
down_sampled_image(down_sampled_image<0) = 0;
end