Perform any of 8 permutations of 90-degrees rotations or flips for image x.

def dihedral(x, dih):
    """ Perform any of 8 permutations of 90-degrees rotations or flips for image x. """
    x = np.rot90(x, dih%4)
    return x if dih<4 else np.fliplr(x)