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: