def random_rotation(x, rg, row_axis=1, col_axis=2, channel_axis=0, fill_mode='nearest', cval=0.0):
 theta = ((np.pi / 180) * np.random.uniform((- rg), rg))
 rotation_matrix = np.array([[np.cos(theta), (- np.sin(theta)), 0], [np.sin(theta), np.cos(theta), 0], [0, 0, 1]])
 (h, w) = (x.shape[row_axis], x.shape[col_axis])
 transform_matrix = transform_matrix_offset_center(rotation_matrix, h, w)
 x = apply_transform(x, transform_matrix, channel_axis, fill_mode, cval)
 return x

def random_rotation ( x , rg , row_axis = 1 , col_axis = 2 , channel_axis = 0 , fill_mode = 'nearest' , cval = 0.0 ) : theta = ( ( np . pi / 180 ) * np . random . uniform ( ( - rg ) , rg ) ) rotation_matrix = np . array ( [ [ np . cos ( theta ) , ( - np . sin ( theta ) ) , 0 ] , [ np . sin ( theta ) , np . cos ( theta ) , 0 ] , [ 0 , 0 , 1 ] ] ) ( h , w ) = ( x . shape [ row_axis ] , x . shape [ col_axis ] ) transform_matrix = transform_matrix_offset_center ( rotation_matrix , h , w ) x = apply_transform ( x , transform_matrix , channel_axis , fill_mode , cval ) return x
performs a random rotation of a numpy image tensor .