Inhomogeneous magnetoelectric effect