function deltaps = estMeanByReg(frames, b, sigma, penalty, firstNC)
% Created by Yuandong Tian, Oct. 5, 2009
% Email: yuandong@andrew.cmu.edu
% estimate deltaps with respect to the center

[m, n, nFrame] = size(frames);
if n ~= b.w || m ~= b.h
    fprintf(1, 'error!! dimension mismatch!\n');
    deltaps = 0;
    return;
end;

centerFrame = floor(nFrame / 2);

p1 = zeros(firstNC, 1);
p2 = zeros(firstNC, 1);

deltaps = zeros(firstNC, nFrame);

for i = (centerFrame-1):-1:1
    fprintf(1, 'Left Part...deal with image #(%d, %d)...\n', centerFrame, i);
    [p1, p2] = estKernelReg(frames(:, :, centerFrame), frames(:, :, i), b, sigma, penalty, firstNC, p1, p2);
    deltaps(:, i) = p2 - p1;
end;

p1 = zeros(firstNC, 1);
p2 = zeros(firstNC, 1);

for i = (centerFrame+1):nFrame
    fprintf(1, 'Right part...deal with image #(%d, %d)...\n', centerFrame, i);
    [p1, p2] = estKernelReg(frames(:, :, centerFrame), frames(:, :, i), b, sigma, penalty, firstNC, p1, p2);
    deltaps(:, i) = p2 - p1;
end;
