efficient implementation of region filtering.