ANTs (Advanced Normalization Tools)は、近年注目されている脳画像解析ツールです。性能が高いのですが、導入方法などが親切に説明されていません。macOSへのインストール方法を説明します。
2021.01.02: Homebrewを使えばcmakeが入れられるので、そちらに情報を更新しました。また、インストールスクリプトを公開しました。
こちら(右クリックで保存)からダウンロードしてください。Downloadsフォルダにダウンロードしたと仮定しますと、以下でインストールできます。コンパイルにしばらく時間がかかりますので30分くらいかかると思ってください。
1 2 3 | cd ~ /Downloads chmod 755 ANTs_installer_macOS.sh . /ANTs_installer_macOS .sh |
開発者によるHow-toはこちらに記載されています。
以下、詳しい説明です。
- 事前に必要なソフトウェア
- CMake
- command line tools
- CMakeのインストール
- Homebrewを使う場合
- 公式サイトで配布されているCMakeを使う場合
- CMakeのパス設定
- command line toolsのインストール
- フォルダの準備
- ANTsのソースコードの入手
- コンパイル
- インストール
- パスの設定
- ANTsのアップデート
以下の2つが必要です。
Homebrewを使えば、一発で入れられます。
1 | brew install cmake |
パスの設定なども不要なので、こちらがおすすめです。
公式サイトで、MacOSX用のインストーラーが配布されています。
http://www.cmake.org/download/に行き、cmake-3.x.x-Darwin-x86_64.dmgをダウンロードします。そして、その後、ファイルをダブルクリックすると、CMake.appが見えますので、Applicationsアイコンにドラッグ&ドロップすれば、完了です。2020年2月現在、ANTsは3.10.2以降であればインストールできるとのことです。
ただ、これだけだと、普通に開こうとすると「セキュリティの問題で開けません」と言われます。そこで、アプリケーションフォルダで、controlを押しながら、CMakeをクリックします。そうして、一番上にある「開く」をクリックすると、「開いてもいいですか?」と尋ねられますので、はいと答えれば、OKです。
次に、CMakeをターミナルから利用できるように設定します。
ターミナルを開き、.bash_profileを開きます。
そこで、次のようにタイプします。
1 2 | open -e .bash_profile |
すると、.bash_profileが立ち上がりますので、そこの一番下に以下の内容を記載します。
1 2 | #CMake PATH=/Applications/CMake.app/Contents/bin:$PATH |
これを保存してテキストエディットを閉じます。ターミナルを一度終了し、再度起動します。
パスがきちんと通っているか確認するために、以下をタイプします。
1 | echo $PATH |
一番最初に/Applications/CMake.app/Contents/binが確認できればOKです。
最初に、App StoreからXcodeをインストールします。
その後、ターミナルを立ち上げ、以下をタイプします。
1 | xcode- select -- install |
そうすると、インストールしますか?と聞かれますので、”Install”をクリックすればインストール完了です。
いよいよ本題に入っていきます。
ANTsを準備するためのフォルダを準備しましょう。ホームフォルダの下にANTSを作成します。そのうえで、その中に build と install というフォルダを準備します。
1 2 3 4 | cd mkdir ANTS cd ANTS mkdir build install |
gitでソースコードを入手します。
ANTsというフォルダにソースコードが入ります。
1 2 3 | pwd #今は、~/ANTS にいると仮定します。 workingDir=${PWD} git clone https: //github .com /ANTsX/ANTs .git |
早速コンパイルに入ります。
先程作成した build ディレクトリに移動し、そこでコンパイルを行います。
ターミナルから次のコマンドをタイプします。
下の make -j 4 の4はコア数です。自分のPC環境にあわせて変えてください。
1 2 3 4 5 | cd build cmake \ -DCMAKE_INSTALL_PREFIX=${workingDir} /install \ .. /ANTs 2>&1 | tee cmake.log make -j 4 2>&1 | tee build.log |
そうすると、以下のような画面になります。ITKをダウンロードなどします。私の場合、ここだけでだいたい20-30分くらいかかりました。ネットワークの遅い早いもあるかもしれませんが、じっと待ちます。
忍耐の結果、下記の画面のように、”Completed: ANTs”と出れば、無事にコンパイル完了です。
インストールを行います。先程作成した install フォルダにインストールされます。
1 2 | cd ANTS-build make install 2>&1 | tee install .log |
最後に、ANTsのパス設定を行います。先ほどと同様、.bash_profileに記載します。
1 2 | open -e ~/.bash_profile |
すると、.bash_profileが立ち上がりますので、そこの一番下に以下の内容を記載します。
今、ANTsの実行ファイルは、~/ANTS/installにあります。
1 2 3 | #ANTs export ANTSPATH=~/ANTS/install/bin export PATH=$PATH:$ANTSPATH |
これを保存し、終了し、ターミナルを一度閉じて再度開きます。
ANTsのパスが通っているかどうかを確認するには、以下をタイプします。
1 2 | which antsRegistration antsRegistrationSyN.sh |
最初のコマンドで
自分のホームディレクトリ/ANTS/install/bin/antsRegistration
となり、
次のコマンドで、antsRegistrationSyN.sh の説明がでれば正しくセットアップできています。
今後、ANTsがアップデートされた場合、以下のようにすればよいとのことです。
1 2 | cd ~ /ANTS/ANTs git pull origin master |
これで、ANTsの中身が最新になりますので、再度コンパイルという形になります。
お世話になっております。
mac native環境下でインストラクション通りにANTSをインストールしました。
ところが、以下のようなエラーメッセージが出てしまい、antsRegistrationした画像が出力されませんでした。
MacbookPro(M2 Max)を使用しているのですが、M2 Chipが原因ということでしょうか?
何か解決方法があれば教えていただけますと幸いです。
どうぞ宜しくお願い致します。
*** Running B-spline SyN registration (updateMeshSizeAtBaseLevel = [10, 10, 7], totalMeshSizeAtBaseLevel = [4294967295, 4294967295, 4294967295]) ***
Exception caught:
itk::ExceptionObject (0x600001234080)
Location: “unknown”
File: /Users/toga/ANTS/build/staging/include/ITK-5.4/itkBSplineScatteredDataPointSetToImageFilter.hxx
Line: 223
Description: ITK ERROR: BSplineScatteredDataPointSetToImageFilter(0x110e0aa80): The number of control points must be greater than the spline order.
私が M2 chip を持っていないので原因究明は難しいのですが、とりあえず、私の方で M1 でコンパイルした ANTs を試してみていただけませんでしょうか。
http://www.lin4neuro.net/lin4neuro/neuroimaging_software_packages/ANTS/ANTS_arm64.zip
去年の11月にコンパイルしたものなので、そこまで古くないです。
コンパイルしたデータを送ってくださりありがとうございます。
open -e ~/.zprofile
__
以下を最後の2行に挿入しました。
# ANTs
export ANTSPATH=/Users/toga/ANTS/bin
export PATH=$PATH:$ANTSPATH
__
以下も確認しました。
toga@togaMacBook-Pro ~ % which antsRegistration
/Users/toga/ANTS/install/bin/antsRegistration
___
N4BiasFieldCorrection 、ResampleImage、 DenoiseImageまではうまくできたのですが、antsRegistrationはやはり以下のエラーメッセージが出てしまいました。
何か解決策はありますでしょうか?
*** Running B-spline SyN registration (updateMeshSizeAtBaseLevel = [10, 10, 7], totalMeshSizeAtBaseLevel = [4294967295, 4294967295, 4294967295]) ***
Exception caught:
itk::ExceptionObject (0x6000036da600)
Location: “unknown”
File: /Users/kiyotaka/ANTS/build/staging/include/ITK-5.3/itkBSplineScatteredDataPointSetToImageFilter.hxx
Line: 223
Description: ITK ERROR: BSplineScatteredDataPointSetToImageFilter(0x129406aa0): The number of control points must be greater than the spline order.
Registration finished. The antsRegistration call was:
————————————————————————————–
/Users/toga/ANTS/install/bin/antsRegistration –verbose 1 –dimensionality 3 –float 0 –collapse-output-transforms 1 –output [ move_,move_Warped.nii.gz,move_InverseWarped.nii.gz ] –interpolation Linear –use-histogram-matching 0 –winsorize-image-intensities [ 0.005,0.995 ] –initial-moving-transform [ drnT1.nii,standard_T1.nii,1 ] –transform Rigid[ 0.1 ] –metric MI[ drnT1.nii,standard_T1.nii,1,32,Regular,0.25 ] –convergence [ 1000x500x250x100,1e-6,10 ] –shrink-factors 8x4x2x1 –smoothing-sigmas 3x2x1x0vox –transform Affine[ 0.1 ] –metric MI[ drnT1.nii,standard_T1.nii,1,32,Regular,0.25 ] –convergence [ 1000x500x250x100,1e-6,10 ] –shrink-factors 8x4x2x1 –smoothing-sigmas 3x2x1x0vox –transform BSplineSyN[ 0.1,26,0,3 ] –metric CC[ drnT1.nii,standard_T1.nii,1,4 ] –convergence [ 100x70x50x20,1e-6,10 ] –shrink-factors 8x4x2x1 –smoothing-sigmas 3x2x1x0vox
————————————————————————————–
Moving image resampled into fixed space: move_Warped.nii.gz
Fixed image resampled into moving space: move_InverseWarped.nii.gz
Apple M1でコンパイルしたものがApple M2で同じエラーが出るということは、Apple M2に起因する何かがあるということですね。
今、検索してみたら、ちょうどGitHubでissueをたててくださったようなので、そこで確認ということになるでしょうか。
ありがとうございます。
-t bではなく-t sであればうまく画像出力されました。
antsRegistrationSyN.sh -d 3 -f drnT1.nii -m standard_T1.nii -o move_ -n 32 -t s
引き続きGitHubでやりとりをしてみます。
どうぞよろしくお願いします。
そうなんですね。またいろいろわかったら共有していただければ。
進展ありました。
https://github.com/ANTsX/ANTs/issues/1572
https://github.com/ANTsX/ANTs/pull/1575
こちらから再インストールをしてくださいとのことで、実施しましたところ目的のファイルを出力することができました。BUGを修正してくれた?
のかもしれません。
https://github.com/ANTsX/ANTs/wiki/Compiling-ANTs-on-Linux-and-Mac-OS
よかったです。バグを修正してくれたのですね。解決ですね。
.zprofileに記載したところ、解決しました!
大変助かりました。
ありがとうございます。
無事解決してよかったです。
zshを使われるようでしたら、設定を全部 .zprofile に書く事を覚えておいていただけたら。
承知しました、そのようにします。
ありがとうございます。
ちなみに
ターミナルから
bash
とタイプして、bashを起動して、
ANTS
とやると、ANTSがきちんと起動すると思いますよ。この設定は、.bash_profileの設定を読み込んでいます。
脳画像解析を始めるにあたりいつも参考にさせていただいております。MacOSでANTsを使用し脳画像解析に挑戦しようと思いANTsのインストールを行ったのですが、PAHTの設定がうまくいきませんでした。
.bash_profileに/usr/local/ANTs/bin/を設定し、echo $PATHで確認出来たのですが、which antsRegistrationでnot foundとなってしいます。何か解決策ありましたらご教授お願いいたします。
すみません、なぜだかスパムに分類されてしまっていて確認が遅くなりました。
– パスを設定した後、ターミナルを再起動する必要がありますが、そちらはされましたか?
– お使いのターミナルではbash, zshのどちらが動いていますか?
– which antsRegistrationSyN.sh の結果はどうなりますか?
– /usr/local/ANTsにインストールされたのですか?
根本清貴
お世話になります。
Macnative(AppleM2)インストールを試みましたが、パス設定がうまくいかなようです。
open -e ~/.bash_profile
入力すると以下の.bash_profileが表示されます。
#CMake
PATH=/Applications/CMake.app/Contents/bin:$PATH
#ANTs
export ANTSPATH=~/ANTS/install/bin
export PATH=$PATH:$ANTSPATH
_________________
ターミナルを閉じ、再度開いて入力したところ以下となってしまいました。
which antsRegistration
antsRegistrationSyN.sh
antsRegistration not found
zsh: command not found: antsRegistrationSyN.sh
どのように対応すればよいでしょうか?
どうぞ宜しくお願いします。
~
/ANTS/install/bin/antsRegistrationSyN
.sh
としていただいたらどうなりますか?
以下のようなメッセージがでました。
————————————————————————————–
Error locating ANTS
————————————————————————————–
It seems that the ANTSPATH environment variable is not set. Please add the ANTSPATH
variable. This can be achieved by editing the .bash_profile in the home directory.
Add:
ANTSPATH=/home/yourname/bin/ants/
Or the correct location of the ANTS binaries.
Alternatively, edit this script ( antsRegistrationSyN.sh ) to set up this parameter correctly.
了解です。
そうしましたら、.bash_profileの中の
export
ANTSPATH=~
/ANTS/install/bin
を
export
ANTSPATH=$HMOE
/ANTS/install/bin
と、~ を $HOME に置き換えていただけますか。
それでターミナルを起動して改めて
which
antsRegistration
とやってみてください。
推測ですが、チルダが悪さしている気がします。
ご連絡ありがとうございます。
置き換えてみましたがうまくいきませんでした。
which antsRegistration
antsRegistration not found
find
$HOME -name
'antsRegistration'
の結果はどうなりますか?
おそらく、パスが何か違っているのではないかと思うので、antsRegistrationが入っているパスがどこかを確認したいです。
以下のようになりました。いかがでしょうか?
akira@AkiranoMacBook-Air ~ % find $HOME -name ‘antsRegistration’
/Users/akira/ANTS/install/bin/antsRegistration
/Users/akira/ANTS/build/ANTS-build/Examples/antsRegistration
find: /Users/akira/Library/Application Support/CallHistoryTransactions: Operation not permitted
find: /Users/akira/Library/Application Support/CloudDocs/session/db: Operation not permitted
find: /Users/akira/Library/Application Support/com.apple.sharedfilelist: Operation not permitted
find: /Users/akira/Library/Application Support/Knowledge: Operation not permitted
find: /Users/akira/Library/Application Support/com.apple.TCC: Operation not permitted
find: /Users/akira/Library/Application Support/FileProvider: Operation not permitted
find: /Users/akira/Library/Application Support/FaceTime: Operation not permitted
find: /Users/akira/Library/Application Support/com.apple.avfoundation/Frecents: Operation not permitted
find: /Users/akira/Library/Application Support/CallHistoryDB: Operation not permitted
find: /Users/akira/Library/Assistant/SiriVocabulary: Operation not permitted
find: /Users/akira/Library/Autosave Information: Operation not permitted
find: /Users/akira/Library/IdentityServices: Operation not permitted
find: /Users/akira/Library/Messages: Operation not permitted
find: /Users/akira/Library/HomeKit: Operation not permitted
find: /Users/akira/Library/Sharing: Operation not permitted
find: /Users/akira/Library/com.apple.aiml.instrumentation: Operation not permitted
find: /Users/akira/Library/Mail: Operation not permitted
find: /Users/akira/Library/Trial: Operation not permitted
find: /Users/akira/Library/AppleMediaServices: Operation not permitted
find: /Users/akira/Library/DuetExpertCenter: Operation not permitted
find: /Users/akira/Library/Accounts: Operation not permitted
find: /Users/akira/Library/Safari: Operation not permitted
find: /Users/akira/Library/Biome: Operation not permitted
find: /Users/akira/Library/IntelligencePlatform: Operation not permitted
find: /Users/akira/Library/Suggestions: Operation not permitted
find: /Users/akira/Library/Weather: Operation not permitted
find: /Users/akira/Library/Group Containers/group.com.apple.secure-control-center-preferences: Operation not permitted
find: /Users/akira/Library/Group Containers/group.com.apple.notes: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.archiveutility: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.Maps/Data/Maps: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.Home: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.Safari: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.CloudDocs.MobileDocumentsFileProvider: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.mail: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.Notes: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.corerecents.recentsd/Data/Library/Recents: Operation not permitted
find: /Users/akira/Library/Containers/com.apple.stocks: Operation not permitted
find: /Users/akira/Library/PersonalizationPortrait: Operation not permitted
find: /Users/akira/Library/Metadata/CoreSpotlight: Operation not permitted
find: /Users/akira/Library/Cookies: Operation not permitted
find: /Users/akira/Library/CoreFollowUp: Operation not permitted
find: /Users/akira/Library/StatusKit: Operation not permitted
find: /Users/akira/Library/DoNotDisturb: Operation not permitted
find: /Users/akira/Library/Caches/com.apple.HomeKit: Operation not permitted
find: /Users/akira/Library/Caches/CloudKit: Operation not permitted
find: /Users/akira/Library/Caches/FamilyCircle: Operation not permitted
find: /Users/akira/Library/Caches/com.apple.homed: Operation not permitted
find: /Users/akira/Library/Caches/com.apple.ap.adprivacyd: Operation not permitted
find: /Users/akira/.Trash: Operation not permitted
/Users/akira/ANTS/install/bin/antsRegistration
ここにあることがわかりましたので、
.bash_profile の中のANTSの設定を
export
ANTSPATH=
/Users/akira/ANTS/install/bin
export
PATH=$PATH:$ANTSPATH
と書き換えて、保存し、
ターミナルを一度終了し、そして、ターミナルを再度起動されたうえで、
ANTS
としてみていただけませんか?
これで、
call ANTS -h or ANTS --help
と出力されることが期待されます。
さらに
antsRegistration
とすれば
COMMAND:
antsRegistration
This program is a user-level registration application meant to utilize classes
in ITK v4.0 and later. The user can specify any number of "stages" where a stage
consists of a transform; an image metric; and iterations, shrink factors, and
smoothing sigmas for each level. Note that explicitly setting the
dimensionality, metric, transform, output, convergence, shrink-factors, and
smoothing-sigmas parameters is mandatory.
といった表示になることが期待されます。
.bash_profile の中のANTSの設定を変えましたが、以下のように表示されてしまいました。
akira@AkiranoMacBook-Air ~ % ANTS
zsh: command not found: ANTS
あ、わかりました。
zshをお使いなので、.bash_profileではなく、.zprofileに記載する必要があります。
そちらに書いたら問題なくなると思います。
ピングバック: ANTsのUbuntu 14.04へのインストール方法(ソースからのコンパイル)