Relations between Optimization and Gradient Flow Methods with Applications to Image Registration