This paper proposes a novel two-stage denoising method for removing random-valued impulse noise from an image. First, an impulse noise detection scheme is used to detect the pixels which are likely to be corrupted by the impulse noise (called the noise candidates). Then the noise candidates are reconstructed by using the image inpainting method based on sparse representation in an iterative manner until convergence. The proposed method leads to a simple and very effective denoising algorithm for the random-valued impulse noise removal. It is experimentally shown that the proposed algorithm outperforms the state-of-the-art denoising techniques for the removal of impulse noise both visually and quantitatively.