In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Python how to generate random Gaussian blur picture related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Python how to generate random Gaussian blur picture article will have a harvest, let's take a look.
Introduction and principle of Gaussian blur
Usually, image processing software provides a "blur" filter to blur the picture.
There are many algorithms for "blur", one of which is called "Gaussian Blur". It uses normal distribution (also known as "Gaussian distribution") for image processing.
The so-called "blur" can be understood to mean that each pixel takes the average of the surrounding pixels.
If you use simple averaging, it is obviously not very reasonable, because the images are continuous, the closer the point is, the closer the point relationship is, and the farther away the point relationship is, the more distant the point relationship is. Therefore, the weighted average is more reasonable, the closer the distance is, the greater the weight is, and the farther the distance is, the smaller the weight is.
Python generates Gaussian blur
Python can easily generate blurred images using the opencv library, and if you don't have opencv installed, you can install it with pip:
Pip install python-opencv
If you want to know what Gaussian blur is, you can see wiki encyclopedia-Gaussian blur. For ordinary people, as long as you know that this operation can generate blurred images, you can do it with one line of code:
Import cv2img = cv2.GaussianBlur (ori_img, (9,9), 0)
The first parameter of this function is the original image, the second parameter is the Gaussian matrix, note that the length and width must be singular, the third parameter is the standard deviation, if you write 0, the function will calculate itself.
Then how to control the degree of blur? Very simply, the larger the size of the Gaussian matrix, the greater the standard deviation, and the greater the blurred degree of the processed image.
After introducing the simple Gaussian blur operation, we add a random processing to randomly generate several images with different blur degrees, which is actually very simple, just add a random function to generate the size of the Gaussian matrix:
Import cv2import randomimgName = "img.png" min_size = 11ori_img = cv2.imread (imgName) for i in range (3): addition = random.choice ((0,2,4,6,8,10,12)) size = min_size + addition kernel_size = (size, size) img = cv2.GaussianBlur (ori_img, kernel_size) 0) new_imgName = "New_" + str (I) + "_" + str (kernel_size [0]) + "_" + imgName cv2.imwrite (new_imgName, img)
Here the use of the random library, to randomly select a number in a group of numbers, add to the minimum size, as each generated blur image of the Gaussian matrix size, here my minimum size is set to 11, you can try to see the effect to set according to your needs.
This is the end of the article on "how to generate random Gaussian blur images by Python". Thank you for reading! I believe that everyone has a certain understanding of "how to generate random Gaussian blur pictures in Python". If you want to learn more, you are welcome to follow the industry information channel.
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.