Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the blur of Python OpenCV image

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article analyzes "how to do Python OpenCV image blur analysis" with you. The content is detailed and easy to understand. Friends who are interested in "how to analyze Python OpenCV image blur" can follow the editor's idea to read it slowly and deeply. I hope it will be helpful to everyone after reading. Let's follow the editor to learn more about "how to blur and analyze Python OpenCV images".

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 image ksize: blur core 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:

On how to carry out Python OpenCV image blurring analysis is shared here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report