def test_random_brightness_in_memory():

    tmp, tmpdir = create_colour_temp_image((800, 800), "JPEG")

    op = Operations.RandomBrightness(probability=1,
                                     min_factor=0.5,
                                     max_factor=1.5)
    tmp_im = []
    tmp_im.append(Image.open(tmp))
    tmp_im = op.perform_operation(tmp_im)

    assert tmp_im is not None
    assert isinstance(tmp_im[0], Image.Image)

    tmp_bw, tmpdir_bw = create_greyscale_temp_image((800, 800), "PNG")

    op = Operations.RandomBrightness(probability=1,
                                     min_factor=0.5,
                                     max_factor=1.5)
    tmp_im = []
    tmp_im.append(Image.open(tmp))
    tmp_im = op.perform_operation(tmp_im)

    assert tmp_im is not None
    assert isinstance(tmp_im[0], Image.Image)

    tmp.close()
    tmp_bw.close()
    shutil.rmtree(tmpdir)
    shutil.rmtree(tmpdir_bw)
def test_random_brightness_in_memory():

    im, tmpdir = create_colour_temp_image((800, 800), "JPEG")

    op = Operations.RandomBrightness(probability=1,
                                     min_factor=0.5,
                                     max_factor=1.5)
    tmp_im = op.perform_operation([im])

    assert tmp_im is not None
    assert isinstance(tmp_im[0], Image.Image)
    shutil.rmtree(tmpdir)

    if os.name == "nt":
        # not testing bw images
        return

    im_bw, tmpdir_bw = create_greyscale_temp_image((800, 800), "PNG")

    op = Operations.RandomBrightness(probability=1,
                                     min_factor=0.5,
                                     max_factor=1.5)
    tmp_im = op.perform_operation([im_bw])

    assert tmp_im is not None
    assert isinstance(tmp_im[0], Image.Image)

    shutil.rmtree(tmpdir_bw)
示例#3
0
 def __init__(self):
     self.imgaug_transform = iaa.Add((127, 127), per_channel=False)
     self.augmentor_op = Operations.RandomBrightness(probability=1,
                                                     min_factor=1.5,
                                                     max_factor=1.5)
     self.solt_stream = slc.Stream(
         [slt.ImageRandomBrightness(p=1, brightness_range=(127, 127))])
示例#4
0
 def __init__(self):
     self.imgaug_transform = iaa.Sequential(
         [iaa.Multiply((1.5, 1.5), per_channel=False), iaa.Add((127, 127), per_channel=False)]
     )
     self.augmentor_pipeline = Pipeline()
     self.augmentor_pipeline.add_operation(
         Operations.RandomBrightness(probability=1, min_factor=1.5, max_factor=1.5)
     )
     self.augmentor_pipeline.add_operation(Operations.RandomContrast(probability=1, min_factor=1.5, max_factor=1.5))
     self.solt_stream = slc.Stream(
         [
             slt.ImageRandomBrightness(p=1, brightness_range=(127, 127)),
             slt.ImageRandomContrast(p=1, contrast_range=(1.5, 1.5)),
         ]
     )
示例#5
0
def get_augmentation_group(data_aug_group,
                           input_size,
                           center=True,
                           resize=True):
    resize_prob = 1 if resize else 0
    center_prob = 1 if center else 0

    DATA_AUGMENTATION_GROUPS = [
        # GROUP 0 (NO DATA AUGMENTATION)
        [
            # Center crop
            CropCenter(probability=center_prob),
            # Resize the image to the desired input size
            Operations.Resize(probability=resize_prob,
                              width=input_size[0],
                              height=input_size[1],
                              resample_filter="BICUBIC")
        ],
        # GROUP 1 (Common transformations: rotations, flips, crops, shears)
        [
            # Rotate the image by 90 degrees randomly
            Operations.Rotate(probability=0.5, rotation=-1),
            # Flip top/bottom
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="TOP_BOTTOM"),
            # Flip left/right
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="LEFT_RIGHT"),
            # Random crops
            Operations.CropPercentage(probability=0.5,
                                      percentage_area=0.85,
                                      centre=center,
                                      randomise_percentage_area=True),
            # Resize the image to the desired input size
            Operations.Resize(probability=resize_prob,
                              width=input_size[0],
                              height=input_size[1],
                              resample_filter="BICUBIC")
        ],
        # GROUP 2 (Pixel intensity transformations)
        [
            # Rotate the image by 90 degrees randomly
            Operations.Rotate(probability=0.5, rotation=-1),
            # Flip top/bottom
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="TOP_BOTTOM"),
            # Flip left/right
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="LEFT_RIGHT"),
            # Random change brightness of the image
            Operations.RandomBrightness(probability=0.5,
                                        min_factor=0.5,
                                        max_factor=1.5),
            # Random change saturation of the image
            Operations.RandomColor(probability=0.5,
                                   min_factor=0.5,
                                   max_factor=1.5),
            # Random change saturation of the image
            Operations.RandomContrast(probability=0.5,
                                      min_factor=0.5,
                                      max_factor=1.5),
            # Random crops
            Operations.CropPercentage(probability=0.5,
                                      percentage_area=0.85,
                                      centre=center,
                                      randomise_percentage_area=True),
            # Resize the image to the desired input size
            Operations.Resize(probability=resize_prob,
                              width=input_size[0],
                              height=input_size[1],
                              resample_filter="BICUBIC")
        ],
        # GROUP 3 (Perspective transformations)
        [
            # Rotate the image by 90 degrees randomly
            Operations.Rotate(probability=0.5, rotation=-1),
            # Flip top/bottom
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="TOP_BOTTOM"),
            # Flip left/right
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="LEFT_RIGHT"),
            # Shear Image
            Operations.Shear(probability=0.5,
                             max_shear_left=20,
                             max_shear_right=20),
            # Random Tilt up down
            Operations.Skew(probability=0.5,
                            skew_type="TILT_TOP_BOTTOM",
                            magnitude=1.0),
            # Random Tilt left right
            Operations.Skew(probability=0.5,
                            skew_type="TILT_LEFT_RIGHT",
                            magnitude=1.0),
            # Random Skew CORNER
            Operations.Skew(probability=0.5, skew_type="CORNER",
                            magnitude=1.3),
            # Random crops
            Operations.CropPercentage(probability=0.5,
                                      percentage_area=0.85,
                                      centre=center,
                                      randomise_percentage_area=True),
            # Resize the image to the desired input size
            Operations.Resize(probability=resize_prob,
                              width=input_size[0],
                              height=input_size[1],
                              resample_filter="BICUBIC")
        ],
        # GROUP 4 (Noise transformations)
        [
            # Center crop
            CropCenter(probability=1),
            # Rotate the image by 90 degrees randomly
            Operations.Rotate(probability=0.5, rotation=-1),
            # Flip top/bottom
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="TOP_BOTTOM"),
            # Flip left/right
            Operations.Flip(probability=0.5,
                            top_bottom_left_right="LEFT_RIGHT"),
            # Random distortions
            Operations.Distort(probability=0.5,
                               grid_width=8,
                               grid_height=8,
                               magnitude=15),
            # Random erasing
            Operations.RandomErasing(probability=0.5, rectangle_area=0.25),
            # Random crops
            Operations.CropPercentage(probability=0.5,
                                      percentage_area=0.85,
                                      centre=center,
                                      randomise_percentage_area=True),
            # Resize the image to the desired input size
            Operations.Resize(probability=resize_prob,
                              width=input_size[0],
                              height=input_size[1],
                              resample_filter="BICUBIC")
        ]
    ]

    return DATA_AUGMENTATION_GROUPS[data_aug_group]