The quality of a digital image deteriorates by the corruption of impulse noise in the record or transmission. The process of efficiently removing this impulse noise from a corrupted image is an important research task. This investigation presents a novel three-values-weighted method for the removal of salt-and-pepper noise. Initially, a variable-size local window is employed to analyze each extreme pixel (0 or 255 for an 8-bit gray-level image). Each non-extreme pixel is classified and placed into the maximum, middle, or minimum groups in the local window. The numbers of non-extreme pixels belonging to the maximum or the minimum group determines the centroid of the middle group. The distribution ratios of these three groups are employed to weight the non-extreme pixels with the maximum, middle, and minimum pixel values. The center pixel with an extreme value is replaced by the weighted value, thus enabling the noisy pixels to be restored. Experimental results show that the proposed method can efficiently remove salt-and-pepper noise (only for known extreme values of 0 and 255) from a corrupted image for different noise corruption densities (from 10% to 90%); meanwhile, the denoised image is freed from the blurred effect.