私はPython2.7で3D numpy配列を使って作業しており、2D傾きのディスクにあるピクセルだけを取得しようとしています。ある傾斜したディスクで3D数値配列をマスキングする
:ここ
ディスク(=円)の境界線をプロットする私のコードで私は
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#creating a 3d numpy array (empty in this example, but will represent a binary 3D image in my application)
space=np.zeros((40,40,20))
r = 8 #radius of the circle
theta = np.pi/4 # "tilt" of the circle
phirange = np.linspace(0, 2 * np.pi) #to make a full circle
#center of the circle
center=[20,20,10]
#computing the values of the circle in spherical coordinates and converting them
#back to cartesian
for phi in phirange:
x = r * np.cos(theta) * np.cos(phi) + center[0]
y= r*np.sin(phi) + center[1]
z= r*np.sin(theta)* np.cos(phi) + center[2]
space[int(round(x)),int(round(y)),int(round(z))]=1
x,y,z = space.nonzero()
#plotting
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, zdir='z', c= 'red')
plt.show()
にプロットは、以下の図を与える興味を持っています良いスタートですが、円で定義されたディスクにあるspace
のピクセルの値だけを取得する方法が必要です。次の画像のピンクゾーンにあるもの(私のアプリケーションでは、space
は)3Dバイナリイメージで、ここではそれだけでプロットし、あなたに私がしたいディスクを表示できるようにする)numpy.zeros(です:
私はprocede必要がありますか? 私はいくつかのマジックが関与していると思いますが、私はあなたが2Dでそれをやる方法を理解しています(this questionのように)が、これを3Dに適用するのに問題があります。
「落ちる」とはどういう意味ですか?ピクセルがポイントの場合は、円の内側だけでなく、平面と交差するという保証はありません。代わりに高さ1のシリンダーを見たいと思っていますか? – Eric
はい、私は知っている、近似との作業はこのアプリケーションでは問題ありません。従って、私が示すコードのround()は、図の点は近似的に円上にあります。私は、これは1ピクセルの高さのシリンダでポイントを探すことと同等であると言うことができると思います。 – Soltius