aleju / imgaug

Image augmentation for machine learning experiments.
http://imgaug.readthedocs.io
MIT License
14.43k stars 2.44k forks source link

Are there any function to remove the bbox with too small area after transformation? #786

Open lantudou opened 3 years ago

lantudou commented 3 years ago

Hi, I am a freshman of this library, I want to use some transformation which could lead to the change of bbox location and range to argument my dataset of object detection.

Now my question is are there any function to remove the bbox with too small area after transformation? The function is like the min_visibility parameter in albumentations as follows:

import albumentations  as A

augmentation_pipeline = A.Compose(
    [
        A.HorizontalFlip(p = 0.5), # apply horizontal flip to 50% of images
        A.VerticalFlip(p=0.5),
        A.OneOf(
               [

                   #A.CLAHE(clip_limit=1),
                   A.RandomBrightnessContrast(),
                   A.RandomGamma(),
                   A.Blur()

               ],
            p = 1
        ),

        A.OneOf(
            [
                # apply one of transforms to 50% of images
                A.RandomContrast(), # apply random contrast
                A.RandomGamma(), # apply random gamma
                A.RandomBrightnessContrast(), # apply random brightness
            ],
            p = 0.5
        ),
        A.OneOf(
            [
                # apply one of transforms to 50% images
                A.ElasticTransform(
                    alpha = 120,
                    sigma = 120 * 0.05,
                    alpha_affine = 120 * 0.03,
                    border_mode = cv2.BORDER_CONSTANT

                ),
                A.GridDistortion(border_mode = cv2.BORDER_CONSTANT),
                A.OpticalDistortion(
                    distort_limit = 3,
                    shift_limit = 0.6,
                    border_mode = cv2.BORDER_CONSTANT
                ),
            ],
            p = 0
        ),
        A.OneOf(
            [

                    A.SafeRotate(limit=10,border_mode=cv2.BORDER_CONSTANT)

            ],
            p = 0
        ),
    ],

    bbox_params= A.BboxParams('coco',   min_visibility= 0.3)

) 

Because I want to remove the bbox with a small area in the transformed image like this:

image