Skip to main content

Image augmentation for PyTorch

Project description


Image augmentation for PyTorch

  • Apply random cropped rotations without going out of image bounds
  • Convert RGB to YUV color space
  • Adjust brightness and contrast, and more


Artwork by @hcnone

Quick Start

The transformations are designed to be chained together using torchvision.transforms.Compose. Additionally, there is a functional module. Functional transforms give more fine-grained control if you have to build a more complex transformation pipeline.


pip3 install -r requirements.txt
python3 install


  • Pillow
  • torchvision
  • numpy


from torchvision.transforms import ToTensor, ToPILImage, Compose
from PIL import Image
from imageaug.transforms import Colorspace, RandomAdjustment, RandomRotatedCrop

image_filename = 'test.png'
img =, 'r').convert("RGB")

crop_size = (64, 64)
angle_std = 90 # in degrees
# Note: apply color adjustments before a random rotated crop so that so that the
#       fillcolor for out of bounds is not randomly adjusted (this only applies
#       if you have images smaller than the crop size)
transform = Compose([
    # convert PIL Image to Tensor
    # convert RGB to YUV colorspace
    Colorspace("rgb", "yuv"),
    # randomly adjust the brightness and contrast of channel 0 (Y: luminance)
    RandomAdjustment(0, 0.1, 0.1, rgb=False),
    # randomly adjust the contrast of channel 1 and 2 (UV: color channels)
    RandomAdjustment((1,2), 0, 0.38, rgb=False),
    # convert YUV to RGB colorspace
    Colorspace("yuv", "rgb"),
    # convert Tensor back to PIL Image
    # random rotated crop
    RandomRotatedCrop(crop_size, 0.0, angle_std, downscale=0.5)
out = transform(img)"out.png")

Current Features

  • Rotate and crop images within the bounds of the original image for any given degree of angle perturbation (for training samples with rotational noise)
  • Convert images to and from RGB/YUV/YCH colorspace with alpha channel support
  • Adjust contrast and brightness of channels
  • Noise occulsion


This project is still a work in progress.

  • Uniform distribution for RandomRotatedCrop
  • Color lookup table for faster conversions between colorspaces
  • Add image, text, shape, and pixelation occulsions

Project Page


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ImageAug, version 0.1.0.post0
Filename, size File type Python version Upload date Hashes
Filename, size ImageAug-0.1.0.post0-py3.7.egg (15.7 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size ImageAug-0.1.0.post0-py3-none-any.whl (8.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size ImageAug-0.1.0.post0.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page