Using PIL Library in Python to implement picture Gaussian fuzzy instance _python

Source: Internet
Author: User

I. Installation of PIL

PIL is the Python Imaging library abbreviation for working with pictures. PIL has a picture of the Gaussian blur processing class, but there is a bug (the current 1.1.7bug still exists), that is, the fuzzy radius is written dead 2, can not be set. On the 160th line of the source imagefilter.py:

So, we'll just have to make a change here.

Project Address: http://www.pythonware.com/products/pil/

Second, the revised Code

The code is as follows:

Copy Code code as follows:

#-*-Coding:utf-8-*-

From PIL import Image, ImageFilter

Class Mygaussianblur (Imagefilter.filter):
Name = "Gaussianblur"

def __init__ (self, radius=2, Bounds=none):
Self.radius = Radius
Self.bounds = Bounds

def filter (self, image):
If Self.bounds:
Clips = Image.crop (self.bounds). Gaussian_blur (Self.radius)
Image.paste (clips, self.bounds)
return image
Else
Return Image.gaussian_blur (Self.radius)

Third, call

Copy Code code as follows:

simg = ' demo.jpg '
dimg = ' demo_blur.jpg '
Image = Image.open (simg)
Image = Image.filter (Mygaussianblur (radius=30))
Image.Save (DIMG)
Print dimg, ' success '

If you only need to process an area, pass in the bounds parameter

Four, the effect
Original artwork:

After processing:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.