function [corr_offset] = test_plus(n_template,n,coffset,roffset)
if (n<n_template)
error('n must be greater than n_template.')
end
template = .6*ones(n_template);
center = floor((n_template - 1)/2);
half_width = floor(.1*n_template);
cmin = center - half_width;
cmax = center + half_width;
template(1:n_template,cmin:cmax) = .2;
template(cmin:cmax,1:n_template) = .2;
imshow(template)
template_size = size(template);
and coffset columns.
J = .6*ones(n);
rbegin = 1 + roffset;
rend = rbegin + template_size(1) - 1;
cbegin = 1 + coffset;
cend = cbegin + template_size(2) - 1;
J(rbegin:rend,cbegin:cend) = template;
figure;
imshow(J)
cc = normxcorr2(template,J);
[max_cc, imax] = max(abs(cc(:)));
[ypeak, xpeak] = ind2sub(size(cc),imax(1));
corr_offset = [ (xpeak-template_size(2)) (ypeak-template_size(1)) ];
Best Answer