I have a series of images that serve as my raw data, which I am trying to prepare for publication. These shots randomly have a series of white spots that I would like to replace with the average values ββof the surrounding pixels.
I can not send images, but the following code should contain PNG, which approximates the problem I'm trying to fix:
import numpy as np from 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 this should create an image with a similar distribution of spots that are present in my source data, my images do not have spots uniform in intensity, and some of them are larger than one pixel (although none of them are more than 2). In addition, there are spots on my image that I donβt want to change, which were intentionally saturated during data collection for the purpose of clarity in their presentation: these spots have a diameter of approximately 10 pixels.
Basically, I could write something to look for pixels whose value exceeds a certain threshold, and then check them for the average of their nearest neighbors. However, I assume that what I am ultimately trying to achieve is not uncommon in image processing, and I highly suspect that there are some SciPy features that will do this without having to reinvent the wheel. My problem is that I am not familiar with the formal aspects / vocabulary of image processing to really know what I should look for. Can someone point me in the right direction?
source share