How to generate a rotationally symmetric function with a 1d array in python?

Viewed 328

I have a 1D array and I want to rotate it around its centre to generate a symmetric 2D array. How can I do it? For example, I define a 1D window array via scipy and now I want to generate its 2D version which has rotation symmetry. However, the result of numpy.outer doesn't have rotation symmetry.

from scipy.signal import windows
import matplotlib.pyplot as plt
exp1 = windows.get_window(('exponential', None, 5), 60)
exp2d = np.sqrt(np.outer(exp1, exp1))
plt.imshow(exp2d)

enter image description here

I realize that if the 1D window has a analytical form, it is simple to do it. However, is there some general method for an arbitrary 1D array (function) without analytical form?

1 Answers

Yes, this can be done. Here is a possible approach:

  1. Generate a "radius" image like this, where at each point, the pixel value is its distance from the center:

    radius image

  2. Evaluate f(radius), where f is any 1D function. For instance:

    enter image description here

    Alternatively, if you have a 1D array and not a function, interpolate it for instance with scipy.interpolate.interp1d like f = interpolate.interp1d(x, y).

Related