function pp = CS4640_correl(W,im)
%

[M,N] = size(im);
[MW,NW] = size(W);
MW2 = (MW-1)/2;
NW2 = (NW-1)/2;

pp = zeros(M,N);
wb = waitbar(0,'Correl');
for r = 1+MW2:M-MW2
    waitbar(r/M);
    for c = 1+NW2:N-NW2
        if r==697 & c==260
            tch = 0;
        end
        pp(r,c) = corr2(im(r-MW2:r+MW2,c-NW2:c+NW2),W);
%        v = 0;
%        for rr = -MW2:MW2
%            for cc = -NW2:NW2
%                rb = r + rr;
%                cb = c + cc;
%                r2 = rr + MW2 + 1;
%                c2 = cc + NW2 + 1;
%                if rb>0&rb<M&cb>0&cb<N
%                    v = v + abs(im(rb,cb)-W(r2,c2));
%                end
%            end
%        end
%        pp(r,c) = exp(-double(v));
    end
end
close(wb);
