python - How do I find and remove white specks from an image using SciPy/NumPy? -
i have series of images serve raw data trying prepare publication. these images have series of white specks randomly throughout replace average of surrounding pixels.
i cannot post images, following code should produce png approximates issue i'm trying correct:
import numpy np scipy.misc import imsave random_array = np.random.random_sample((512,512)) random_array[random_array < 0.999] *= 0.25 imsave('white_specs.png', random_array) while should produce image similar distribution of specks present in raw data, images do not have specks uniform in intensity, , of specks more single pixel in size (though none of them more 2). additionally, there spots on image do not want alter intentionally saturated during data acquisition purpose of clarity when presented: these spots approximately 10 pixels in diameter.
in principle, write pixels value exceeds threshold check them against average of nearest neighbors. however, assume i'm trying achieve not uncommon action in image processing, , suspect there scipy functionality without having reinvent wheel. issue not familiar enough formal aspects/vocabulary of image processing know should looking for. can point me in right direction?
you try median filter small kernel size,
from scipy.ndimage import median_filter filtered_array = median_filter(random_array, size=3) which remove specks without noticeably changing original image.
a median filter suited such tasks since better preserve features in original image high spatial frequency, when compared instance simple moving average filter.
by way, if images experimental (i.e. noisy) applying non-aggressive median filter (such 1 above) never hurts allows attenuate noise well.
Comments
Post a Comment