Package: imgcrop
imgcropSimple 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 likeimgaug[1],Augmentor[2], andalbumentations[3]
to further transform images cropped by this library.FeaturesSimple API, easy to useEfficient; 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)InstallationpipinstallimgcropAPIsimgcrop.get_cropperget_cropper(patch_size=128,scale=(1.0,1.0),rotate=(0,0),distort=0.0,flip=0.0,margin=0)parameterspatch_size:int, default 128output patch size (in pixel)scale:tuple of float, default (1.0, 1.0)sampling scale rangerotate:tuple of int, default (0, 0)sampling rotation range (in degree)distort:float, default 0.0distortion strength in perspective transformation (ratio to output image scale)flip:float, default 0.0horizontal flip probabilitymargin:int, default 0margin in cropping around original imagereturnsrandom_crop: functionrandom_croprandom_crop(img,points=None)->cropped_img[,output_points],src_points,mparametersimg:numpy array (single image) or list of numpy arrays (multiple images)input image(s) to be cropped with the same geometric transformationpoints:numpy array with the shape (point_num, 2), default Noneinput points to be transformed with the same transformation matrix as input image(s)returnscropped_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 givensrc_points:numpy arraypoints defining the cropped region in the input image(s)m:numpy array3x3 perspective transformation matrix from the input image(s) to the output image(s)ExamplePleaes run or refer tothe example scriptto see how this library works:pythonexample/example.pyYou can easily try different parameters by arguments:optionalarguments:-h,--helpshowthishelpmessageandexit--patch_sizePATCH_SIZEoutputpatchimagesize(default:256)--scaleSCALESCALEscalerangeinsampling(default:[0.8,1.2])--rotateROTATEROTATErotationrangeinsampling(default:[-60,60])--distortDISTORTdistortionstrengthforperspectivetransformation(default:0.2)--flipFLIPhorizontalflipprobability(default:0.5)--marginMARGINmarginaroundoriginalimage(default:0)parameterscropping results (input, cropped, mask, keypoints)scalingrotation + scalingdistortion + scalingflip + rotationmargin + scalingallAlgorithmPatch 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.Referencesimgaug,https://github.com/aleju/imgaugAugmentor,https://github.com/mdbloice/Augmentoralbumentations,https://github.com/albu/albumentations