arb*_*dge 6 python arrays analysis slice radial
我正在研究环的强度如何根据角度而变化.这是一个图像的示例:
我想做的是从该甜甜圈的中心取一圈值并绘制它们与角度的关系.我目前正在做的是使用scipy.ndimage.interpolation.rotate并通过环径向切片,并提取两个峰的最大值并绘制那些与角度的关系.
crop = np.ones((width,width)) #this is my image
slices = np.arange(0,width,1)
stack = np.zeros((2*width,len(slices)))
angles = np.linspace(0,2*np.pi,len(crop2))
for j in range(len(slices2)): # take slices
stack[:,j] = rotate(crop,slices[j],reshape=False)[:,width]
Run Code Online (Sandbox Code Playgroud)
但是我认为这不是我正在寻找的东西.我主要是如何提取我想要的数据.我也试过应用一个看起来像这样的面具;
到图像,但后来我不知道如何以正确的顺序获取该掩码内的值(即按照增加角度0 - 2pi的顺序)
任何其他想法都会有很大的帮助!
我制作了不同的输入图像来帮助验证正确性:
\n\nimport numpy as np\nimport scipy as sp\nimport scipy.interpolate\nimport matplotlib.pyplot as plt\n\n# Mock up an image.\nW = 100\nx = np.arange(W)\ny = np.arange(W)\nxx,yy = np.meshgrid(x,y)\n\nimage = xx//5*5 + yy//5*5\nimage = image / np.max(image) # scale into [0,1]\n\nplt.imshow(image, interpolation=\'nearest\', cmap=\'gray\')\nplt.show()\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n为了从图像中的圆形路径采样值,我们首先构建一个插值器,因为我们想要访问任意位置。我们还将其矢量化以使其更快。\n然后,我们使用圆的参数定义生成圆圆周上点
的坐标。\n应至少是周长的两倍(奈奎斯特\xe2\x80\x93香农采样定理)。Nx(t) = sin(t), y(t) = cos(t)N
interp = sp.interpolate.interp2d(x, y, image)\nvinterp = np.vectorize(interp)\n\nfor r in (15, 30, 45): # radii for circles around image\'s center\n xcenter = len(x)/2\n ycenter = len(y)/2\n arclen = 2*np.pi*r\n angle = np.linspace(0, 2*np.pi, arclen*2, endpoint=False)\n value = vinterp(xcenter + r*np.sin(angle),\n ycenter + r*np.cos(angle))\n plt.plot(angle, value, label=\'r={}\'.format(r))\n\nplt.legend()\nplt.show()\nRun Code Online (Sandbox Code Playgroud)\n\n\n
| 归档时间: |
|
| 查看次数: |
1020 次 |
| 最近记录: |