In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how OpenCV uses Gaussian blur to achieve skinning and beauty effect, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
1. Gaussian blur 1. What is Gaussian blur?
We already know the mean fuzzy and the median fuzzy, and now we begin to understand the Gaussian blur.
First of all, Gauss refers to the Gaussian function, which I think everyone should know, is a very common probability distribution function. That's about what it looks like.
Through the mean fuzzy analogy, we can boldly guess the meaning of Gaussian fuzzy:
Each time the pixel values of different parts of the pixel matrix that need to be processed are different in the proportion of the final assigned pixels. This proportion is distributed according to the Gaussian function.
In other words, the farther away from the central pixel, the smaller the proportion of the pixel, and the central pixel value has the heaviest proportion in the assigned pixel.
In other words, we know that the matrix multiplied by the mean fuzzy is
And the 3'3 matrix multiplied by Gaussian blur can be like this.
This is what happens after visualization.
Although we can know the difference between Gaussian fuzzy and mean fuzzy mathematically, I personally think that Gaussian fuzzy can retain edge information better than mean fuzzy (just personal opinion).
Finally, the calculation formula of Gaussian ambiguity is provided to the math boss.
APIGaussianBlur (Mat src, Mat dst, Size (11,11), sigmax, sigmay) provided by 2.opencv
Where Size (x, y), x, y must be positive and odd.
The parameter SigmaX represents the standard variance in the X direction of the Gaussian equation.
The parameter SigmaY represents the standard variance in the X direction of the Gaussian equation.
In the Gaussian distribution, the variance can be understood as the smoothness of the Gaussian distribution, that is to say, the smaller the variance, the greater the proportion of the intermediate value, and the effect of blurring will be relatively lower (under the same size).
Visualize the matrix you will multiply:
When the variance is large:
The variance is small:
The two pictures here are not completely suitable, they are just analogies.
two。 Bilateral blur 1. What is bilateral ambiguity?
Considering whether it is mean blur or Gaussian blur, the final effect is the blur of the whole image. Sometimes we don't need to blur the whole, such as just blurring the edges or blurring the details.
On the other hand, bilateral ambiguity realizes the retention of edge information and weakens the details. (this effect can be used to grind the skin, you can think about why.)
The principle of implementation is that we determine a threshold that represents the difference between two pixels. Once this threshold is exceeded between two pixels, then the two pixels are not blurred by Gaussian blurring. Because the pixel difference in the edge area is relatively large, the edge information can be retained.
APIbilateralFilter of 2.opencv (src, dest, dice 15,150,3)
15-the calculated radius and the number of images within the radius will be included in the calculation. If-1 is provided, the value will be taken according to the sigma space parameter.
150-sigma color determines how many pixels within the difference will be calculated
3-sigma space declares invalid if the value of d is greater than 0, otherwise the value of d is calculated according to it
3. The realization of skin grinding and beauty effect 1. Realization process
Through the operation of deepening the contrast of the bilateral blurred image, the last thing is to deepen the blurred edge, which almost returns to the original effect. The blur effect removes the details from the skin, which makes the skin look smooth and glossy.
And I can use the slide rail to dynamically set the fuzzy threshold on both sides of the table so that you can control the effect of skin grinding.
two。 Main code # include # include using namespace cv;using namespace std;int main (int argc, char** argv) {string path = "xxxxxxxxxxxx.jpg"; Mat img = imread (path); Mat img2 = Mat::zeros (img.size (), img.type ()); Mat img3; Mat kernel = (Mat_ (3,3))
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.