Python PIL.ImageOps() Examples

The following are 30 code examples of PIL.ImageOps(). 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 , or try the search function .
Example #1
Source File: batch_image.py    From batchflow with Apache License 2.0 6 votes vote down vote up
def pad(self, image, *args, **kwargs):
        """ Calls ``PIL.ImageOps.expand``.

        For more details see `<http://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.expand>`_.

        Parameters
        ----------
        offset : sequence
            Size of the borders in pixels. The order is (left, top, right, bottom).
        mode : {'const', 'wrap'}
            Filling mode
        src : str
            Component to get images from. Default is 'images'.
        dst : str
            Component to write images to. Default is 'images'.
        p : float
            Probability of applying the transform. Default is 1.
        """
        return PIL.ImageOps.expand(image, *args, **kwargs) 
Example #2
Source File: batch_image.py    From batchflow with Apache License 2.0 6 votes vote down vote up
def flip(self, image, mode='lr'):
        """ Flips image.

        Parameters
        ----------
        mode : {'lr', 'ud'}

            - 'lr' - apply the left/right flip
            - 'ud' - apply the upside/down flip
        src : str
            Component to get images from. Default is 'images'.
        dst : str
            Component to write images to. Default is 'images'.
        p : float
            Probability of applying the transform. Default is 1.
        """
        if mode == 'lr':
            return PIL.ImageOps.mirror(image)
        return PIL.ImageOps.flip(image) 
Example #3
Source File: batch_image.py    From batchflow with Apache License 2.0 6 votes vote down vote up
def posterize(self, image, bits=4):
        """ Posterizes image.

        More concretely, it quantizes pixels' values so that they have``2^bits`` colors

        Parameters
        ----------
        bits : int
            Number of bits used to store a color's component.
        src : str
            Component to get images from. Default is 'images'.
        dst : str
            Component to write images to. Default is 'images'.
        p : float
            Probability of applying the transform. Default is 1.
        """
        return PIL.ImageOps.posterize(image, bits) 
Example #4
Source File: Fun.py    From NotSoBot with MIT License 6 votes vote down vote up
def generate_ascii(self, image):
		font = PIL.ImageFont.truetype(self.files_path('FreeMonoBold.ttf'), 15, encoding="unic")
		image_width, image_height = image.size
		aalib_screen_width= int(image_width/24.9)*10
		aalib_screen_height= int(image_height/41.39)*10
		screen = aalib.AsciiScreen(width=aalib_screen_width, height=aalib_screen_height)
		im = image.convert("L").resize(screen.virtual_size)
		screen.put_image((0,0), im)
		y = 0
		how_many_rows = len(screen.render().splitlines()) 
		new_img_width, font_size = font.getsize(screen.render().splitlines()[0])
		img = PIL.Image.new("RGBA", (new_img_width, how_many_rows*15), (255,255,255))
		draw = PIL.ImageDraw.Draw(img)
		for lines in screen.render().splitlines():
			draw.text((0,y), lines, (0,0,0), font=font)
			y = y + 15
		imagefit = PIL.ImageOps.fit(img, (image_width, image_height), PIL.Image.ANTIALIAS)
		return imagefit 
Example #5
Source File: Fun.py    From NotSoBot with MIT License 6 votes vote down vote up
def do_waaw(self, b):
		f = BytesIO()
		f2 = BytesIO()
		with wand.image.Image(file=b, format='png') as img:
			h1 = img.clone()
			width = int(img.width/2) if int(img.width/2) > 0 else 1
			h1.crop(width=width, height=int(img.height), gravity='east')
			h2 = h1.clone()
			h1.rotate(degree=180)
			h1.flip()
			h1.save(file=f)
			h2.save(file=f2)
		f.seek(0)
		f2.seek(0)
		list_im = [f2, f]
		imgs = [PIL.ImageOps.mirror(PIL.Image.open(i).convert('RGBA')) for i in list_im]
		min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1]
		imgs_comb = np.hstack((np.asarray(i.resize(min_shape)) for i in imgs))
		imgs_comb = PIL.Image.fromarray(imgs_comb)
		final = BytesIO()
		imgs_comb.save(final, 'png')
		final.seek(0)
		return final

	#Thanks to Iguniisu#9746 for the idea 
Example #6
Source File: Fun.py    From NotSoBot with MIT License 6 votes vote down vote up
def do_haah(self, b):
		f = BytesIO()
		f2 = BytesIO()
		with wand.image.Image(file=b, format='png') as img:
			h1 = img.clone()
			h1.transform('50%x100%')
			h2 = h1.clone()
			h2.rotate(degree=180)
			h2.flip()
			h1.save(file=f)
			h2.save(file=f2)
		f.seek(0)
		f2.seek(0)
		list_im = [f2, f]
		imgs = [PIL.ImageOps.mirror(PIL.Image.open(i).convert('RGBA')) for i in list_im]
		min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1]
		imgs_comb = np.hstack((np.asarray(i.resize(min_shape)) for i in imgs))
		imgs_comb = PIL.Image.fromarray(imgs_comb)
		final = BytesIO()
		imgs_comb.save(final, 'png')
		final.seek(0)
		return final 
Example #7
Source File: Fun.py    From NotSoBot with MIT License 5 votes vote down vote up
def flop(self, ctx, *urls:str):
		get_images = await self.get_images(ctx, urls=urls, limit=5)
		if not get_images:
			return
		for url in get_images:		
			b = await self.bytes_download(url)
			img = PIL.Image.open(b)
			img = PIL.ImageOps.mirror(img)
			final = BytesIO()
			img.save(final, 'png')
			final.seek(0)
			await self.bot.upload(final, filename='flop.png') 
Example #8
Source File: augmentations.py    From cutmix with MIT License 5 votes vote down vote up
def AutoContrast(img, _):
    return PIL.ImageOps.autocontrast(img) 
Example #9
Source File: augmentations.py    From cutmix with MIT License 5 votes vote down vote up
def Invert(img, _):
    return PIL.ImageOps.invert(img) 
Example #10
Source File: augmentations.py    From cutmix with MIT License 5 votes vote down vote up
def Equalize(img, _):
    return PIL.ImageOps.equalize(img) 
Example #11
Source File: augmentations.py    From cutmix with MIT License 5 votes vote down vote up
def Flip(img, _):  # not from the paper
    return PIL.ImageOps.mirror(img) 
Example #12
Source File: augmentations.py    From cutmix with MIT License 5 votes vote down vote up
def Solarize(img, v):  # [0, 256]
    assert 0 <= v <= 256
    return PIL.ImageOps.solarize(img, v) 
Example #13
Source File: augmentations.py    From cutmix with MIT License 5 votes vote down vote up
def Posterize2(img, v):  # [0, 4]
    assert 0 <= v <= 4
    v = int(v)
    return PIL.ImageOps.posterize(img, v) 
Example #14
Source File: Fun.py    From NotSoBot with MIT License 5 votes vote down vote up
def flip(self, ctx, *urls:str):
		get_images = await self.get_images(ctx, urls=urls, limit=5)
		if not get_images:
			return
		for url in get_images:		
			b = await self.bytes_download(url)
			img = PIL.Image.open(b)
			img = PIL.ImageOps.flip(img)
			final = BytesIO()
			img.save(final, 'png')
			final.seek(0)
			await self.bot.upload(final, filename='flip.png') 
Example #15
Source File: augmentations.py    From fast-autoaugment with MIT License 5 votes vote down vote up
def Posterize2(img, v):  # [0, 4]
    assert 0 <= v <= 4
    v = int(v)
    return PIL.ImageOps.posterize(img, v) 
Example #16
Source File: augmentations.py    From pytorch-randaugment with MIT License 5 votes vote down vote up
def AutoContrast(img, _):
    return PIL.ImageOps.autocontrast(img) 
Example #17
Source File: augmentations.py    From pytorch-randaugment with MIT License 5 votes vote down vote up
def Invert(img, _):
    return PIL.ImageOps.invert(img) 
Example #18
Source File: augmentations.py    From pytorch-randaugment with MIT License 5 votes vote down vote up
def Equalize(img, _):
    return PIL.ImageOps.equalize(img) 
Example #19
Source File: augmentations.py    From pytorch-randaugment with MIT License 5 votes vote down vote up
def Flip(img, _):  # not from the paper
    return PIL.ImageOps.mirror(img) 
Example #20
Source File: augmentations.py    From pytorch-randaugment with MIT License 5 votes vote down vote up
def Solarize(img, v):  # [0, 256]
    assert 0 <= v <= 256
    return PIL.ImageOps.solarize(img, v) 
Example #21
Source File: augmentations.py    From pytorch-randaugment with MIT License 5 votes vote down vote up
def Posterize(img, v):  # [4, 8]
    v = int(v)
    v = max(1, v)
    return PIL.ImageOps.posterize(img, v) 
Example #22
Source File: augment.py    From autogluon with Apache License 2.0 5 votes vote down vote up
def AutoContrast(img, _):
    return PIL.ImageOps.autocontrast(img) 
Example #23
Source File: augment.py    From autogluon with Apache License 2.0 5 votes vote down vote up
def Invert(img, _):
    return PIL.ImageOps.invert(img) 
Example #24
Source File: augment.py    From autogluon with Apache License 2.0 5 votes vote down vote up
def Equalize(img, _):
    return PIL.ImageOps.equalize(img) 
Example #25
Source File: augment.py    From autogluon with Apache License 2.0 5 votes vote down vote up
def Flip(img, _):  # not from the paper
    return PIL.ImageOps.mirror(img) 
Example #26
Source File: augment.py    From autogluon with Apache License 2.0 5 votes vote down vote up
def Solarize(img, v):  # [0, 256]
    assert 0 <= v <= 256
    return PIL.ImageOps.solarize(img, v) 
Example #27
Source File: augment.py    From autogluon with Apache License 2.0 5 votes vote down vote up
def Posterize(img, v):  # [4, 8]
    #assert 4 <= v <= 8
    v = int(v)
    return PIL.ImageOps.posterize(img, v) 
Example #28
Source File: augment.py    From autogluon with Apache License 2.0 5 votes vote down vote up
def Posterize2(img, v):  # [0, 4]
    assert 0 <= v <= 4
    v = int(v)
    return PIL.ImageOps.posterize(img, v) 
Example #29
Source File: randAug.py    From Tricks-of-Semi-supervisedDeepLeanring-Pytorch with MIT License 5 votes vote down vote up
def Invert(img, **kwarg):
    return PIL.ImageOps.invert(img) 
Example #30
Source File: augmentations.py    From autoclint with Apache License 2.0 5 votes vote down vote up
def Invert(img, _):
    return PIL.ImageOps.invert(img)