The factorization method for cracks in inhomogeneous media