function im_cos = CS4640_dot_norm(im,H)
%

im_cos = -(im==im);

[M_H,N_H] = size(H);
[M_im,N_im] = size(im);

if mod(M_H,2)==0
    M_H = M_H + 1;
end
if mod(N_H,2)==0
    N_H = N_H + 1;
end
H = imresize(H,[M_H,N_H]);

k1 = (M_H-1)/2;
k2 = (N_H-1)/2;

H_len = norm(H);
if H_len==0|norm(im(:))==0
    return
end
H = H(:);

for r = 1+k1:M_im-k1
    for c = 1+k2:N_im-k2
        W = im(r-k1:r+k1,c-k2:c+k2);
        W = W(:);
        W_len = norm(W);
        if W_len>0
            im_cos(r,c) = dot(W,H)/W_len/H_len;
        end
    end
end
