Try running some AugLy image augmentations! For a full list of available augmentations, see here.
Our image augmentations use PIL
as their backend. All functions accept a path to the image or a PIL Image object to be augmented as input and return the augmented PIL Image object. If an output path is specified, the image will also be saved to a file.
You can call the functional augmentations like so:
import augly.image as imaugs
image_path = "your_img_path.png"
output_path = "your_output_path.png"
# Augmentation functions can accept image paths as input and
# always return the resulting augmented PIL Image
aug_image = imaugs.apply_ig_filter(image_path, filter_name="clarendon")
# Augmentation functions can also accept PIL Images as input
aug_image = imaugs.pad_square(aug_image)
# If an output path is specified, the image will also be saved to a file
aug_image = imaugs.overlay_onto_screenshot(aug_image, output_path=output_path)
You can also call any augmentation as a Transform class, including composing them together and applying them with a given probability. This also means that you can easily integrate with PyTorch transformations if needed:
import torchvision.transforms as transforms
import augly.image as imaugs
COLOR_JITTER_PARAMS = {
"brightness_factor": 1.2,
"contrast_factor": 1.2,
"saturation_factor": 1.4,
}
AUGMENTATIONS = [
imaugs.Blur(),
imaugs.ColorJitter(**COLOR_JITTER_PARAMS),
imaugs.OneOf(
[imaugs.ScreenshotOverlay(), imaugs.EmojiOverlay(), imaugs.TextOverlay()]
),
]
TRANSFORMS = imaugs.Compose(AUGMENTATIONS)
TENSOR_TRANSFORMS = transforms.Compose(AUGMENTATIONS + [transforms.ToTensor()])
# aug_image is a PIL image with your augs applied!
# aug_tensor_image is a Tensor with your augs applied!
image = Image.open("your_img_path.png")
aug_image = TRANSFORMS(image)
aug_tensor_image = TENSOR_TRANSFORMS(image)
If your image is currently in the form of a NumPy array and you don't want to save the image as a file before using the augmentation functions, you can use our NumPy wrapper:
from augly.image import aug_np_wrapper, overlay_emoji
np_image = np.zeros((300, 300))
# pass in function arguments as kwargs
np_aug_img = aug_np_wrapper(np_image, overlay_emoji, **{'opacity': 0.5, 'y_pos': 0.45})
You can run our normal image unit tests if you have cloned augly
(see here) by running the following:
python -m unittest discover -s augly/tests/image_tests/ -p "*_tests.py"
Note: If you want to additionally run the pytorch unit test (you must have torchvision installed), you can run:
python -m unittest discover -s augly/tests/image_tests/ -p "*"