function c = conv2tch(f,g)
%
% conv2tch: 2D pointwise summed result of mask with image
%
% On input:
%     f: 2D image function
%     g: 2D mask
% On output:
%     c: f pointwise summed result with mask
%

[m1,n1] = size(f);
[m2,n2] = size(g);
c = zeros(m1,n1);

k1 = (m2-1)/2;
k2 = (n2-1)/2;
for i1 = 1+k1:m1-k1
  for j1 = 1+k2:n1-k2
    w = f(i1-k1:i1+k1,j1-k2:j1+k2);
    c(i1,j1) = sum(sum(w.*g));
  end
end

c(1,:) = c(2,:);
c(m1,:) = c(m1-1,:);
c(:,1) = c(:,2);
c(:,n1) = c(:,n1-1);
