Lattice Boltzmann method for inhomogeneous fluids