Counting intersections of scanning lines with pattern