This paper proposes the median-type filters with an impulse noise detector using the decision tree and the particle swarm optimization, for the recovery of the corrupted gray-level images by impulse noises. It first utilizes an impulse noise detector to determine whether a pixel is corrupted or not. If yes, the filtering component in this method is triggered to filter it. Otherwise, the pixel is kept unchanged. In this work, the impulse noise detector is an adaptive hybrid detector which is constructed by integrating 10 impulse noise detectors based on the decision tree and the particle swarm optimization. Subsequently, the restoring process in this method respectively utilizes the median filter, the rank ordered mean filter, and the progressive noise-free ordered median filter to restore the corrupted pixel. Experimental results demonstrate that this method achieves high performance for detecting and restoring impulse noises, and outperforms the existing well-known methods.