6

我正在研究环的强度如何随角度变化。这是一个图像示例:

在此处输入图像描述

我想做的是从那个甜甜圈的中心取一圈值,然后绘制它们与角度的关系。我目前正在做的是使用 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]

但是,我认为这并不是我真正想要的。我主要为如何提取我想要的数据而苦苦挣扎。我也尝试过使用看起来像这样的面具;

在此处输入图像描述

到图像,但后来我不知道如何以正确的顺序获取该掩码中的值(即按增加角度 0 - 2pi 的顺序)

任何其他想法都会有很大帮助!

4

1 回答 1

3

我制作了一个不同的输入图像来帮助验证正确性:

import numpy as np
import scipy as sp
import scipy.interpolate
import matplotlib.pyplot as plt

# Mock up an image.
W = 100
x = np.arange(W)
y = np.arange(W)
xx,yy = np.meshgrid(x,y)

image = xx//5*5 + yy//5*5
image = image / np.max(image)  # scale into [0,1]

plt.imshow(image, interpolation='nearest', cmap='gray')
plt.show()

备用输入图像

为了从图像中的圆形路径中采样值,我们首先构建一个插值器,因为我们想要访问任意位置。我们还对其进行矢量化以更快。
然后,我们N使用圆的参数定义生成圆圆周上点的坐标x(t) = sin(t), y(t) = cos(t)
N应该至少是圆周的两倍(奈奎斯特-香农采样定理)。

interp = sp.interpolate.interp2d(x, y, image)
vinterp = np.vectorize(interp)

for r in (15, 30, 45):    # radii for circles around image's center
    xcenter = len(x)/2
    ycenter = len(y)/2
    arclen = 2*np.pi*r
    angle = np.linspace(0, 2*np.pi, arclen*2, endpoint=False)
    value = vinterp(xcenter + r*np.sin(angle),
                    ycenter + r*np.cos(angle))
    plt.plot(angle, value, label='r={}'.format(r))

plt.legend()
plt.show()

从中心采样的圆圈。

于 2016-04-14T16:54:45.497 回答