This paper presents a new approach for the correction of image inhomogeneities. The corruption of the image brightness values by a low-frequency bias field often occurs in MR imaging and impedes visual inspection and intensity-based segmentation. The inhomogeneity problem is even more pronounced in surface-coil images. The new correction method is based on a mathematical model of the imaging process and of the original scene. The imaging process is described by a linear combination of tissue intensity, noise and additive inhomogeneity. Multiplicative inhomogeneities are modelled with a logarithmic version of the image brightness. The model of the original scene assumes to assign a unique category to each pixel, each category described by its statistics. The appropriateness of a parametric model of the bias field in MR imaging is tested by applying the procedure to a phantom scene and to its MR image. The formulation of the bias field estimate as an energy minimization problem assigns minimal energy to pixel values near one of the given category means $\mu_k$. A width parameter $\sigma$ accounts for noise variations. A minimal total energy would be achieved if the bias correction would perfectly counteract for the distortion, assigning each pixel to a category. The global energy minimum is found by varying the multiple parameters of the bias field model. The nonlinear optimization is solved by applying a discrete optimization technique. The procedure in general is independent of the dimensionality of the image data and also independent of the geometrical constellation of the image regions. It runs fully automatically and requires no user interaction. Further, it does not require a presegmented image which comes close to the optimal segmentation.