Detection and correction of patient motion in magnetic resonance imaging