53
loading...
This website collects cookies to deliver better user experience
We need to import few libraries given below and are available in Google Colab, independent installations may be required for other platforms.
import cv2
from google.colab.patches import cv2_imshow
import numpy as np
import matplotlib.pyplot as plt
Domain Filtering - Frequency Domain Filters are used for smoothing and sharpening of image by removal of high or low frequency components. Sometimes it is possible of removal of very high and very low frequency.
#read image
src = cv2.imread(r'/content/P.png', cv2.IMREAD_UNCHANGED)
DF = cv2.edgePreservingFilter(src, flags=1, sigma_s=60, sigma_r=0.4)
print("Domain Filter - Cartoonify")
cv2_imshow(numpy.hstack((src, DF)))
Frequency Domain Filters are used for smoothing and sharpening of images by removal of high or low-frequency components.
Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image by a Gaussian function.
#apply guassian blur on src image
dst = cv2.GaussianBlur(src,(5,5),cv2.BORDER_DEFAULT)
print("Gaussian Smoothing")
cv2_imshow(numpy.hstack((src, dst)))
kernel = np.ones((10,10),np.float32)/25
dst2 = cv2.filter2D(src,-1,kernel)
print("Mean Filter")
cv2_imshow(numpy.hstack((src, dst2)))
#Median Filter
dst3 = cv2.medianBlur(src,5)
print("Median Filter")
cv2_imshow(numpy.hstack((src, dst3)))
#Bilateral filter
print("Bilateral Filter")
dst4 = cv2.bilateralFilter(src, 60, 60, 60)
cv2_imshow(numpy.hstack((src, dst4)))
#low pass filter
Lp = cv2.filter2D(src,-1, kernel)
Lp = src - Lp
print("Low Pass")
cv2_imshow(numpy.hstack((src, Lp)))
Hp = src - dst
filtered = filtered + 127*numpy.ones(src.shape, numpy.uint8)
print("High Pass")
cv2_imshow(numpy.hstack((src, Hp)))