Salt-and-pepper (SAP) noise may degrade the bio-images at the time of capturing or transmission. In this paper, we propose a gain factor adapted by a noise-free pixel number and pixel variation for the removal of the impulse noise. All pixels with a non-extreme gray level value are sorted in an ascending order and are grouped according to the gray level variation of pixels in an analysis window. The distribution ratio and median value of each group are computed to determine the values of the gain factors. They are multiplied with the median value of each group to obtain a weighted value which is employed to replace the center pixel with an extreme gray level value, enabling noise-corrupted pixels to be reconstructed. Experimental results show that the proposed approach can effectively remove SAP noise from a corrupted bio-image for various noise corruption densities; meanwhile, the denoised bio-image is not blurred.