<jupyter_start><jupyter_text>Gaussian Filtering using cv2.GaussianBlur<jupyter_code>import cv2
import numpy as np
from skimage import io, img_as_float
import matplotlib.pyplot as plt
#image_as_float is used here to keep the values of the image in floating point value to avoid round-off errors


img_gaussian_noise=img_as_float(io.imread('images/Gaussian_noise.jpg',as_gray=True))  #image containing gaussian noise

img_saltandpepper_noise=img_as_float(io.imread('images/Salt&pepper_noise.png',as_gray=True)) #image containing salt and pepper noise

img_speckle_noise=img_as_float(io.imread('images/Speckle_noise.jpg',as_gray=True)) #image containing speckle noise

img_poission_noise=img_as_float(io.imread('images/Poission_noise.png',as_gray=True)) #image containing poission noise


img=img_gaussian_noise #use as per preference : here gaussian noise image is used


using_cv2 = cv2.GaussianBlur(img, (5,5), 0, borderType=cv2.BORDER_CONSTANT)
#BORDER_CONSTANT - Pad the image with a constant value (i.e. black or 0)
#BORDER_REPLICATE: The row or column at the very edge of the original is replicated to the extra border.

cv2.imshow("Original", img)
cv2.imshow("Using cv2 gaussian", using_cv2)

cv2.waitKey(0)  #display the window infinitely until any keypress

cv2.destroyAllWindows() #simply destroys all the windows we created or popped-up

# plt.subplot(1, 2, 1)
# plt.title('Original')
# plt.imshow(img,cmap='gray')
# plt.subplot(1, 2, 2)
# plt.title('Using cv2 gaussian')
# plt.imshow(using_cv2,cmap='gray')<jupyter_output><empty_output><jupyter_text>Original Image > Filtered Image   Gaussian Filtering using cv2.getGaussianKernel<jupyter_code>import cv2
import numpy as np
from skimage import io, img_as_float
#image_as_float is used here to keep the values of the image in floating point value to avoid round-off errors


img_gaussian_noise=img_as_float(io.imread('images/Gaussian_noise.jpg',as_gray=True))  #image containing gaussian noise

img_saltandpepper_noise=img_as_float(io.imread('images/Salt&pepper_noise.png',as_gray=True)) #image containing salt and pepper noise

img_speckle_noise=img_as_float(io.imread('images/Speckle_noise.jpg',as_gray=True)) #image containing speckle noise

img_poission_noise=img_as_float(io.imread('images/Poission_noise.png',as_gray=True)) #image containing poission noise


img=img_gaussian_noise #use as per preference : here gaussian noise image is used


a = cv2.getGaussianKernel(5,1) # Creates a 1-D Gaussian kernel


using_cv2 = cv2.sepFilter2D(img,-1,a,a, borderType=cv2.BORDER_CONSTANT) 
# Apply the above Gaussian kernel. Here, I have used the same kernel for both X and Y
#BORDER_CONSTANT - Pad the image with a constant value (i.e. black or 0)
#BORDER_REPLICATE: The row or column at the very edge of the original is replicated to the extra border.

cv2.imshow("Original", img)
cv2.imshow("Using cv2 gaussian", using_cv2)

cv2.waitKey(0)  #display the window infinitely until any keypress

cv2.destroyAllWindows() #simply destroys all the windows we created or popped-up<jupyter_output><empty_output><jupyter_text>Original Image > Filtered Image   Gaussian Filtering using Gaussian Kernel function<jupyter_code>import cv2
import numpy as np
import numpy
from skimage import io, img_as_float
#image_as_float is used here to keep the values of the image in floating point value to avoid round-off errors

def gaussian_kernel(size, size_y=None):
    size = int(size)
    if not size_y:
        size_y = size
    else:
        size_y = int(size_y)
    x, y = numpy.mgrid[-size:size+1, -size_y:size_y+1]
    g = numpy.exp(-(x**2/float(size)+y**2/float(size_y)))
    return g / g.sum()
 

img_gaussian_noise=img_as_float(io.imread('images/Gaussian_noise.jpg',as_gray=True))  #image containing gaussian noise

img_saltandpepper_noise=img_as_float(io.imread('images/Salt&pepper_noise.png',as_gray=True)) #image containing salt and pepper noise

img_speckle_noise=img_as_float(io.imread('images/Speckle_noise.jpg',as_gray=True)) #image containing speckle noise

img_poission_noise=img_as_float(io.imread('images/Poission_noise.png',as_gray=True)) #image containing poission noise


img=img_gaussian_noise #use as per preference : here gaussian noise image is used


gaussian_kernel_array = gaussian_kernel(1)
#calling the gaussian_kernel function and passing "1" which is the kernel size

conv_using_cv2 = cv2.filter2D(img, -1, gaussian_kernel_array, borderType=cv2.BORDER_CONSTANT)
#BORDER_CONSTANT - Pad the image with a constant value (i.e. black or 0)
#BORDER_REPLICATE: The row or column at the very edge of the original is replicated to the extra border.


cv2.imshow("Original", img)
cv2.imshow("Using cv2 gaussian", conv_using_cv2)

cv2.waitKey(0)     #display the window infinitely until any keypress

cv2.destroyAllWindows() #simply destroys all the windows we created or popped-up<jupyter_output><empty_output>