Created
August 8, 2019 17:13
-
-
Save Lexie88rus/6b80fbfe94ae85d814aa77d0808fb96b to your computer and use it in GitHub Desktop.
Augmenting images with bounding boxes with imgaug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import bounding boxes from imgaug | |
| from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage | |
| # Initialize the bounding box for the original image | |
| # using helpers from imgaug package | |
| bbs = BoundingBoxesOnImage([ | |
| BoundingBox(x1=1, x2=980, y1=9, y2=535) | |
| ], shape=image.shape) | |
| # Define a simple augmentations pipeline for the image with bounding box | |
| seq = iaa.Sequential([ | |
| iaa.GammaContrast(1.5), # add contrast | |
| iaa.Affine(translate_percent={"x": 0.1}, scale=0.8), # translate the image | |
| iaa.Fliplr(p = 1.0) # apply horizontal flip | |
| ]) | |
| # Apply augmentations | |
| image_aug, bbs_aug = seq(image=image, bounding_boxes=bbs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment