A method for locally creating effectively homogeneous or "clean" magnetic
field gradients (of high uniformity) for imaging (with NMR, MRI, or
spectroscopic MRI) both in in-situ and ex-situ systems with high degrees
of inhomogeneous field strength. The method of imaging comprises: a)
providing a functional approximation of an inhomogeneous static magnetic
field strength B.sub.0 (r) at a spatial position r; b) providing a
temporal functional approximation of G.sub.shim(t) with i basis functions
and j variables for each basis function, resulting in v.sub.ij variables;
c) providing a measured value .OMEGA., which is an temporally accumulated
dephasing due to the inhomogeneities of B.sub.0 (r); and d) minimizing a
difference in the local dephasing angle (I) by varying the v.sub.ij
variables to form a set of minimized v.sub.ij variables. The method
requires calibration of the static fields prior to minimization, but may
thereafter he implemented without such calibration, may he used in open
or closed systems, and potentially portable systems.