本文整理匯總了Python中PIL.ImageChops.add方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageChops.add方法的具體用法?Python ImageChops.add怎麽用?Python ImageChops.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PIL.ImageChops
的用法示例。
在下文中一共展示了ImageChops.add方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: black_or_b
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def black_or_b(diff_image, image, reference, opacity=0.85):
"""Copied from https://stackoverflow.com/a/30307875 """
thresholded_diff = diff_image
for _ in range(3):
thresholded_diff = ImageChops.add(thresholded_diff, thresholded_diff)
size = diff_image.size
mask = new_gray(size, int(255 * (opacity)))
shade = new_gray(size, 0)
new = reference.copy()
new.paste(shade, mask=mask)
if image.size != new.size:
image = image.resize(new.size)
if image.size != thresholded_diff.size:
thresholded_diff = thresholded_diff.resize(image.size)
new.paste(image, mask=thresholded_diff)
return new
示例2: _repr_html_
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def _repr_html_(self):
ret = self.summary()
ret += "<div>"
for name in self.names:
fullpath_name = os.path.join(self.directory, name)
fullpath_reference = os.path.join(self.directory, 'references', name)
if os.path.exists(os.path.join(SWD, fullpath_reference)):
if self.data[name]['ratio'] == 1:
ret += Results.passed_result_html(fullpath_name, fullpath_reference,
self.data[name]['diff_name'],
self.data[name]['title'])
else:
ret += Results.failed_result_html(fullpath_name, fullpath_reference,
self.data[name]['diff_name'],
self.data[name]['title'])
else:
title = 'Download <a download="%s" href="%s">this image</a> to <tt>%s</tt>' \
' and add/push to the repo</td>' % (name, fullpath_name, fullpath_reference)
ret += Results.no_reference_html(fullpath_name, title)
ret += "</div>"
return ret
示例3: test_sanity
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def test_sanity(self):
im = hopper("L")
ImageChops.constant(im, 128)
ImageChops.duplicate(im)
ImageChops.invert(im)
ImageChops.lighter(im, im)
ImageChops.darker(im, im)
ImageChops.difference(im, im)
ImageChops.multiply(im, im)
ImageChops.screen(im, im)
ImageChops.add(im, im)
ImageChops.add(im, im, 2.0)
ImageChops.add(im, im, 2.0, 128)
ImageChops.subtract(im, im)
ImageChops.subtract(im, im, 2.0)
ImageChops.subtract(im, im, 2.0, 128)
ImageChops.add_modulo(im, im)
ImageChops.subtract_modulo(im, im)
ImageChops.blend(im, im, 0.5)
ImageChops.composite(im, im, im)
ImageChops.offset(im, 10)
ImageChops.offset(im, 10, 20)
示例4: test_add
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def test_add(self):
# Arrange
im1 = Image.open("Tests/images/imagedraw_ellipse_RGB.png")
im2 = Image.open("Tests/images/imagedraw_floodfill_RGB.png")
# Act
new = ImageChops.add(im1, im2)
# Assert
self.assertEqual(new.getbbox(), (25, 25, 76, 76))
self.assertEqual(new.getpixel((50, 50)), ORANGE)
示例5: test_add_scale_offset
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def test_add_scale_offset(self):
# Arrange
im1 = Image.open("Tests/images/imagedraw_ellipse_RGB.png")
im2 = Image.open("Tests/images/imagedraw_floodfill_RGB.png")
# Act
new = ImageChops.add(im1, im2, scale=2.5, offset=100)
# Assert
self.assertEqual(new.getbbox(), (0, 0, 100, 100))
self.assertEqual(new.getpixel((50, 50)), (202, 151, 100))
示例6: test_add_clip
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def test_add_clip(self):
# Arrange
im = hopper()
# Act
new = ImageChops.add(im, im)
# Assert
self.assertEqual(new.getpixel((50, 50)), (255, 255, 254))
示例7: load_image
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def load_image(filename):
"""Load an image from the given filename.
Loads an image into a variable of type PImage. Four types of
images may be loaded.
In most cases, load all images in setup() or outside the draw()
call to preload them at the start of the program. Loading images
inside draw() will reduce the speed of a program.
:param filename: Filename (or path)of the given image. The
file-extennsion is automatically inferred.
:type filename: str
:returns: An :class:`p5.PImage` instance with the given image data
:rtype: :class:`p5.PImage`
"""
# todo: add support for loading images from URLs -- abhikpal
# (2018-08-14)
img = Image.open(filename)
w, h = img.size
pimg = PImage(w, h)
pimg._img = img
return pimg
示例8: do_add
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def do_add(self):
"""usage: add <image:pic1> <image:pic2> <int:offset> <float:scale>
Pop the two top images, produce the scaled sum with offset.
"""
from PIL import ImageChops
image1 = self.do_pop()
image2 = self.do_pop()
scale = float(self.do_pop())
offset = int(self.do_pop())
self.push(ImageChops.add(image1, image2, scale, offset))
示例9: _trim
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def _trim(self, img):
bg = Image.new(img.mode, img.size, img.getpixel((0,0)))
diff = ImageChops.difference(img, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
return img.crop(diff.getbbox())
示例10: trim
# 需要導入模塊: from PIL import ImageChops [as 別名]
# 或者: from PIL.ImageChops import add [as 別名]
def trim(image):
bg = Image.new(image.mode, image.size, image.getpixel((0, 0)))
diff = ImageChops.difference(image, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
bbox = diff.getbbox()
if bbox:
return image.crop(bbox)