pattern and region counting