Image effects are created by applying a convolution matrix (also known as kernel) to the image. This is a small matrix that slides through the original image and does a mathematical operation on the pixels for each position of the sliding window. Depending on the convolution matrix you get a different image effect. OpenCV has many of these effects integrated including guassian blur, laplacian and sobel.
Python code to do image effects: gaussian blur, laplacian, sobel:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import numpy as np
import cv2
img = cv2.imread('face.jpg')
# converting to gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# gaussian blur
blur = cv2.GaussianBlur(gray,(3,3),0)
# convolute with proper kernels
laplacian = cv2.Laplacian(img,cv2.CV_64F)
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) # x
sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) # y
cv2.imshow("Grayscale", gray)
cv2.imshow("Gaussian blur", blur)
cv2.imshow("Laplacian", laplacian)
cv2.imshow("SobelX", sobelx)
cv2.imshow("SobelY", sobely)
cv2.waitKey(0)
|
Output:
Image effects