We provide a novel formulation for computing median filter with spatial regularization as minimizing a cost function composed of absolute value norms. We turn this cost minimization into an equivalent linear programming (LP) and solve its dual LP as a minimum cost flow (MCF) problem. The MCF is solved over a graph constructed for an input image, and the primal LP solution is retrieved as the filtered image. For solving the MCF, we utilize an efficient network simplex algorithm. Numerical results show that the proposed median filter with a spatial regularization term outperforms median filters and a decision theoretic filter for impulse noise removal.