Theory of Gestalt Formation