Last active
January 15, 2022 11:53
-
-
Save thuwarakeshm/79ca63803c6e23ff58442c443ddb367c to your computer and use it in GitHub Desktop.
This file contains 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
bboxes = [[0, 128, 300, 420], [366.7, 340, 270, 230]] | |
category_ids = [1, 2] | |
transform = A.Compose( | |
[A.HorizontalFlip(p=0.5), A.Rotate()], | |
bbox_params=A.BboxParams(format="coco", label_fields=["category_ids"]), # Configuring pipeline for annotation | |
) | |
# Passing annotation coordinates and categories with the image | |
transformed = transform(image=image, bboxes=bboxes, category_ids=category_ids) |
This file contains 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 albumentations as A | |
from PIL import Image | |
import numpy as np | |
# Create a pipline with 4 different transformations. | |
transform = A.Compose( | |
[ | |
A.RandomCrop(width=256, height=256), | |
A.HorizontalFlip(p=0.5), | |
A.RandomBrightnessContrast(brightness_limit=.5, contrast_limit=.3), | |
A.Rotate(), | |
] | |
) | |
# Read the image and convert it to a numpy array | |
pillow_image = Image.open("image.jpg") | |
image = np.array(pillow_image) | |
# Apply transformation | |
transformed = transform(image=image) | |
# Access and show transformation | |
transformed_image = transformed["image"] | |
img = Image.fromarray(transformed_image) | |
img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment