Skip to main content

Simple image augmentation library focusing on random geometric cropping.

Project description

imgcrop

Simple image augmentation library focusing on random geometric cropping. Different from pipeline-based augmentation libraries, this library efficiently performs cropping and geometric transformations at once. As image processing functions such as adding Gaussian noise, blurring, and contrast adjustment are not provided, please use the other great libraries like imgaug [1], Augmentor [2], and albumentations [3] to further transform images cropped by this library.

Features

  • Simple API, easy to use
  • Efficient; cropping and all geometric transformations are performed at once (by a single perspective transformation)
  • Guarantee that all pixels in cropped image are taken from inside the original image (if margin is not used)

Installation

pip install imgcrop

APIs

imgcrop.get_cropper

get_cropper(patch_size=128, scale=(1.0, 1.0), rotate=(0, 0), distort=0.0, flip=0.0, margin=0)

parameters

  • patch_size: int, default 128
    • output patch size (in pixel)
  • scale: tuple of float, default (1.0, 1.0)
    • sampling scale range
  • rotate: tuple of int, default (0, 0)
    • sampling rotation range (in degree)
  • distort: float, default 0.0
    • distortion strength in perspective transformation (ratio to output image scale)
  • flip: float, default 0.0
    • horizontal flip probability
  • margin: int, default 0
    • margin in cropping around original image

returns

  • random_crop: function

random_crop

random_crop(img, points=None) -> cropped_img[, output_points], src_points, m

parameters

  • img: numpy array (single image) or list of numpy arrays (multiple images)
    • input image(s) to be cropped with the same geometric transformation
  • points: numpy array with the shape (point_num, 2), default None
    • input points to be transformed with the same transformation matrix as input image(s)

returns

  • cropped_img: numpy array or list of numpy arrays)
    • cropped output image(s)
  • output_points: numpy array with the shape (point_num, 2)
    • output points if input points are given
  • src_points: numpy array
    • points defining the cropped region in the input image(s)
  • m: numpy array
    • 3x3 perspective transformation matrix from the input image(s) to the output image(s)

Example

Pleaes run or refer to the example script to see how this library works:

python example/example.py

You can easily try different parameters by arguments:

optional arguments:
  -h, --help            show this help message and exit
  --patch_size PATCH_SIZE
                        output patch image size (default: 256)
  --scale SCALE SCALE   scale range in sampling (default: [0.8, 1.2])
  --rotate ROTATE ROTATE
                        rotation range in sampling (default: [-60, 60])
  --distort DISTORT     distortion strength for perspective transformation
                        (default: 0.2)
  --flip FLIP           horizontal flip probability (default: 0.5)
  --margin MARGIN       margin around original image (default: 0)
parameters cropping results (input, cropped, mask, keypoints)
scaling
rotation + scaling
distortion + scaling
flip + rotation
margin + scaling
all

Algorithm

Patch region in the original image is defined by a set of four points. These points are randomly transformed according to transformation parameters. The transformation matrix from input image to output image is then calculated using these points. Finally, cropping is performed by applying perspective transformation.

References

  1. imgaug, https://github.com/aleju/imgaug
  2. Augmentor, https://github.com/mdbloice/Augmentor
  3. albumentations, https://github.com/albu/albumentations

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

imgcrop-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imgcrop-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file imgcrop-0.1.0.tar.gz.

File metadata

  • Download URL: imgcrop-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.4

File hashes

Hashes for imgcrop-0.1.0.tar.gz
Algorithm Hash digest
SHA256 360649c4b00ad85c42a002da58d87c05b008c4f8d759ea67407c4966a2bf88be
MD5 5dc1aa76babc76250d1b0a1aeaac6b1d
BLAKE2b-256 608373c5f3a458a65b404c7f1643d06bc9d4d07c9adc53f89952e293a44d0eb3

See more details on using hashes here.

File details

Details for the file imgcrop-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: imgcrop-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.4

File hashes

Hashes for imgcrop-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fc7dc3d61a5c3c37addcfccaf2f490b0e9d8b99123e4b3bce6e3d0670a70ebc
MD5 903bb55afdcc6169b9ce503d5064ce2b
BLAKE2b-256 fc1db9d85582cd6a71fd13990206f0ab183fae82fa9a2a0a74e5d4b158c50908

See more details on using hashes here.

Supported by

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