Skip to main content

Image Augmentations 🚀



GitHub code size in bytes GitHub code size in bytes GitHub Repo stars GitHub followers

This is a augemntation tool for Object Detection , Image classification and Instance Segmentation , it can perform 14 annotations. The important ones are rotation, affine, zooming in and out, noise, and blur. The augmentations were applied to a fraction of the data (40 - 50 percent of the images out of 100 can be augmented).When rotating or zooming in and out, the bounding box coordinates will also change as the image is rotated or zoomed.


Code Starts from here

👩🏼‍💻Create a folder first, inside that folder keep your image annotation folder 👩🏼‍💻


👩🏼‍💻 Create a virtual environment 👩🏼‍💻

pip install virtualenv
#name your environment
python3 -m venv <your env name>

#activate the environment --> for linux user
source <your env name>/bin/activate

#activate the environment  --> for windows user
<your env name>/Source/activate.ps1

Installation (for pip installation) 🚀

pip install image_augs

After installation 🎯


Create a .py script inside your created folder

This Script is for OBJECT DETECTION

#import these modules in your created <scriptname>.py file


from object_detection_new.txt_reader_rect import RectAugmentation

################# image height and width combination  ##################

# first combination --> for custom image size
#  image_height = < custom image size > ; 640
#  image_width = < custom image size > ; 320


# second combination --> keep aspect ratio of the image
#  image_height = 640
#  image_width  = 'keep_aspect_ratio_False'

# Third combination --> keeping original image height and width
#  image_height = 'keep_original_image_height'
#  image_width = 'keep_original_image_width'



annotation_folder = 'your folder'
new_aug_saved_folder = 'new saved folder'
train_split = 0.90
image_H = 640  #check above for height and width setting
image_W = 'keep_aspect_ratio'


rect_aug = RectAugmentation(new_aug_saved_folder)

rect_aug.Image_augmentation(annotation_folder,
                                 
                                train_split=train_split,
                                 image_height= image_H,
                                 image_width= image_W,


                                 blur=False,  blur_f=0.8,

                                 motionBlur= False , motionBlur_f= 0.8 ,

                                 rotate=False, rotate_f = 0.8, 

                                 noise=False, noise_f=0.8,

                                 perspective=False, perspective_f = 0.8,

                                 affine=False, affine_f=0.8,

                                 brightness=False, brightness_f=0.8,
                                    
                                 hue=False, hue_f=0.8,

                                 removesaturation=False, removesaturation_f=0.8,

                                 contrast=False, contrast_f=0.8,

                                 upflip=False, upflip_f=0.8,

                                 shear=False, shear_f=0.8, 

                                 rotate90=False, rotate90_f =0.8,

                                 blur_and_noise=False, blur_and_noise_f=0.8,

                                 image_cutout = False, image_cutout_f=0.8,
                                    
                                 mix_aug= False, mix_aug_f=0.8, 
                                    
                                 temperature_change= False, temperature_change_f=0.8,  # change color temperature from cool to warm color

                                 weather_change=True,weather_change_f=0.8), # add rain , fog , snow in your images
                               
                                

#results will be saved in < your given folder >

This Script is for INSTANCE SEGMENTATION

#import these modules in your created <scriptname>.py file
from instance_seg.json_reader_poly import PolygonAugmentation


################# image height and width combination  ##################

# first combination --> for custom image size
#  image_height = < custom image size > ; 640
#  image_width = < custom image size > ; 320


# second combination --> keep aspect ratio of the image
#  image_height = 640
#  image_width  = 'keep_aspect_ratio_False'

# Third combination --> keeping original image height and width
#  image_height = 'keep_original_image_height'
#  image_width = 'keep_original_image_width'


#### yolo ####
# if yolo False then it will normalize all images and save it as txt , if false augmentations will be saved as json.

annotation_folder = 'your data'
new_aug_saved_folder = 'new saved dataset name'
train_split = 0.70
image_H = 640  #check above for height and width setting
image_W = 'keep_aspect_ratio'
yolo = True


im_aug_helper = PolygonAugmentation(aug_save_folder_name=new_aug_saved_folder,
                                    yolo=yolo)

im_aug_helper.Image_augmentation(annotation_folder,
                                 
                                 train_split=train_split,
                                 image_height= image_H,
                                 image_width= image_W,


                                 blur=True,  blur_f=0.8,

                                 motionBlur= False , motionBlur_f= 0.5,

                                 rotate=True, rotate_f = 0.8, 

                                 noise=True, noise_f=0.6,

                                 perspective=True, perspective_f = 0.6,

                                 affine=True, affine_f=0.6,

                                 brightness=True, brightness_f=0.6,
                                    
                                 hue=True, hue_f=0.6,

                                 removesaturation=True, removesaturation_f=0.6,

                                 contrast=True, contrast_f=0.6,

                                 upflip=True, upflip_f=0.8,

                                 shear=True , shear_f=0.7, 

                                 rotate90=True, rotate90_f =1.0,

                                 blur_and_noise=True, blur_and_noise_f=0.6,

                                 image_cutout = True, image_cutout_f=0.6,
                                    
                                 mix_aug=True, mix_aug_f=0.7,
                                    
                                 temperature_change=True, temperature_change_f=0.5,
                                 
                                 weather_change=True,weather_change_f=0.3)
#results will be saved in < your given folder >
***

This Script is for IMAGE CLASSIFICATION

#import these modules in your created <scriptname>.py file
from classification.classification_combined import ImageAugmentHelper


### PARAMS ###
source_folder = '<source folder>'
aug_saved_folder = '<augmentation saved folder>'
train_split = 0.5
image_height = 512
image_width = 512

classification_aug = ImageAugmentHelper(source_folder=source_folder,
                                        aug_save_folder_name=aug_saved_folder,
                                        train_split=train_split,
                                        height=image_height,
                                        width=image_width)


classification_aug.augmentations(

    save_raw_images=True,

    blur=True, blur_f=1.0,

    noise=True,noise_f=1.0,

    horizontalFlip=True, horizontalFlip_f=1.0,

    brightness=True, brightness_f=1.0,

    contrast=True, contrast_f=1.0,

    hue=True, hue_f=1.0,

    saturation=True, saturation_f=1.0,

    zoom=True, zoom_f=1.0,

    perspective=True, perspective_f=1.0,

    translation=True, translation_f=1.0,

    sharpen=True, sharpen_f=1.0,
    
    randomShadow=True, randomShadow_f=1.0
)

Use github to clone image_augmentations repo 🖥️ Use instanceSeg_aug_script.py / classification_aug_script.py / objectDetection_augScript.py according to your needs.


Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Metadata

Release files for image-augs 2.4.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for image-augs 2.4.20
File Size Uploaded
image_augs-2.4.20.tar.gz 29.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for image-augs 2.4.20
File Interpreter ABI Platform
image_augs-2.4.20-py3-none-any.whl Python 3 none any Details

Total release size: 60.6 kB

Release files / image_augs-2.4.20.tar.gz

Download URL image_augs-2.4.20.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8a9a8b0bbc73feabce251f5c5bb33a0cb05b58c848152562349222508a7be166
BLAKE2b-256 checksum
How to use checksums
092c8b9192e31aa7f858f861804669a6dddd921cb0e79d9a1f0c15f176105043
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / image_augs-2.4.20-py3-none-any.whl

Download URL image_augs-2.4.20-py3-none-any.whl
Size 31.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2be3af776442b062274223a3eb127b8c990e9c469f4d97c08846690a2a81e1ae
BLAKE2b-256 checksum
How to use checksums
57f2b8beb76e07df044d6eb3c90dc95ee6106b3b3e3593cb8de876680f9b98b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

2.4.20 This release

2 release files

2.4.19

2 release files

2.4.18

2 release files

2.4.16

2 release files

2.4.15

2 release files

2.3.15

2 release files

2.3.14

2 release files

2.3.13

2 release files

2.3.12

2 release files

2.3.11

2 release files

2.3.10

2 release files

2.2.10

2 release files

2.2.9

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.1

2 release files

0.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page