Package: discolight
DiscolightFlashy, ravey and state-of-the-art image augmentations to boost the
performance of deep convolutional neural networksAt a GlanceThe library works with images inHxWxC(channels last) format.Based on numpy, OpenCV, paperspace, imgaug and albumentation.Diversified set of augmentations available.Supports python 3.6-3.8Supports transformations on images, and bounding boxes.The library works with images inHxWxCformat.SetupThe easiest way to get started is to install thediscolightpackage
via pip:$ pip install discolightAlternatively, if you have cloned this repository, you can run pip on
the contents of the repository folder:$ pip install .Supported AugmentationsSampleImageAugmentedImageSampleImage (BoundingBoxes)AugmentedImage (BoundingBoxes)ColorTemperatureChanges the color temperature of the input image.GaussianNoiseAdd gaussian noise to the given image.GrayScaleReturn a grayscale version of the given image.HorizontalFlipHorizontally flips the given image.ImageCompressionApply a compression effect to the given image.MotionBlurAdd motionblur to a given image.OneOfPerform a randomly selected augmentation on the given image.RandomCropRandomly crops the given image.RandomEraserRandomly erase a rectangular area in the given image.RandomHSVRandomly shift the color space of the given image.RandomRotateRandomly rotate the given image.RandomScaleRandomly scale the given image.RandomShearRandomly shear the given image.RandomTranslateRandomly Translate the given image.ResizeResize an image without preserving aspect ratio.ResizeMaintainAspectRatioResize an image while preserving aspect ratio.RotateRotate the given image.SaltAndPepperNoiseAdd salt and pepper or RGB noise to the given image.ScaleScale the given image.SepiaReturns a given image passed through the sepia filter.SequencePerform a sequence of augmentations on the given image.ShearHorizontally shear the given image.TranslateTranslate the given image.VerticalFlipVertically flip the given image.Generating Augmented Images on the Command LineTo augment a set of images with annotations, you must first prepare
your input data and prepare YAML configuration file to describe the
augmentations you want to perform:input:images:loader:Directoryoptions:directory:./sample_images# The base path of where the images are storedannotations:loader:FourCornersCSVoptions:annotations_file:./sample_images/annotations.csv# The CSV file with annotationsnormalized:trueoutput:images:writer:Directoryoptions:directory:./output_folderannotations:writer:FourCornersCSVoptions:annotations_file:./output_folder/aug_annotations.csvnormalized:trueaugmentations:-name:GrayScaleoptions:probs:0.5-name:Rotateoptions:probs:0.7angle:35-name:GaussianNoiseoptions:probs:0.9-name:Shearoptions:{}save-original:true# Whether to save the original images to the output foldersave-bbox:true# Whether bounding boxes should be drawn on the augmented imagesThe image and annotation loaders specify how the images and
annotations should be loaded. TheFourCornersCSV(so-named because
it expects the bounding box to be specified with four coordinates)
loader expects an input CSV file in the following format:image_name,x_min,y_min,x_max,y_max,label
	wheat1.jpg,0,0.799805,0.037109,0.94043,1
	wheat1.jpg,0.064453,0.892578,0.181641,0.949219,1
	...The chosen image loader will be used to load the images specified
under theimage_namecolumn (for example,wheat1.jpg). In this
case, theDirectoryimage loader will fetch the images from the
specified folder. For more information on available image and
annotation loaders, see.Now you can run Discolight:$ discolight generate configuration.ymlYou can also pass your YAML configuration on standard input:$ cat configuration.yml | discolight generateAfter generation is complete, the augmented images and annotations
will be written out according to your configuration options. Here, we
choose to save the annotations to a CSV file using the same
four-corners format, and the augmented images will appear in theoutput_folder/directory.Library FunctionalityIn addition to invoking Discolight from the command line, you can also
invoke it as a library. First, construct the augmentation you want to
apply to an image. For example, here is a simple augmentation
sequence:fromdiscolight.discoimportdiscofromdiscolight.annoationsimportBoundingBoxfromdiscolight.util.imageimportload_image,save_imageseq=disco.Sequence(augmentations=[disco.GaussianNoise(),disco.RandomEraser(),disco.Rotate(angle=35)])Then, load the image and specify your annotations:image=load_image("path/to/image.jpg")annotations=[# BoundingBox(x_min, y_min, x_max, y_max, class_idx)BoundingBox(0,819,38,963,1),BoundingBox(66,914,186,972,1),BoundingBox(52,526,126,645,1),]Now, you can invokeseqas a function to apply your augmentation:aug_img,aug_annotations=seq(image,annotations)If you have no annotations, you can also applyseqonly to an image:aug_img=seq(image)To save the augmented image, use the providedsave_imagefunction. You can optionally pass the augmented annotations (also an
array ofBoundingBoxobjects) to be drawn in red over the augmented
image:save_image("aug-with-bboxes.jpg",aug_img,annotations=aug_annotations)save_image("aug-no-bboxes.jpg",aug_img)If you prefer to perform additional operations on the image after
augmentation, augmented images are OpenCV images in RGB format.DevelopmentTo learn more about how to develop Discolight (e.g., adding additional
augmentatations), see the guide indoc/develop.md.