0
1

More than 1 year has passed since last update.

CT再構成ライブラリのTomoPyが使えるようになるまで

Last updated at Posted at 2022-02-06

CTのアライメントや再構成法を色々試せるpythonライブラリのTomoPyというののをみつけた。

Anacondaなら簡単そうだが、Anacondaにアレルギーを持っているので、セルフビルドした。
オフィシャルのやり方は、下記にある。
https://tomopy.readthedocs.io/en/latest/devguide.html

なお、等方の環境は以下の通り。
・Ubuntu 20.04
・python 3.8
・cuda 11.3 (RTX3080)

cloning

git clone https://github.com/tomopy/tomopy.git

依存ソフトのインストール&build

乱暴だが、setup.pyを走らせながら必要なのを入れていった--> 失敗
きちんと依存ライブラリを先に入れましょう。
aptでいれたcmakeでは古いらしいので、

sudo apt remove cmake

してから、公式からダウンロード&インストール
cmakeのパスをきちんと通しておくこと。

また、ファイル変換のモジュールdxchangeをいれる。
pipだとかなり古いので、最新を公式に従っていれること。
https://dxchange.readthedocs.io/en/latest/source/install.html

ほかにも、MKL

sudo apt intel-mkl

https://qiita.com/termoshtt/items/6fb0f81c876de3ed1617
(Ryzenにいれても高速化するらしい、、、)

最後に、

cd tomopy
python3 setup.py

当方の環境では、

python3 setup.py install --enable-cuda --enable-nvtx --enable-mkl --cuda-arch 86

としてみた。

install

python3 setup.py install

で行けると思いきや

[Errno 13] Permission denied: '/usr/local/lib/python3.8/dist-packages/test-easy-install-385127.write-test'

ここからしばらく試行錯誤したが、結局rootして入れることに。
但し、rootからはローカルにあるsite-packageが読まれないので、rootに入ってから環境変数PYTHONPATHにきちんと渡しすこと。

また、ローカルとrootでpythonが同じかwhich pythonなどで確かめておくこと。

当方はcsh環境なので、以下のようにした。

sudo su
set path = ($path /home/hogehoge/cmake-path)
setenv PYTHONPATH /home/hogehoge/.local/lib/python3.8/site-packages
python setup.py install
exit

test run

pip install py.test
py.test test/test_tomopy/test_recon/test_rotation.py

とりあえず、お疲れさまでした。

demoscript

https://tomopy.readthedocs.io/en/1.10.1/ipynb/tomopy.html
をやってみる。ただし、等方はjupyterがあんまりわかっていないので、コマンドラインでやってみる。

デモデータtooth.h5をダウンロードし、

cd hogehoge
wget https://tomopy.readthedocs.io/en/1.4.2/_downloads/f2a49e30ca902adc40a6e66950a9b348/tooth.h5

pythonに入って、、

import tomopy
import dxchange
import matplotlib.pyplot as plt

fname = './tooth.h5'

start = 0
end = 2

proj, flat, dark, theta = dxchange.read_aps_32id(fname, sino=(start, end))
plt.imshow(proj[:, 0, :], cmap='Greys_r')
plt.show()


proj = tomopy.normalize(proj, flat, dark)

rot_center = tomopy.find_center(proj, theta, init=290, ind=0, tol=0.5)

proj = tomopy.minus_log(proj)

recon = tomopy.recon(proj, theta, center=rot_center, algorithm='gridrec')
recon = tomopy.circ_mask(recon, axis=0, ratio=0.95)
plt.imshow(recon[0, :,:], cmap='Greys_r')
plt.show()
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1