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/03 Report--
This article mainly introduces "what is the process of blurring the image by Python OpenCV". In the daily operation, I believe that many people have doubts about what is the process of blurring the image by Python OpenCV. The editor has consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for you to answer the question of "what is the process of blurring the image by Python OpenCV?" Next, please follow the editor to study!
In fact, the convolution operation that we usually talk about in deep learning can also be carried out in opencv, or similar operations. So what is the operation of it? It is the blurring (filtering) of the image.
Mean filter
Use the cv2.blur (src, ksize) function in opencv. The parameters are described as follows:
Src: original ima
Ksize: fuzzy kernel size
Principle: it only takes the average of all pixels under the kernel area and replaces the central element. The 3x3 standardized cartridge filter is as follows:
Features: the contribution rate of regions in the core is the same.
Function: the filtering effect of salt and pepper noise is better.
#-*-coding:utf-8-*- "" File Name: image_deeplearning.pyProgram IDE: PyCharmDate: 2021/10/17Create File By Author: Hong "" import cv2 as cvdef image_blur (image_path: str): "" Image convolution operation: set the convolution kernel size Step: param image_path:: return: "img = cv.imread (image_path, cv.IMREAD_COLOR) cv.imshow ('input', img) # Fuzzy operation (similar to convolution) The second parameter ksize is to set the fuzzy kernel size result = cv.blur (img, (5,5)) cv.imshow ('result', result) cv.waitKey (0) cv.destroyAllWindows () if _ _ name__ = =' _ main__': path = 'images/2.png' image_blur (path)
The results show:
Gaussian filter
Gaussian filtering uses the cv2.GuassianBlur (img, ksize,sigmaX,sigmaY) function.
Description: sigmaX,sigmaY represents the standard deviation in the direction of XQuery Y respectively. If only sigmaX is specified, sigmaY is the same as sigmaX; if both are zero, they are calculated based on kernel size.
Features: the contribution rate of the region in the core is proportional to the distance from the center of the region, and the weight is related to the Gaussian distribution.
Function: Gaussian blur is very effective in removing Gaussian noise from images.
Def image_conv (image_path: str): "" Gaussian blur: param image_path:: return: "" img = cv.imread (image_path, cv.IMREAD_COLOR) cv.imshow ('img', img) # Gaussian convolution (Gaussian filtering). Ksize can be set, must be odd, and if not 0, the following steps will not work. It can also be set to (0if 0), and then the standard deviation result = cv.GaussianBlur (img, (0Power0), 15) cv.imshow ('result', result) cv.waitKey (0) cv.destroyAllWindows () if _ name__ = =' _ main__': path = 'images/2.png' image_conv (path) is calculated by sigmaX and sigmaY
The results show:
Gaussian bilateral filtering
Bilateral filtering (blur) uses the cv2.bilateralFilter (img,d, sigmaColor, sigmaSpace) function.
Description: d is the neighborhood diameter and sigmaColor is the standard deviation of spatial Gaussian function. The larger the parameter is, the smaller the adjacent pixel will be.
SigmaSpace gray value similarity Gaussian function standard deviation, the larger the parameter, the greater the influence of those colors that are close enough.
Bilateral filtering is a nonlinear filtering method, which is a tradeoff between spatial proximity and pixel similarity of an image, and considers spatial, information and gray similarity to achieve the purpose of edge preservation and denoising. It has the characteristics of simplicity, non-iteration and local processing. The reason why the filtering effect of edge preserving and denoising can be achieved is that the filter consists of two functions: one function determines the filter coefficient by the geometric space distance, and the other determines the filter coefficient by the pixel difference.
Features: processing takes time.
Function: it can guarantee certain edge information while filtering.
# Edge preserving filter-Gaussian bilateral blur def image_bifilter (image_path: str): "Gaussian bilateral blur: param image_path: picture file: return: no return value" img = cv.imread (image_path, cv.IMREAD_COLOR) cv.imshow ('input') Img) # the third parameter is to set the color, and the fourth parameter is to set the image coordinates result = cv.bilateralFilter (img, 0,50,10) cv.imshow ('result', result) cv.waitKey (0) cv.destroyAllWindows () if _ _ name__ = =' _ main__': path = 'images/2.png' image_bifilter (path)
The results show:
At this point, the study on "what is the process of blurring the image by Python OpenCV" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.