Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PiecewiseAffine #892

Merged
merged 11 commits into from
May 17, 2021
Merged

PiecewiseAffine #892

merged 11 commits into from
May 17, 2021

Conversation

Dipet
Copy link
Collaborator

@Dipet Dipet commented May 15, 2021

Implemented PiecewiseAffine is a same as IAAPiecewiseAffine

Example:

import albumentations as A
import numpy as np
import imgaug.augmenters as iaa
import cv2 as cv
import random
import matplotlib.pyplot as plt


def draw_data(image, bboxes, keypoints):
    image = image.copy()

    for x1, y1, x2, y2, _ in bboxes:
        cv.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (255, 0, 0), 3)

    for x, y in keypoints:
        cv.circle(image, (int(x), int(y)), 10, (0, 255, 0), -1)

    return image


seed = 0
np.random.seed(seed)
random.seed(seed)

img = cv.imread("/home/dipet/GitRepos/albumentations_examples/images/original_parrot.jpg")
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
h, w = img.shape[:2]

bboxes = []
keypoints = []
for i in range(10):
    keypoints.append((random.randint(0, w - 1), random.randint(0, h - 1)))

    x1 = random.randint(0, w - 1)
    y1 = random.randint(0, h - 1)
    x2 = random.randint(x1, w)
    y2 = random.randint(y1, h)
    bboxes.append([x1, y1, x2, y2, 0])

t1 = A.Compose([
    A.PiecewiseAffine(
            p=1,
    ),
],
    keypoint_params=A.KeypointParams("xy"),
    bbox_params=A.BboxParams("pascal_voc"),
)

t2 = A.Compose([
    A.PiecewiseAffine(
            scale=0.33,
            nb_rows=(10, 20),
            nb_cols=33,
            interpolation=2,
            mask_interpolation=1,
            cval=10,
            cval_mask=20,
            mode="edge",
            absolute_scale=True,
            p=1,
    ),
],
    keypoint_params=A.KeypointParams("xy"),
    bbox_params=A.BboxParams("pascal_voc"),
)

plt.figure(figsize=(10, 10))
plt.subplot(221, title="original")
plt.imshow(draw_data(img, bboxes, keypoints))
plt.subplot(222, title="result")
plt.imshow(draw_data(**t1(image=img, bboxes=bboxes, keypoints=keypoints)))
plt.subplot(223, title="result")
plt.imshow(draw_data(**t1(image=img, bboxes=bboxes, keypoints=keypoints)))
plt.subplot(224, title="result")
plt.imshow(draw_data(**t2(image=img, bboxes=bboxes, keypoints=keypoints)))
plt.show()

image

@Dipet Dipet changed the title Implementation of IAAPiecewiseAffine PiecewiseAffine May 15, 2021
@Dipet Dipet requested review from BloodAxe and ternaus May 16, 2021 18:53
@BloodAxe BloodAxe merged commit b527fa9 into master May 17, 2021
@Dipet Dipet deleted the iaa_piecewise_affine branch May 20, 2021 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants