An adaptive median-Gaussian filtering algorithm is proposed to solve the problem of poor noise filtering effect and easy to destroy the details of crack edge in the process of the crack detection of the tunnel lining by traditional filtering algorithm. Firstly, the Gaussian noise and salt and pepper noise in the image are detected by comparing the gray value of the window target pixel with the weighted average gray value of the window, and then the difference between the gray value of the point pixel and the weighted average gray value of the window is used to detect the noise twice by setting a suitable threshold. Finally, the detected Gaussian and salt and pepper noise are filtered by Gaussian filtering and adaptive median filtering, respectively. The experimental results show that compared with the traditional filtering algorithm, the mean square error (MSE) of the proposed algorithm is the smallest, and the peak signal-to-noise ratio (PSNR) is the largest, and it has better performance in filtering noise and protecting the details of crack edge.