将 1D 径向轮廓转换为 2D 图像

Nem*_*sis 3 python image python-2.7

如何将一维矢量 f(r) 转换为具有对称旋转的图像。我正在使用 python 2.7。

我想用一个人物做什么。我想要右侧的图像,左侧的矢量:

非常感谢。

arm*_*ita 5

您可以构建一个中心为零的距离矩阵,并将其绘制为您想要的任何函数的参数:

import numpy as np
import matplotlib.pyplot as plt

def centeredDistanceMatrix(n):
    # make sure n is odd
    x,y = np.meshgrid(range(n),range(n))
    return np.sqrt((x-(n/2)+1)**2+(y-(n/2)+1)**2)

def function(d):
    return np.log(d) # or any function you might have

d = centeredDistanceMatrix(101)
f = function(d)
plt.plot(np.arange(51),function(np.arange(51)))
plt.show()
plt.imshow(f.T,origin='lower',interpolation='nearest')
plt.show()
Run Code Online (Sandbox Code Playgroud)

,结果是:

数字日志

, 和:

二维数字日志

编辑:对于任意数据。

您可以使用interp1D将向量传递给函数来给出像素值。

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

def centeredDistanceMatrix(n):
    # make sure n is odd
    x,y = np.meshgrid(range(n),range(n))
    return np.sqrt((x-(n/2)+1)**2+(y-(n/2)+1)**2)

def function(d):
    return np.log(d) # or any funciton you might have

def arbitraryfunction(d,y,n):
    x = np.arange(n) 
    f = interp1d(x, y)
    return f(d.flat).reshape(d.shape)

n = 101
d = centeredDistanceMatrix(n)
y = np.random.randint(0,100,n) # this can be your vector
f = arbitraryfunction(d,y,n)
plt.plot(np.arange(101),arbitraryfunction(np.arange(n),y,n))
plt.show()
plt.imshow(f.T,origin='lower',interpolation='nearest')
plt.show()
Run Code Online (Sandbox Code Playgroud)

,结果是这样的:

任意一维数据

, 和这个:

任意数据的革命