Grayscale image processing is a key research area in the field of computer vision and image analysis, where image quality and visualization effects may be seriously damaged by high-density salt and pepper noise. A traditional median filter for noise removal may result in poor detail reservation performance under strong noise and the judgment performance of different noise characteristics has strong dependence and rather weak robustness. In order to reduce the effects of high-density salt and pepper noise on image quality when processing high-noise grayscale images, an improved two-dimensional maximum Shannon entropy median filter (TSETMF) is proposed for the adaptive selection of a threshold to enhance the filter performance while stably and effectively retaining the details of the images. The framework of the proposed improved TSETMF algorithm is designed in detail. The noise in images is filtered by means of automatically partitioning a window size, the threshold value of which is adaptively calculated using two-dimensional maximum Shannon entropy. The theoretical model is verified and analyzed through comparative experiments using three kinds of classical grayscale images. The experimental results demonstrate that the proposed improved TSETMF algorithm exhibits better processing performance than that of the traditional filter, with a higher suppression of high-density noise and denoising stability. This stronger ability while processing high-density noise is demonstrated by a higher peak signal-to-noise ratio (PSNR) of 24.97 dB with a 95% noise density located in the classical Lena grayscale image. The better denoising stability, with a noise density from 5% to 95%, is demonstrated by the minor decline in the PSNR of approximately 10.78% relative to a PSNR of 23.10 dB located in the classical Cameraman grayscale image. Furthermore, it can be advanced to promote higher noise filtering and stability for processing high-density salt and pepper noise in grayscale images.