How to use the augmentor.transform.change_transform_origin function in Augmentor

To help you get started, we’ve selected a few Augmentor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xuannianz / keras-CenterNet / augmentor / misc.py View on Github external
def translate(image, boxes, prob=0.5, border_value=(128, 128, 128)):
    random_prob = np.random.uniform()
    if random_prob < (1 - prob):
        return image, boxes
    h, w = image.shape[:2]
    min_x1, min_y1 = np.min(boxes, axis=0)[:2]
    max_x2, max_y2 = np.max(boxes, axis=0)[2:]
    translation_matrix = translation_xy(min=(min(-min_x1 // 2, 0), min(-min_y1 // 2, 0)),
                                        max=(max((w - max_x2) // 2, 1), max((h - max_y2) // 2, 1)), prob=1.)
    translation_matrix = change_transform_origin(translation_matrix, (w / 2, h / 2))
    image = cv2.warpAffine(
        image,
        translation_matrix[:2, :],
        dsize=(w, h),
        flags=cv2.INTER_CUBIC,
        borderMode=cv2.BORDER_CONSTANT,
        borderValue=border_value,
    )
    new_boxes = []
    for box in boxes:
        x1, y1, x2, y2 = box
        points = translation_matrix.dot([
            [x1, x2, x1, x2],
            [y1, y2, y2, y1],
            [1, 1, 1, 1],
        ])
github xuannianz / EfficientDet / augmentor / misc.py View on Github external
def translate(image, boxes, prob=0.5, border_value=(128, 128, 128)):
    boxes = boxes.astype(np.float32)
    random_prob = np.random.uniform()
    if random_prob < (1 - prob):
        return image, boxes
    h, w = image.shape[:2]
    if boxes.shape[0] != 0:
        min_x1, min_y1 = np.min(boxes, axis=0)[:2]
        max_x2, max_y2 = np.max(boxes, axis=0)[2:]
        translation_matrix = translation_xy(min=(min(-min_x1 // 2, 0), min(-min_y1 // 2, 0)),
                                            max=(max((w - max_x2) // 2, 1), max((h - max_y2) // 2, 1)), prob=1.)
    else:
        translation_matrix = translation_xy(min=(min(-w // 8, 0), min(-h // 8, 0)),
                                            max=(max(w // 8, 1), max(h // 8, 1)))
    translation_matrix = change_transform_origin(translation_matrix, (w / 2, h / 2))
    image = cv2.warpAffine(
        image,
        translation_matrix[:2, :],
        dsize=(w, h),
        flags=cv2.INTER_CUBIC,
        borderMode=cv2.BORDER_CONSTANT,
        borderValue=border_value,
    )
    if boxes.shape[0] != 0:
        new_boxes = []
        for box in boxes:
            x1, y1, x2, y2 = box
            points = translation_matrix.dot([
                [x1, x2, x1, x2],
                [y1, y2, y2, y1],
                [1, 1, 1, 1],

Augmentor

Image augmentation library for Machine Learning

MIT
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages