本文整理汇总了Python中ImageChops.difference方法的典型用法代码示例。如果您正苦于以下问题:Python ImageChops.difference方法的具体用法?Python ImageChops.difference怎么用?Python ImageChops.difference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageChops
的用法示例。
在下文中一共展示了ImageChops.difference方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rms_difference
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def rms_difference(self, im1, im2):
"Calculate the root-mean-square difference between two images"
diff = ImageChops.difference(im1, im2)
h = diff.histogram()
#sq = (value*(idx**2) for idx, value in enumerate(h))
sq = (value*((idx%256)**2) for idx, value in enumerate(h))
sum_of_squares = sum(sq)
rms = math.sqrt(sum_of_squares / float(im1.size[0] * im1.size[1]))
return rms
# Convert all captured images into the formats defined in image_defs
示例2: _compare_entropy
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def _compare_entropy(start_slice, end_slice, slice, difference):
"""
Calculate the entropy of two slices (from the start and end of an axis),
returning a tuple containing the amount that should be added to the start
and removed from the end of the axis.
"""
start_entropy = utils.image_entropy(start_slice)
end_entropy = utils.image_entropy(end_slice)
if end_entropy and abs(start_entropy / end_entropy - 1) < 0.01:
# Less than 1% difference, remove from both sides.
if difference >= slice * 2:
return slice, slice
half_slice = slice // 2
return half_slice, slice - half_slice
if start_entropy > end_entropy:
return 0, slice
else:
return slice, 0
示例3: do_subtract
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def do_subtract(self):
"""usage: subtract <image:pic1> <image:pic2> <int:offset> <float:scale>
Pop the two top images, produce the scaled difference with offset.
"""
import ImageChops
image1 = self.do_pop()
image2 = self.do_pop()
scale = float(self.do_pop())
offset = int(self.do_pop())
self.push(ImageChops.subtract(image1, image2, scale, offset))
# ImageEnhance classes
示例4: equal
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def equal(self, img1, img2, skip_area=None):
"""Compares two screenshots using Root-Mean-Square Difference (RMS).
@param img1: screenshot to compare.
@param img2: screenshot to compare.
@return: equal status.
"""
if not HAVE_PIL:
return None
# Trick to avoid getting a lot of screen shots only because the time in the windows
# clock is changed.
# We draw a black rectangle on the coordinates where the clock is locates, and then
# run the comparison.
# NOTE: the coordinates are changing with VM screen resolution.
if skip_area:
# Copying objects to draw in another object.
img1 = img1.copy()
img2 = img2.copy()
# Draw a rectangle to cover windows clock.
for img in (img1, img2):
self._draw_rectangle(img, skip_area)
# To get a measure of how similar two images are, we use
# root-mean-square (RMS). If the images are exactly identical,
# this value is zero.
diff = ImageChops.difference(img1, img2)
h = diff.histogram()
sq = (value * ((idx % 256)**2) for idx, value in enumerate(h))
sum_of_squares = sum(sq)
rms = math.sqrt(sum_of_squares/float(img1.size[0] * img1.size[1]))
# Might need to tweak the threshold.
return rms < 8
示例5: autocrop
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def autocrop(im, autocrop=False, **kwargs):
"""
Remove any unnecessary whitespace from the edges of the source image.
This processor should be listed before :func:`scale_and_crop` so the
whitespace is removed from the source image before it is resized.
autocrop
Activates the autocrop method for this image.
"""
if autocrop:
# If transparent, flatten.
if utils.is_transparent(im) and False:
no_alpha = Image.new('L', im.size, (255))
no_alpha.paste(im, mask=im.split()[-1])
else:
no_alpha = im.convert('L')
# Convert to black and white image.
bw = no_alpha.convert('L')
# bw = bw.filter(ImageFilter.MedianFilter)
# White background.
bg = Image.new('L', im.size, 255)
bbox = ImageChops.difference(bw, bg).getbbox()
if bbox:
im = im.crop(bbox)
return im
示例6: assertImagesEqual
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def assertImagesEqual(self, im1, im2, msg=None):
if im1.size != im2.size or (
ImageChops.difference(im1, im2).getbbox() is not None):
raise self.failureException(
msg or 'The two images were not identical')
示例7: near_identical
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def near_identical(im1, im2):
"""
Check if two images are identical (or near enough).
"""
diff = ImageChops.difference(im1, im2).histogram()
for color in diff[2:]:
if color:
return False
return True
示例8: do_difference
# 需要导入模块: import ImageChops [as 别名]
# 或者: from ImageChops import difference [as 别名]
def do_difference(self):
"""usage: difference <image:pic1> <image:pic2>
Pop the two top images, push the difference image
"""
import ImageChops
image1 = self.do_pop()
image2 = self.do_pop()
self.push(ImageChops.difference(image1, image2))