📜  Python PIL |带有 ImageFilter 模块的图像过滤器

📅  最后修改于: 2022-05-13 01:55:26.559000             🧑  作者: Mango

Python PIL |带有 ImageFilter 模块的图像过滤器

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。

ImageFilter 模块包含一组预定义过滤器的定义,可与Image.filter()方法一起使用。

使用的图像:

过滤器 –
当前版本的库提供了一组预定义的图像增强过滤器:

1. 模糊

# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
  
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
  
# applying the blur filter
im2 = im1.filter(ImageFilter.BLUR)
  
im2.show()

输出:
2. 轮廓

# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
  
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
  
# applying the contour filter
im2 = im1.filter(ImageFilter.CONTOUR)
  
im2.show()

输出:
3.浮雕

# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
  
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
  
# applying the emboss filter
im2 = im1.filter(ImageFilter.EMBOSS)
  
im2.show()

输出:
4.EDGE_ENHANCE

# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
  
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
  
# applying the EDGE_ENHANCE filter
im2 = im1.filter(ImageFilter.EDGE_ENHANCE)
  
im2.show()

输出:
5.EDGE_ENHANCE_MORE

# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
  
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
  
# applying the EDGE_ENHANCE_MORE filter
im2 = im1.filter(ImageFilter.EDGE_ENHANCE_MORE)
  
im2.show()

输出: