This is the 21st day of my participation in the August Text Challenge.More challenges in August
Python OpenCV 365 day learning plan, enter the graphics realm with eraser.
Foundation of basic knowledge
See a saying, explain gaussian blur is relatively simple, gaussian blur is weighted mean blur.
The explanation is as follows:
Gaussian fuzziness is essentially a kind of mean fuzziness, but gaussian fuzziness is based on weighted average, the closer the distance is, the greater the weight of the point, the farther the distance is, the smaller the weight of the point.
Generally speaking, Gaussian filtering is the process of weighted average of the whole image. The value of each pixel is obtained by weighted average of its own and other pixel values in the neighborhood.
But reading is a bit of a struggle, and in this case, there are two ways to learn
The first, deadknock linear algebra, deals with convolution algorithms
Second, first, because the current Gaussian blur application scenario, is not completely clear, you can use this part of the knowledge in the future, in learning, eraser to choose the second.
Gaussian blur is quite common in beauty software, and professional image processing tools are certainly available, mainly for polishing and frosted glass effects.
There is a good blog about Gaussian blur that you can refer to (it is suggested to open in a new TAB and learn by reference).
When looking for information, also found a big man on Gauss vague explanation, can refer to.
Function prototype introduction
Gaussian Blur
The function prototype is as follows:
dst = cv2.GaussianBlur(src, ksize, sigmaX, dst=None, sigmaY=None, borderType=None)
Copy the code
Parameter Description:
- SRC: original image;
- Ksize: The size of the Gaussian kernel in the format of (width, height), where width and height can be different, both are positive odd numbers; If I set it to zero, I get sigma;
- SigmaX: Standard deviation of Gaussian kernel in X direction;
- SigmaY: the standard deviation of the Gaussian kernel in the Y direction. If sigmaY is set to 0, it is equal to sigmaX. If both are 0, it can be calculated according to Ksize.
Official Manual Inspection
The test code is as follows:
import cv2
import numpy as np
img = cv2.imread('test.jpg')
# DST = cv2. GaussianBlur (img, ksize = (5, 5), sigmaX = 0, sigmaY = 0)
# Create frosted glass effect
# Parameter 2: Width and height of gaussian kernel (recommended to be odd)
# Parameter 3: Standard deviation of x and y axes
dst = cv2.GaussianBlur(img, (5.5), 0)
cv2.imshow('dst', dst)
cv2.waitKey()
Copy the code
Comparison between operation effect and original picture:
You can continue to modify the parameters, the larger the size and standard deviation of the Gaussian kernel, the more blurred the image
dst1 = cv2.GaussianBlur(img, (5.5), 0.5)
dst2 = cv2.GaussianBlur(img, (5.5), 1.5)
dst3 = cv2.GaussianBlur(img, (9.9), 1.5)
cv2.imshow('dst1', dst1)
cv2.imshow('dst2', dst2)
cv2.imshow('dst3', dst3)
Copy the code
Eraser section
This series of blogs is a learning journey, and some of the concepts will not be extended until they have been learned, or must be thoroughly mastered. Keep studying for 1 hour a day.
An hour has passed. Have you mastered the Python OpenCV related knowledge points?
As a beginner, there are many places to learn not in-depth, I hope you stick to it with me.
reading
Today is the 62/100 day of continuous writing. If you have ideas or techniques you’d like to share, feel free to leave them in the comments section.
Blogger ID: Dream eraser, hope you like, comment, favorites.