function [R] = pts2gridIm(pts)
L = max(pts(:,3)) + 1;
M = ceil(max(pts(:,2))+min(pts(:,2)));
N = ceil(max(pts(:,1))+min(pts(:,1)));
R = logical(zeros(M, N, L));
for i=2:L
    r = R(:,:,i);
    ind = find(pts(:,3)==i-1);
    x = round(pts(ind,1)');
    y = round(pts(ind,2)');
    R(:,:,i) = roipoly(r,x, y);
    R(:,:,1) = R(:,:,1) | R(:,:,i);
end

