Python PIL | Image.point() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 Image
模块提供了一个同名的类,用于表示 PIL 图像。该模块还提供了许多工厂函数,包括从文件加载图像和创建新图像的函数。
Image.point()
通过查找表或函数映射此图像。
Syntax: Maps this image through a lookup table or function.
Parameters:
lut – A lookup table, containing 256 (or 65336 if self.mode==”I” and mode == “L”) values per band in the image. A function can be used instead, it should take a single argument. The function is called once for each possible pixel value, and the resulting table is applied to all bands of the image.
mode – Output mode (default is same as input). In the current version, this can only be used if the source image has mode “L” or “P”, and the output has mode “1” or the source image mode is “I” and the output mode is “L”.
Returns: An Image object.
使用的图像:
# importing Image class from PIL package
from PIL import Image
# creating a object
im = Image.open(r"C:\Users\System-Pc\Desktop\home.png")
# using point function
threshold = 191
im = im.point(lambda p: p >value threshold and 255)
im.show()
输出:
另一个例子:这里改变阈值。
使用的图像:
# importing Image class from PIL package
from PIL import Image
# creating a object
im = Image.open(r"C:\Users\System-Pc\Desktop\home.png")
# using point function
threshold = 120
im = im.point(lambda p: p > threshold and 255)
im.show()
输出: