A novel method based on Bayesian compressed sensing is proposed to remove impulse noise from atomic force microscopy (AFM) images. The image denoising problem is transformed into a compressed sensing imaging problem of the AFM. First, two different ways, including interval approach and self-comparison approach, are applied to identify the noisy pixels. An undersampled AFM image is generated by removing the noisy pixels from the image. Second, a series of measurement matrices, all of which are identity matrices with some rows removed, are constructed by recording the position of the noise-free pixels. Third, the Bayesian compressed sensing reconstruction algorithm is applied to recover the image. Different from traditional compressed sensing reconstruction methods in AFM, each row of the AFM image is reconstructed separately in the proposed method, which will not reduce the quality of the reconstructed image. The denoising experiments are conducted to demonstrate that the proposed method can remove the impulse noise from AFM images while preserving the details of the image. Compared with other methods, the proposed method is robust and its performance is not influenced by the noise density in a certain range.