當前位置: 首頁>>代碼示例>>Python>>正文


Python ImageChops.difference方法代碼示例

本文整理匯總了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 
開發者ID:eoghan-c,項目名稱:photobooth,代碼行數:13,代碼來源:photo_handling.py

示例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 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:21,代碼來源:processors.py

示例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 
開發者ID:YoYoAdorkable,項目名稱:ngx_status,代碼行數:15,代碼來源:pildriver.py

示例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 
開發者ID:evandowning,項目名稱:cuckoo-headless,代碼行數:35,代碼來源:screenshot.py

示例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 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:29,代碼來源:processors.py

示例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') 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:7,代碼來源:test_processors.py

示例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 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:11,代碼來源:test_source_generators.py

示例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)) 
開發者ID:YoYoAdorkable,項目名稱:ngx_status,代碼行數:11,代碼來源:pildriver.py


注:本文中的ImageChops.difference方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。