CVAugmentor
The CVAugmentor Augmentation Package.
CVAugmentor is a python package for augmenting image and video files. It provides a number of utilities that aid augmentation in a automated manner. The aim of the package is to make augmentation easier. The package is built on top of the OpenCV and Pillow libraries.
- class CVAugmentor.pipeline.Pipeline
- augment(input_path: str, output_path: str, target: str, process_type: str, mode: str, augmentations: Dict[str, Callable], verbose: Optional[bool] = False, aug_verbose: Optional[bool] = False, warn_verbose: Optional[bool] = False) None
Augments the input data.
- Parameters
input_path (str) – Path to the input data.
output_path (str) – Path to the output data.
target (str) –
- Target of the augmentation.
- The options are:
- ”image”
Specifies that the target of the augmentation is an image.
- ”video”
Specifies that the target of the augmentation is a video.
process_type (str) –
- Type of the augmentation.
- The options are:
- ”batch”
Batch type means that the input and output paths are directories.
- ”single”
Single type means that the input and output paths are files.
mode (str) –
- Mode of the augmentation.
- The options are:
- ”sequential”
Sequential mode means that the augmentations will be applied one by one. This means that the data will be saved after each augmentation.
- ”singular”
Singular mode means that the augmentations will be applied all at once. This means that the data will be saved only after all augmentations were applied.
augmentations (dict) – Dict of augmentations to be applied to the data. The keys are the names of the augmentations and the values are the augmentations themselves.
verbose (bool, optional) – If True, prints the overall progress of the augmentation process. The default is False.
aug_verbose (bool, optional) – If True, prints the progress of the augmentation process. The default is False.
warn_verbose (bool, optional) – If True, prints the warnings. The default is False.
- Return type
None.
- class CVAugmentor.assets.main.augmentations_class.Augmentations
- Class containing the image augmentations.
- The augmentations include:
no_augmentation, flip, zoom, rotate, shear, grayscale, hue, saturation, brightness, exposure, blur, noise, cutout, negative.
- static blur(radius: Optional[Union[int, float]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Blur the image. The blur radius is the standard deviation of the Gaussian blur.
- Parameters
radius (int or float, optional) – Blur radius. The default is None. If None, a random blur radius is generated.
- Returns
blur_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static brightness(brightness_factor: Optional[Union[int, float]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Adjust the brightness of the image.
- Parameters
brightness_factor (int or float, optional) – Brightness factor. The default is None. If None, a random brightness factor is generated.
- Returns
brightness_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static cutout(max_count: Optional[int] = None, max_size: Optional[Union[int, float]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Cutout a random part of the image. This method cuts out a random part of the image and replaces it with a black rectangle.
- Parameters
max_size (int or float, optional) – Maximum size of the cutout. The default is None. If None, a random maximum size is generated.
max_count (int, optional) – Maximum number of cutouts. The default is None. If None, a random maximum count is generated.
- Returns
cutout_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static exposure(exposure_factor: Optional[Union[int, float]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Adjust the exposure of the image. The exposure means the amount of light that reaches the image sensor.
- Parameters
exposure_factor (int or float, optional) – Exposure factor. The default is None. If None, a random exposure factor is generated.
- Returns
exposure_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static flip(flip_type: Optional[str] = 'vertical') Callable[[PIL.Image.Image], PIL.Image.Image]
Flip the image horizontally or vertically.
- Parameters
flip_type (str, optional) –
- Type of flip. The default is “vertical”.
- The options are:
- ”horizontal”
Flip the image horizontally
- ”vertical”
Flip the image vertically
- Returns
flip_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static grayscale() Callable[[PIL.Image.Image], PIL.Image.Image]
Convert the image to grayscale. Note that the grayscale conversion is keeping the image in RGB format in order to be consistent with the other methods.
- Parameters
None. –
- Returns
grayscale_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static hue(hue_shift: Optional[Union[int, float]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Shift the hue of the image. Hue is the color of the image.
- Parameters
hue_shift (int or float, optional) – Hue shift value. The default is None. If None, a random hue shift value is generated.
- Returns
hue_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static negative() Callable[[PIL.Image.Image], PIL.Image.Image]
Convert the image to negative. This method converts the image to negative by inverting the pixel values.
- Parameters
None. –
- Returns
negative_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static no_augmentation() Callable[[PIL.Image.Image], PIL.Image.Image]
No augmentation. This can be used when you want to copy the image to the output folder without augmenting it.
- Parameters
None. –
- Returns
no_augmentation_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static noise(intensity: Optional[Union[int, float]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Add noise to the image. This method adds noise to the image by multiplying the pixel values by a random number between -1 and 1. It creates a noisy image that looks like the output from an analog TV with bad reception.
- Parameters
intensity (int or float, optional) – Noise intensity. The default is None. If None, a random noise intensity is generated.
- Returns
noise_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static rotate(rotate_type: Optional[str] = 'definite', angle: Optional[Union[int, float]] = 90) Callable[[PIL.Image.Image], PIL.Image.Image]
Rotate the image by a definite angle or a random angle.
- Parameters
rotate_type (str, optional) –
- Type of rotation. The default is “definite”.
- The options are:
- ”definite”
Rotate the image by a definite angle
- ”random”
Rotate the image by a random angle
angle (int or float, optional if rotate_type is "random") – Angle of rotation. The default is 90.
- Returns
rotate_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static saturation(saturation_factor: Optional[Union[int, float]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Adjust the saturation of the image. The stauration means the intensity of the colors.
- Parameters
saturation_factor (int or float, optional) – Saturation factor. The default is None. If None, a random saturation factor is generated.
- Returns
saturation_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static shear(shear: Optional[Tuple[Union[int, float], Union[int, float]]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Shear the image. The shearing means that the image is slanted along the x-axis and/or y-axis.
- Parameters
shear (tuple, optional) – Shear values. The default is None. If None, a random shear value is generated.
- Returns
shear_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function
- static zoom(zoom_size: Optional[Tuple[Union[int, float], Union[int, float]]] = None) Callable[[PIL.Image.Image], PIL.Image.Image]
Zoom the image.
- Parameters
zoom_size (tuple, optional) – Size of the zoom. The default is None. If None, a random zoom size is generated.
- Returns
zoom_wrapper –
- Args:
- imageImage.Image
The image to be augmented.
- Return type
function