To avoid the weakness of the Median Filter, a new algorithm is proposed in this paper. It works in this way: firstly, use fuzzy gradient values and fuzzy logic theory to detect impulse noise,then a noise label matrix is generated; secondly, scans the noise label matrix: if the pixel is a signal point, then its gray value is outputted directly,otherwise, the size of filtering window is adaptively adjusted to the density of noise points in the window. Afterward, generates a difference matrix which is defined as the absolute difference of the gray value of the pixels and the mean of the signal point's intensity in the filtering window, and adaptively assigns a weight value to the pixels of the difference matrix. Lastly, returns the location of the minimum pixel of the weighted difference matrix through linear comparison, then replaces the intensity of the noise point with the gray value in the location. Experimental results have demonstrated that the proposed filter outperforms many well-accepted switching median-based filters in terms of both noise suppression and detail preservation.