def rotation(x, rg=20, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0.0):
 if is_random:
  theta = ((np.pi / 180) * np.random.uniform((- rg), rg))
 else:
  theta = ((np.pi / 180) * 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_index], x.shape[col_index])
 transform_matrix = transform_matrix_offset_center(rotation_matrix, h, w)
 x = apply_transform(x, transform_matrix, channel_index, fill_mode, cval)
 return x

def rotation ( x , rg = 20 , is_random = False , row_index = 0 , col_index = 1 , channel_index = 2 , fill_mode = 'nearest' , cval = 0.0 ) : if is_random : theta = ( ( np . pi / 180 ) * np . random . uniform ( ( - rg ) , rg ) ) else : theta = ( ( np . pi / 180 ) * 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_index ] , x . shape [ col_index ] ) transform_matrix = transform_matrix_offset_center ( rotation_matrix , h , w ) x = apply_transform ( x , transform_matrix , channel_index , fill_mode , cval ) return x
rotate an image randomly or non-randomly .