Home > Net >  How to perform image augmentation for sequence of images representing a sample
How to perform image augmentation for sequence of images representing a sample

Time:07-12

I want to know how to perform image augmentaion for sequence image data.

The shape of my input to the model looks as below. (None,30,112,112,3) Where 30 is the number of images present in one sample. 112*112 are heigth and width,3 is the number of channels.

Currently I have 17 samples(17,30,112,112,3) which are not enough therefore i want make some sequence image augmentation so that I will have atleast 50 samples as (50,30,112,112,3)

(Note : My data set is not of type video,rather they are in the form of sequence of images captured at every 3 seconds.So,we can say that it is in the form of already extacted frames)

17 samples, each having 30 sequence images are stored in separate folders in a directory. folder_1 folder_2, . . . folder_17

Can you Please let me know the code to perform data augmentation?

CodePudding user response:

Here is an illustration of using enter image description here

# Reading an image using OpenCV
import cv2
img = cv2.imread('flower.jpg')

# Appending images 5 times to a list and convert to an array
images_list = []
for i in range(0,5):
    images_list.append(img)
images_array = np.array(images_list)

The array images_array has shape (5, 133, 200, 3) => (number of images, height, width, number of channels)

Now our input is set. Let's do some augmentation:

# Import 'imgaug' library
import imgaug as ia
import imgaug.augmenters as iaa

# preparing a sequence of functions for augmentation
seq = iaa.Sequential([
    iaa.Fliplr(0.5), 
    iaa.Crop(percent=(0, 0.1)),
    iaa.LinearContrast((0.75, 1.5)),
    iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5),
    iaa.Multiply((0.8, 1.2), per_channel=0.2)
    ],random_order=True)  

enter image description here

enter image description here

enter image description here

You can extend the above for your own problem.

  • Related