-
Notifications
You must be signed in to change notification settings - Fork 5
/
gaussian_shaped_labels.m
executable file
·34 lines (26 loc) · 1.26 KB
/
gaussian_shaped_labels.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
function labels = gaussian_shaped_labels(sigma, sz)
%GAUSSIAN_SHAPED_LABELS
% Gaussian-shaped labels for all shifts of a sample.
%
% LABELS = GAUSSIAN_SHAPED_LABELS(SIGMA, SZ)
% Creates an array of labels (regression targets) for all shifts of a
% sample of dimensions SZ. The output will have size SZ, representing
% one label for each possible shift. The labels will be Gaussian-shaped,
% with the peak at 0-shift (top-left element of the array), decaying
% as the distance increases, and wrapping around at the borders.
% The Gaussian function has spatial bandwidth SIGMA.
%
% Joao F. Henriques, 2014
% http://www.isr.uc.pt/~henriques/
% %as a simple example, the limit sigma = 0 would be a Dirac delta,
% %instead of a Gaussian:
% labels = zeros(sz(1:2)); %labels for all shifted samples
% labels(1,1) = magnitude; %label for 0-shift (original sample)
%evaluate a Gaussian with the peak at the center element
[rs, cs] = ndgrid((1:sz(1)) - floor(sz(1)/2), (1:sz(2)) - floor(sz(2)/2));
labels = exp(-0.5 / sigma^2 * (rs.^2 + cs.^2));
%move the peak to the top-left, with wrap-around
labels = circshift(labels, -floor(sz(1:2) / 2) + 1);
%sanity check: make sure it's really at top-left
assert(labels(1,1) == 1)
end