本文整理汇总了Python中PIL.ImageOps方法的典型用法代码示例。如果您正苦于以下问题:Python PIL.ImageOps方法的具体用法?Python PIL.ImageOps怎么用?Python PIL.ImageOps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PIL
的用法示例。
在下文中一共展示了PIL.ImageOps方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pad
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def pad(self, image, *args, **kwargs):
""" Calls ``PIL.ImageOps.expand``.
For more details see `<http://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.expand>`_.
Parameters
----------
offset : sequence
Size of the borders in pixels. The order is (left, top, right, bottom).
mode : {'const', 'wrap'}
Filling mode
src : str
Component to get images from. Default is 'images'.
dst : str
Component to write images to. Default is 'images'.
p : float
Probability of applying the transform. Default is 1.
"""
return PIL.ImageOps.expand(image, *args, **kwargs)
示例2: flip
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def flip(self, image, mode='lr'):
""" Flips image.
Parameters
----------
mode : {'lr', 'ud'}
- 'lr' - apply the left/right flip
- 'ud' - apply the upside/down flip
src : str
Component to get images from. Default is 'images'.
dst : str
Component to write images to. Default is 'images'.
p : float
Probability of applying the transform. Default is 1.
"""
if mode == 'lr':
return PIL.ImageOps.mirror(image)
return PIL.ImageOps.flip(image)
示例3: posterize
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def posterize(self, image, bits=4):
""" Posterizes image.
More concretely, it quantizes pixels' values so that they have``2^bits`` colors
Parameters
----------
bits : int
Number of bits used to store a color's component.
src : str
Component to get images from. Default is 'images'.
dst : str
Component to write images to. Default is 'images'.
p : float
Probability of applying the transform. Default is 1.
"""
return PIL.ImageOps.posterize(image, bits)
示例4: generate_ascii
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def generate_ascii(self, image):
font = PIL.ImageFont.truetype(self.files_path('FreeMonoBold.ttf'), 15, encoding="unic")
image_width, image_height = image.size
aalib_screen_width= int(image_width/24.9)*10
aalib_screen_height= int(image_height/41.39)*10
screen = aalib.AsciiScreen(width=aalib_screen_width, height=aalib_screen_height)
im = image.convert("L").resize(screen.virtual_size)
screen.put_image((0,0), im)
y = 0
how_many_rows = len(screen.render().splitlines())
new_img_width, font_size = font.getsize(screen.render().splitlines()[0])
img = PIL.Image.new("RGBA", (new_img_width, how_many_rows*15), (255,255,255))
draw = PIL.ImageDraw.Draw(img)
for lines in screen.render().splitlines():
draw.text((0,y), lines, (0,0,0), font=font)
y = y + 15
imagefit = PIL.ImageOps.fit(img, (image_width, image_height), PIL.Image.ANTIALIAS)
return imagefit
示例5: do_waaw
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def do_waaw(self, b):
f = BytesIO()
f2 = BytesIO()
with wand.image.Image(file=b, format='png') as img:
h1 = img.clone()
width = int(img.width/2) if int(img.width/2) > 0 else 1
h1.crop(width=width, height=int(img.height), gravity='east')
h2 = h1.clone()
h1.rotate(degree=180)
h1.flip()
h1.save(file=f)
h2.save(file=f2)
f.seek(0)
f2.seek(0)
list_im = [f2, f]
imgs = [PIL.ImageOps.mirror(PIL.Image.open(i).convert('RGBA')) for i in list_im]
min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1]
imgs_comb = np.hstack((np.asarray(i.resize(min_shape)) for i in imgs))
imgs_comb = PIL.Image.fromarray(imgs_comb)
final = BytesIO()
imgs_comb.save(final, 'png')
final.seek(0)
return final
#Thanks to Iguniisu#9746 for the idea
示例6: do_haah
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def do_haah(self, b):
f = BytesIO()
f2 = BytesIO()
with wand.image.Image(file=b, format='png') as img:
h1 = img.clone()
h1.transform('50%x100%')
h2 = h1.clone()
h2.rotate(degree=180)
h2.flip()
h1.save(file=f)
h2.save(file=f2)
f.seek(0)
f2.seek(0)
list_im = [f2, f]
imgs = [PIL.ImageOps.mirror(PIL.Image.open(i).convert('RGBA')) for i in list_im]
min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1]
imgs_comb = np.hstack((np.asarray(i.resize(min_shape)) for i in imgs))
imgs_comb = PIL.Image.fromarray(imgs_comb)
final = BytesIO()
imgs_comb.save(final, 'png')
final.seek(0)
return final
示例7: AutoContrast
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def AutoContrast(img, _):
return PIL.ImageOps.autocontrast(img)
示例8: Invert
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def Invert(img, _):
return PIL.ImageOps.invert(img)
示例9: Equalize
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def Equalize(img, _):
return PIL.ImageOps.equalize(img)
示例10: Flip
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def Flip(img, _): # not from the paper
return PIL.ImageOps.mirror(img)
示例11: Solarize
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def Solarize(img, v): # [0, 256]
assert 0 <= v <= 256
return PIL.ImageOps.solarize(img, v)
示例12: Posterize2
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def Posterize2(img, v): # [0, 4]
assert 0 <= v <= 4
v = int(v)
return PIL.ImageOps.posterize(img, v)
示例13: Posterize
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def Posterize(img, v): # [4, 8]
#assert 4 <= v <= 8
v = int(v)
return PIL.ImageOps.posterize(img, v)
示例14: AutoContrast
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def AutoContrast(img, **kwarg):
return PIL.ImageOps.autocontrast(img)
示例15: Equalize
# 需要导入模块: import PIL [as 别名]
# 或者: from PIL import ImageOps [as 别名]
def Equalize(img, **kwarg):
return PIL.ImageOps.equalize(img)