Lateral position correction in ptychography using the gradient of intensity patterns