I have this image which has been heavily obscured by impulse(salt&pepper) noise and I am trying to filter it using a median filter. I was able to filter the picture to a slightly readable state, but I want them to filter out to a much more clear image. How can my median filter be improved?
The picture is represented by a (n,m,4) array, with grayscale rgb values between 0 (black) and 1 (white). I used a 3x3 matrix for my median filter, and gave the image a 1-pixel wide white border around each edge.
def medianFilter(image=np.ndarray):
for i in range(1,image.shape[0]):
for j in range(1,image.shape[1]):
square = np.array(image[i-1:i+2,j-1:j+2])
if(square[1,1][0]==1 or square[1,1][0]==0):
square[1,1] = np.median((square))
image[i-1:i+2,j-1:j+2] = square
return image