In Python, the PIL module is used to perform Gaussian blur on images,

Source: Internet
Author: User

In Python, the PIL module is used to perform Gaussian blur on images,

From an article, we can see that PIL 1.1.5 has built-in Gaussian blur, but it is not mentioned in this document, and radius is hard-coded in the Gaussian blur of PIL, although the radius parameter is passed in the constructor, It is not used at all (see here). Therefore, you need to modify it yourself. Of course, knowing the cause makes the modification very easy.

According to the requirements in the post, perform Gaussian blur on the local part. Therefore, use the crop and paste methods to implement local filter.

The Code is as follows:

#-*-Coding: UTF-8-*-from PIL import Image, ImageFilterclass 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) bounds = (150,130,280,230) image = Image.open('source.jpg ') image = image. filter (MyGaussianBlur (radius = 29, bounds = bounds) image. show ()

You can see the following results:

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.