Scipy Gaussian filter

1.利用 Scipy 的高斯濾波器進行影像的濾波(模糊化),事實上 OpenCV 也有這個功能:

高斯濾波器的原理等之後有空再為大家說明(抱歉~)

if __name__ == "__main__":
    import numpy as np
    from PIL import Image
    from matplotlib import pyplot as plt
    from scipy.ndimage import filters
    from matplotlib.pylab import hist  
    
    pil_img = Image.open("lena.jpg").convert("L")
    
    # plot original image and histogram
    img = np.array(pil_img)
    plt.subplot(221)
    plt.axis("off")
    plt.imshow(img, cmap="gray")
    plt.subplot(222)
    hist(img.flatten(), 64) 

    # plot blur image and histogram
    img_blur = filters.gaussian_filter(img, 10)
    plt.subplot(223)
    plt.axis("off")
    plt.imshow(img_blur, cmap="gray")
    
    plt.subplot(224)
    hist(img_blur.flatten(), 64)
    plt.show()

模糊化的結果:

留言

熱門文章