function [u, v, s, drange, minVal] = brute_force(I1, I2, pos, winsize)

% Size of square window can be specified. Must be odd.
if nargin < 4 || isempty(winsize)
    % Size of tracking window
    winsize = 15;
else
    if mod(winsize, 2) == 0
        error('Window size must be odd')
    end
end

% Half the SSD window size
hwin = floor(winsize / 2);

% Maximum dispacement between windows
dmax = floor(winsize * 0.7);
drange = (-dmax):dmax;

% Fixed window in the first image
w1 = window(I1, pos, hwin);

% Compute the SSD for a range of windows in the second image
i = 1;
for dr = drange
    j = 1;
    for dc = drange
        p2 = pos + [dr, dc];
        w2 = window(I2, p2, hwin);
        s(i, j) = ssd(w1, w2);
        j = j + 1;
    end
    i = i + 1;
end

% Find the minimum of the computed SSDs
[minVal, minRow] = min(s);
[minVal, minCol] = min(minVal);
minRow = minRow(minCol);

% Retrieve the corresponding (row, col) displacement
delta = [drange(minRow), drange(minCol)];
u = delta(1);
v = delta(2);