Exemple #1
0
def __apply_transformation(image, generator: ImageDataGenerator):
    # Turn the read image into colour so that the ImageDataGenerator can apply its transformation. Then return the
    # image gray-scaled

    coloured_image = cv.cvtColor(
        image,
        cv.COLOR_GRAY2RGB)  # Transform the gray-scaled image into colour
    transformed_image = generator.random_transform(
        coloured_image)  # Transform the image with the ImageDataGenerator
    gray_scaled_image = cv.cvtColor(
        transformed_image,
        cv.COLOR_RGB2GRAY)  # Revert the coloured image back to grey

    return gray_scaled_image
Exemple #2
0
def imageAugmentation(image):
    seed = int(random() * 100000000)
    wShift = 5
    hShift = 5
    # rotation is changing values of image
    imgen = ImageDataGenerator(rotation_range=365,
                               width_shift_range=wShift,
                               height_shift_range=hShift,
                               horizontal_flip=True,
                               vertical_flip=True,
                               fill_mode='constant',
                               cval=0)
    image = imgen.random_transform(image, seed)
    return image