A self-adaptive weighted mean algorithm is proposed for filtering the salt-pepper noise in images. The algorithm detects the noise pixel with minimum-maximum inspection, and then replaces the noise pixel with weighted mean value, where the weight of each pixel in neighborhood is set based on its correlation with the center pixel. The algorithm adapts itself to different noise densities by rectifying the filtering window according to the number of non-extremum pixels in neighborhood. Simulation results showed that, compared with other methods, the proposed algorithm achieves more satisfactory images while it gives better Signal-to-Noise Ratio(SNR) and Mean Squared Error(MSE), and exhibits more excellent in scenarios where the image is highly corrupted.