A tutorial on using the PIL module in Python to blur a picture with Gauss

Source: Internet
Author: User

This article mainly introduces the use of the PiL module in Python to the image of the Gaussian Blur process tutorial, this no graphical interface script code is very simple, the need for friends can refer to the

As you can see from an article, PiL 1.1.5 has built-in Gaussian blur, but is not mentioned in the document, and the PiL Gaussian blur radius is hard coded, although the construction method has the incoming radius parameters, but there is no use (see here), so need to transform themselves, of course, Knowing the reason, the modification is naturally very simple.

In combination with the requirements in the post, Gaussian blur to the local, so you also need to combine the crop and paste methods to implement the local use of filters.

The code is as follows:

?

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22-23 #-*-coding:utf-8-*-from PIL import Image, ImageFilter class Mygaussianblur (imagefilter.filter): name = "GAUSSIANBL ur "def __init__" (Self, radius=2, bounds=none): Self.radius = Radius Self.bounds = Bounds def filter (self, image): if s Elf.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 = (130, 280, 230) image = Image.open (' source.jpg ') image = Ima Ge.filter (Mygaussianblur (radius=29, Bounds=bounds)) Image.show ()

You can look at the effect:

Related Keywords:
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD