2016-04-14 11 views
6

角度によってリングの強さがどのように変化するかを調べています。私がやりたい何Pythonのサークルからデータを取る

enter image description here

はそのドーナツの中心部内から値の円を取り、角度対してプロットしたものである。ここでは画像の例があります。私が現在行っているのは、scipy.ndimage.interpolation.rotateを使ってリングを半径方向にスライスし、2つのピークの最大値を抽出し、それらの角度をプロットすることです。

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] 

しかし、これは私が実際に探していることではないと思います。私は、私が望むデータをどのように抽出するのかとほとんど苦労しています。私はまたこのようなマスクを適用しようとしました。

画像へ

enter image description here

、その後私は、正しい順序で、マスク内の値を取得する方法がわからない(すなわち角度0増加のために - 。2PI)を

その他アイデアは大きな助けになるでしょう!

答えて

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() 

Alternate input image

を、我々は最初のインターポレータを構築し、我々は、任意の場所にアクセスしたいので。私たちはまたそれをより高速にベクトル化します。
次に円のパラメトリック定義x(t) = sin(t), y(t) = cos(t)を使用して円の円周上に座標Nの座標を生成します。
Nは、円周の少なくとも2倍(ナイキストシャノンサンプリング定理)でなければなりません。

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() 

Circles sampled from center.

+0

こんにちは、答えるために感謝そんなに。コードはすばらしく見えますが、私がラインを外すときは、ここにいるものが得られます。 image = image/np.amax(画像) それはいつものように動作するようです!もしそうでなければ、私はオリジナルの画像が完全に黒くなってしまい、右下の小さな1つの小さな正方形から終わります。 私はscipy interp2dの仕組みについて少し混乱しています - scipy.miscのimread関数を使ってイメージをインポートするので、interp2dの必要なx yとz入力に分割する方法がわかりませんか? – arbitraryknowledge

+1

ああ、私はPython3のコードを書いて、あなたはPython 2.7を持っていますよね? 'image = image * 1.0/np.max(image)'を試してください。また、 'xcenter = 0.5 * len(x) 'などに変更します。これは[整数除算](http://stackoverflow.com/q/21316968/1292641)のためです。 – Norman

+1

'imread()からのあなたのイメージはndarrayです。 'h、w = image.shape;を試してください。 sp.interpolate.interp2d(np.arange(w)、np.arange(h)、image) '。 – Norman

関連する問題