Competitive global and local dynamics in the formation of contours from perceptual grouping