1

I tried to apply a gaussian filter to 6 images to denoise them using the following code:

import os
import matplotlib.image as img

def load_data(dir_name ='C:/Users/ASUS/Desktop/Self_Learning/Coursera/Deep Learning in Computer Vision/plates'):
    im_list=[]
    for f in os.listdir(dir_name):
        fpath = os.path.join(dir_name, f) # this will give you the path of each file in your directory
        im = img.imread(fpath) 
        im_list.append(im)
    return im_list


plates = load_data()

# The auxiliary function `visualize()` displays the images given as argument.
def visualize(imgs, format=None):
    plt.figure(figsize=(20, 40))
    for i, img in enumerate(imgs):
        if img.shape[0] == 3:
            img = img.transpose(1,2,0)
        plt_idx = i+1
        plt.subplot(3, 3, plt_idx)    
        plt.imshow(img, cmap=format)
    plt.show()

visualize(plates, 'gray')


from scipy import ndimage

def noise_reduction(img):

    denoised_list=[]
    for i in img:
        gauss_filtered = ndimage.gaussian_filter(i, sigma=1.4,truncate=2.0)
        denoised_list.append(gauss_filtered)
    return denoised_list 

denoised_img= noise_reduction(plates)

visualize(denoised_img, 'gray')

plates is the file that contains my images and visualize is a function to display the images. The result should have been 6 denoised gray scale images. However, I got blue-ish ones.

Here are my originale images (plates):

enter image description here

This is the result after applying the gaussian filter:

enter image description here

Rim Sleimi
  • 121
  • 1
  • 6
  • What is the shape of the input images? Are they 3D matrices (meaning RGB images, even if they appear gray) or 2D matrices (meaning gray-scale images)? – Cris Luengo Apr 19 '20 at 23:10
  • The input image is the set of 3 plates, corresponding to B, G, and R channels (top-down). But I displayed them as grayscale – Rim Sleimi Apr 19 '20 at 23:16
  • I’m not sure I follow. What is the shape of the `i` that you put into `ndimage.gaussian_filter`? You might want to post complete code so we see exactly what it is that is happening, see [mre]. Right now it’s hard to guess what the problem could be. – Cris Luengo Apr 20 '20 at 00:12
  • Ok I shared the full code – Rim Sleimi Apr 20 '20 at 00:21
  • Can't re-create the problem. Check your code but the result totally fine. See : https://imgur.com/a/QGKBdG8 . You need to upload the image too – Vu Gia Truong Apr 21 '20 at 05:48
  • I am not sure how to upload those images. – Rim Sleimi Apr 21 '20 at 08:06

0 Answers0