pythonopencvimage-processingnoise-reduction

Remove noise or outlier pixels from an image


This is my example image:

Image with noise and outlier pixels

You can see in the bottom left corner and on the edge of the main structure, there is a lot of noise and outlier green pixels. I'm looking for a way to remove them. Currently, I have tried the following:

dst = cv2.fastNlMeansDenoisingColored(img_denoise,None,10,10,7,21)

and

dst = cv2.GaussianBlur(img,(7,7),0,borderType=cv2.BORDER_CONSTANT)

None of these methods seem to be removing these noisy pixels, are there any other methods or libraries that can achieve the result of denoising and removing these noisy pixels properly?


Solution

  • Try this:

    import matplotlib.pyplot as plt
    
    from skimage.restoration import (denoise_tv_chambolle, denoise_bilateral,
                                     denoise_wavelet, estimate_sigma)
    from skimage import data, img_as_float
    from skimage.util import random_noise
    from skimage import io
    
    img =  io.imread('img.png')
    
    
    original = img_as_float(img)
    
    sigma = 0.155
    noisy = random_noise(original, var=sigma**2)
    
    fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(8, 5),
                           sharex=True, sharey=True)
    
    plt.gray()
    
    sigma_est = estimate_sigma(noisy, average_sigmas=True)
    
    ax[0].imshow(noisy)
    ax[0].axis('off')
    ax[0].set_title('Noisy')
    ax[1].imshow(denoise_tv_chambolle(noisy, weight=0.1))
    ax[1].axis('off')
    ax[1].set_title('Noise-removed')
    
    
    fig.tight_layout()
    
    plt.show()