Statistics for Generalizing Shape-from-Template to Topological Changes