function [Px,Py,rmap] = filter_rmap(Bx,By,Px,Py,hsize,thres)

ker = ones(hsize)./(hsize*hsize);
Bxk = conv2(Bx,ker,'same');
Byk = conv2(By,ker,'same');
Bxabsk = conv2(abs(Bx),ker,'same');
Byabsk = conv2(abs(By),ker,'same');
rmap_x = abs(Bxk) ./ (Bxabsk + 0.5);
rmap_y = abs(Byk) ./ (Byabsk + 0.5);
rmap = (rmap_x.^2+rmap_y.^2).^.5;
rmap = rmap./max(max(rmap));
tmp = zeros(size(rmap));
tmp(rmap>thres) = 1;
rmap = tmp;
Px = Px.*rmap;
Py = Py.*rmap;