outline of region growing function