A method for mapping field inhomogeneity for forming a magnetic resonance image is provided. A magnetic resonance excitation is applied. A plurality of k-space echoes signals is acquired. A periodic cost function is calculated from the acquired plurality of k-space echo signals. A period of the calculated periodic cost function is divided into multiple regions. A search algorithm is used to locate a local minimum in each region. Located local minimums are chosen to provide global smoothness.