< Tensorflow >Tensorflow Data Augmentation affine transformation

Method

This method augment image by changing image through affine transformation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def transform_perspective(image):
def x_y_1():
x = tf.random_uniform([], minval=-0.3, maxval=-0.15)
y = tf.random_uniform([], minval=-0.3, maxval=-0.15)
return x, y

def x_y_2():
x = tf.random_uniform([], minval=0.15, maxval=0.3)
y = tf.random_uniform([], minval=0.15, maxval=0.3)
return x, y

def trans(image):
ran = tf.random_uniform([])
x = tf.random_uniform([], minval=-0.3, maxval=0.3)
x_com = tf.random_uniform([], minval=1-x-0.1, maxval=1-x+0.1)

y = tf.random_uniform([], minval=-0.3, maxval=0.3)
y_com = tf.random_uniform([], minval=1-y-0.1, maxval=1-y+0.1)

transforms = [x_com, x,0,y,y_com,0,0.00,0]

ran = tf.random_uniform([])
image = tf.cond(ran<0.5, lambda:tf.contrib.image.transform(image,transforms,interpolation='NEAREST', name=None),
lambda:tf.contrib.image.transform(image,transforms,interpolation='BILINEAR', name=None))
return image

ran = tf.random_uniform([])
image = tf.cond(ran<1, lambda: trans(image), lambda:image)

return image

This images below are origin image and augmented images:



< Tensorflow >Tensorflow Data Augmentation affine transformation

https://zhengtq.github.io/2018/12/20/tf-tur-perspective-transform/

Author

Billy

Posted on

2018-12-20

Updated on

2021-03-13

Licensed under

Comments