Skip to main content

Simple image augmentation library focusing on random geometric cropping.

Project description


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.


  • 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)


pip install imgcrop



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


  • 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


  • random_crop: function


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


  • 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)


  • 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)


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

python example/

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)
rotation + scaling
distortion + scaling
flip + rotation
margin + scaling


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.


  1. imgaug,
  2. Augmentor,
  3. 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 hashes)

Uploaded source

Built Distribution

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

Uploaded py3

Supported by

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