Virial inversion for inhomogeneous systems