scipyのダウンロードUPDATEで3Dボリュームをリサンプリング:変換およびnumpyの/
私はよくノートipython文書を作成しました。 コードだけが必要な場合は、最初の回答を見てください。私はグレースケール値の40x40x40ボリュームを持っている
質問
。 これは回転/シフト/せん断する必要があります。ここで
は均質変換の便利なコレクションです:http://www.lfd.uci.edu/~gohlke/code/transformations.py.html
私は(位置ベクトル、値)のペアのように私ボリューム内のすべてのボクセルを処理する必要があります。 それから私は、変換されたベクトルのセットから各座標の位置とサンプルの新しい値を変換します。
サンプリングはかなり難しいようだ、と私はこれを見つけてうれしかった: https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.ndimage.affine_transform.html#scipy.ndimage.affine_transform
The given matrix and offset are used to find for each point in the output the corresponding coordinates in the input by an affine transformation. The value of the input at those coordinates is determined by spline interpolation of the requested order. Points outside the boundaries of the input are filled according to the given mode.
は完璧ですね。
しかし、使い方は非常に難しいです。 Here誰かがそのコードを画像の回転に使用しています。 彼の回転行列は2x2なので、それは均質な座標ではありません。 Iは、関数に均質座標(2D)の並進マトリックスを通過しようとした:
dim =10
arr=np.zeros((dim,dim))
arr[0,0]=1
mat=np.array([[1,0,1],[0,1,0],[0,0,1]])
out3=scipy.ndimage.affine_transform(arr,mat)
print("out3: ",out3)
エラーを生成する:
Traceback (most recent call last):
File "C:/Users/212590884/PycharmProjects/3DAugmentation/main.py", line 32, in <module>
out3=scipy.ndimage.affine_transform(arr,mat)
File "C:\Users\212590884\AppData\Local\Continuum\Anaconda2\lib\site-packages\scipy\ndimage\interpolation.py", line 417, in affine_transform
raise RuntimeError('affine matrix has wrong number of rows')
RuntimeError: affine matrix has wrong number of rows
明らかに、これは同次座標で動作しません。 これを使ってデータをシフトするにはどうすればよいですか?
そして、これは単なる2Dにあったが、3Dで私もボリューム回転することができない。
dim =10
arr=np.zeros((dim,dim,dim))
arr[0,0]=1
angle=10/180*np.pi
c=np.cos(angle)
s=np.sin(angle)
mat=np.array([[c,-s,0,0],[s,c,0,0],[0,0,1,0],[0,0,0,1]])
out3=scipy.ndimage.affine_transform(arr,mat)
print("out3: ",out3)
をエラーメッセージは同じです:affine matrix has wrong number of rows
は、変換するために、このメソッドを使用することが可能です私のボリューム?
私は、彼らがシフトを提供し、回転させますが、せん断ない、ヘルパーメソッドのコレクションが見つかりました: https://docs.scipy.org/doc/scipy-0.14.0/reference/ndimage.html
しかし、私は、カスタム変換行列を使用することを好むだろう。私は別のオプション見つけた
私は、(y、x、z)である(r、c、z)規則のために奇妙な振る舞いがあると思うので、x座標上で回転する対応するベクトルは(0,1,0) – Ariel