Python PIL.ImageChops.invert() Examples

The following are 5 code examples of PIL.ImageChops.invert(). 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 File: test_imagechops.py    From python3_ios with 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 #2
Source File: test_imagechops.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_invert(self):
        # Arrange
        im = Image.open("Tests/images/imagedraw_floodfill_RGB.png")

        # Act
        new = ImageChops.invert(im)

        # Assert
        self.assertEqual(new.getbbox(), (0, 0, 100, 100))
        self.assertEqual(new.getpixel((0, 0)), WHITE)
        self.assertEqual(new.getpixel((50, 50)), CYAN) 
Example #3
Source File: pildriver.py    From mxnet-lambda with Apache License 2.0 5 votes vote down vote up
def do_invert(self):
        """usage: invert <image:pic1>

        Invert the top image.
        """
        from PIL import ImageChops
        self.push(ImageChops.invert(self.do_pop())) 
Example #4
Source File: image.py    From ParanoiDF with GNU General Public License v3.0 4 votes vote down vote up
def export_image(self, image):
        stream = image.stream
        filters = stream.get_filters()
        (width, height) = image.srcsize
        if len(filters) == 1 and filters[0] in LITERALS_DCT_DECODE:
            ext = '.jpg'
        elif (image.bits == 1 or
              image.bits == 8 and image.colorspace in (LITERAL_DEVICE_RGB, LITERAL_DEVICE_GRAY)):
            ext = '.%dx%d.bmp' % (width, height)
        else:
            ext = '.%d.%dx%d.img' % (image.bits, width, height)
        name = image.name+ext
        path = os.path.join(self.outdir, name)
        fp = file(path, 'wb')
        if ext == '.jpg':
            raw_data = stream.get_rawdata()
            if LITERAL_DEVICE_CMYK in image.colorspace:
                from PIL import Image
                from PIL import ImageChops
                ifp = cStringIO.StringIO(raw_data)
                i = Image.open(ifp)
                i = ImageChops.invert(i)
                i = i.convert('RGB')
                i.save(fp, 'JPEG')
            else:
                fp.write(raw_data)
        elif image.bits == 1:
            bmp = BMPWriter(fp, 1, width, height)
            data = stream.get_data()
            i = 0
            width = (width+7)//8
            for y in xrange(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_RGB:
            bmp = BMPWriter(fp, 24, width, height)
            data = stream.get_data()
            i = 0
            width = width*3
            for y in xrange(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_GRAY:
            bmp = BMPWriter(fp, 8, width, height)
            data = stream.get_data()
            i = 0
            for y in xrange(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        else:
            fp.write(stream.get_data())
        fp.close()
        return name 
Example #5
Source File: image.py    From pdfminer3 with MIT License 4 votes vote down vote up
def export_image(self, image):
        stream = image.stream
        filters = stream.get_filters()
        (width, height) = image.srcsize
        if len(filters) == 1 and filters[0][0] in LITERALS_DCT_DECODE:
            ext = '.jpg'
        elif (image.bits == 1 or
              image.bits == 8 and image.colorspace in (LITERAL_DEVICE_RGB, LITERAL_DEVICE_GRAY)):
            ext = '.%dx%d.bmp' % (width, height)
        else:
            ext = '.%d.%dx%d.img' % (image.bits, width, height)
        name = image.name+ext
        path = os.path.join(self.outdir, name)
        fp=open(path, 'wb')
        if ext == '.jpg':
            raw_data = stream.get_rawdata()
            if LITERAL_DEVICE_CMYK in image.colorspace:
                from PIL import Image
                from PIL import ImageChops
                ifp = BytesIO(raw_data)
                i = Image.open(ifp)
                i = ImageChops.invert(i)
                i = i.convert('RGB')
                i.save(fp, 'JPEG')
            else:
                fp.write(raw_data)
        elif image.bits == 1:
            bmp = BMPWriter(fp, 1, width, height)
            data = stream.get_data()
            i = 0
            width = (width+7)//8
            for y in range(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_RGB:
            bmp = BMPWriter(fp, 24, width, height)
            data = stream.get_data()
            i = 0
            width = width*3
            for y in range(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_GRAY:
            bmp = BMPWriter(fp, 8, width, height)
            data = stream.get_data()
            i = 0
            for y in range(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        else:
            fp.write(stream.get_data())
        fp.close()
        return name