Skip to main content

Image augmentation for PyTorch

Project description

ImageAug

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

Example

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.

Install

pip3 install -r requirements.txt
python3 setup.py install

Requirements:

  • Pillow
  • torchvision
  • numpy

Example

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

image_filename = 'test.png'
img = Image.open(image_filename, '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
    ToTensor(),
    # 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
    ToPILImage(),
    # random rotated crop
    RandomRotatedCrop(crop_size, 0.0, angle_std, downscale=0.5)
])
out = transform(img)
out.save("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

To-do

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

Github: https://github.com/paixi/ImageAug

Project details


Download files

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

Source Distribution

ImageAug-0.1.0.post0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distributions

ImageAug-0.1.0.post0-py3.7.egg (15.7 kB view details)

Uploaded Source

ImageAug-0.1.0.post0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file ImageAug-0.1.0.post0.tar.gz.

File metadata

  • Download URL: ImageAug-0.1.0.post0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for ImageAug-0.1.0.post0.tar.gz
Algorithm Hash digest
SHA256 f2e67cfa2b9602c70e2b9152d02875111df59ad7ac1082560eca17c327a31f59
MD5 79793bfa06ab43fbec7e27f4eab57502
BLAKE2b-256 2b06a7205b1a49976cf92073344d230add959b92b19de326d1f4ebb3b7dcba5c

See more details on using hashes here.

File details

Details for the file ImageAug-0.1.0.post0-py3.7.egg.

File metadata

  • Download URL: ImageAug-0.1.0.post0-py3.7.egg
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for ImageAug-0.1.0.post0-py3.7.egg
Algorithm Hash digest
SHA256 516c231941b02d618d5a34c5d29a11cab1d37e6d596de773e066d1431b2e7a43
MD5 4240fc50e59c10a689b5346c251a6adc
BLAKE2b-256 4aa4888ec8bdfba978f4841ee51d06e9fe72e76830c11a7536a33a68852a1a83

See more details on using hashes here.

File details

Details for the file ImageAug-0.1.0.post0-py3-none-any.whl.

File metadata

  • Download URL: ImageAug-0.1.0.post0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for ImageAug-0.1.0.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e2f57e50208bd5a4add2245ba7fe10b1730fdd25506a0548c309bc98990ee50
MD5 2be7889784c820ee5cc0bba1ba2d2b3f
BLAKE2b-256 b03294b150eaacdf0320e30b7ac65bed574dcfa3a65d72c6487f1e7f7e7b1a8f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page