Python PIL | ImagePath.Path.map() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 ImagePath
模块用于存储和操作二维矢量数据。路径对象可以传递给ImageDraw
模块上的方法。
ImagePath.Path.map()
通过函数映射路径。
Syntax: ImagePath.Path.map(function)
Parameters:
arguments-creating a list.
range– assigning a range.
Returns: (x0, y0)
# from PIL importing ImagePath
from PIL import ImagePath
# creating a list to map
getbox = list(zip(range(3, 41, 1), range(11, 22, 2)))
result = ImagePath.Path(getbox)
# using map function
b = result.map(lambda x, y: (x + 2, y + 2))
a = result.tolist()
print(a)
输出:
[(5.0, 13.0), (6.0, 15.0), (7.0, 17.0), (8.0, 19.0), (9.0, 21.0), (10.0, 23.0)]
另一个例子:改变参数。
# from PIL importing ImagePath
from PIL import ImagePath
# creating a list to map
getbox = list(zip(range(3, 41, 1), range(11, 22, 2)))
result = ImagePath.Path(getbox)
# using map function
b = result.map(lambda x, y: (x + 12, y + 12))
a = result.tolist()
print(a)
输出:
[(15.0, 23.0), (16.0, 25.0), (17.0, 27.0), (18.0, 29.0), (19.0, 31.0), (20.0, 33.0)]