Python PIL.ImageChops.add() Examples

The following are 10 code examples of PIL.ImageChops.add(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PIL.ImageChops , or try the search function .
Example #1
Source Project: qiskit-terra   Author: Qiskit   File: results.py    License: Apache License 2.0 6 votes vote down vote up
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 
Example #2
Source Project: qiskit-terra   Author: Qiskit   File: results.py    License: Apache License 2.0 6 votes vote down vote up
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 
Example #3
Source Project: python3_ios   Author: holzschu   File: test_imagechops.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #4
Source Project: python3_ios   Author: holzschu   File: test_imagechops.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #5
Source Project: python3_ios   Author: holzschu   File: test_imagechops.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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)) 
Example #6
Source Project: python3_ios   Author: holzschu   File: test_imagechops.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_add_clip(self):
        # Arrange
        im = hopper()

        # Act
        new = ImageChops.add(im, im)

        # Assert
        self.assertEqual(new.getpixel((50, 50)), (255, 255, 254)) 
Example #7
Source Project: p5   Author: p5py   File: image.py    License: GNU General Public License v3.0 5 votes vote down vote up
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 
Example #8
Source Project: mxnet-lambda   Author: awslabs   File: pildriver.py    License: Apache License 2.0 5 votes vote down vote up
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)) 
Example #9
Source Project: pysster   Author: budach   File: Motif.py    License: MIT License 5 votes vote down vote up
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()) 
Example #10
Source Project: google-art-downloader   Author: mewforest   File: GoogleArtDownloader.py    License: GNU General Public License v3.0 5 votes vote down vote up
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)