Mac OSX YosemiteにアップグレードしたらFSLが動かなくなった場合の対処法

私自身も遭遇しましたし、他の方からも問い合わせがありましたので、簡単に記載しておきます。

MacをYosemiteにアップグレードした際に、FSLが動作しなくなることがあります。
その際には、バタバタする前に、まず、XQuartzを再インストールしてみてください。
それだけで問題が解決することがあります。

本家にも情報がありました。

Note for Yosemite (10.10) users: even if you have previously installed X11, you will need to reinstall it from the XQuartz web page to get FSL to work.

これで、問題解決といって大丈夫そうです。

Scripts to convert hdr/img format into nii format

Nifti file havs two kinds of extensions, hdr/img or nii.
Sometimes hdr/file nifti files can be confusing because the extension is the same as ANALYZE format.
There are some ways to convert hdr/img into nifti.
One is to use fslchfiletype included in FSL. This is the easiest, but it requires FSL.
The other is to use SPM. However, some scripting is needed.
So I wrote tiny scripts for converting hdr/img format into nii format.

If you prefer SPM, use img2nii_spm.m. Save the script into a folder under MATLAB path and type “img2nii_spm” from MATLAB command window.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
%%img2nii.m--------------------------------------------
%Script to convert hdr/img files to nii.
%This script uses SPM function, so you need to install SPM5 or later.
%Kiyotaka Nemoto 05-Nov-2014
 
%select files
f = spm_select(Inf,'img$','Select img files to be converted');
 
%convert img files to nii
for i=1:size(f,1)
  input = deblank(f(i,:));
  [pathstr,fname,ext] = fileparts(input);
    output = strcat(fname,'.nii');
    V=spm_vol(input);
    ima=spm_read_vols(V);
    V.fname=output;
    spm_write_vol(V,ima);
end

If you prefer FSL, use img2nii_fsl.sh. Save the script into a folder, add executable attribute using “chmod 755 img2nii_fsl.sh”.
Wild card can be used for selecting files.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
 
#Image file type converter using fslchfiletype
#This script converts various image files into NIFTI format (.nii) files.
#K. Nemoto 19 Jan 2013
 
if [ $# -lt 1 ] ; then
  echo "Please specify the files you want to convert!"
  echo "Usage: $0 filename"
  exit 1
fi
 
for file in "$@" ; do
  if [ -f $file ] ; then
    fslchfiletype NIFTI $file
  else
    echo "$file: No such file"
  fi
done

Download img2nii_spm.m (Right-click and save).
Download img2nii_fsl.sh (Right-click and save).

FSLユーザーのためのシェルスクリプトチュートリアル

FSLを開発しているFMRIBグループは、FSL courseのスライドおよびデータセットを公開してくださっています。ここで勉強しているときに、さりげなくシェルスクリプトのチュートリアルもあることが気になっていました。

先日、時間をとってこのチュートリアルを丁寧に見ていったところ、非常に勉強になることが多く、シェルスクリプトの理解が深まりました。FSLユーザーのみならず、脳画像解析でUNIX系のOS(Macも含む)を使う方々にとって有益な情報が多いと思いましたので、日本語にしておきたいと思い、FMRIBのSteve Smith教授の承諾を得て、このチュートリアルを翻訳させていただきました。

オリジナルのサイト自体は、スライド形式になっており、レクチャーと演習部分にわかれています。しかし、翻訳していく段階でこれを完全に模倣するよりは、レクチャーと演習をそれぞれ別の媒体として準備するのも勉強するのには都合がいいかもと考え、それぞれ別のPDFを準備しました。

関心のある方は、以下のリンクからPDFをご覧いただけたらと思います。

FSL course: シェルスクリプト
FSL course: シェルスクリプト演習

FSLViewで画像が正しい向きで表示されない時

FSLViewで画像を表示すると、思ったような向きで表示されないときがあります。
下に例を示します。

fslview01

ここでは、上にある水平断、冠状断が角度が変になってしまっています。

しかし、よくみると、FSLViewは画像の前後をきちんと認識しています。
画像のまわりにあるアルファベットはそれぞれ

A: anterior
P: posterior
L: left
R: right
I: inferior
S: superior

を意味しますが、正しくなっています。

それでは、「正しく」表示するにはどうしたらよいでしょうか。
続きを読む

FSLのMacOSへのインストール方法(FSL 6.0.5以前)

*これは相当古いインストラクションです。新たなインストラクションを別に準備しますので、FSL 6.0.6 以降のインストール方法はそちらをご参照ください。

Mac OSXにFSLをインストールする機会がありました。
いくつか工夫が必要だったので、メモします。

(9/Dec/2014: fslinstaller.pyはスーパーユーザーでなくても大丈夫と気づいたので、修正しました。また、Yosemiteの場合についても追記しました。)
(1/Mar/2014: .bash_profileがない場合の対処を追記しました。また、改行コードについての注意も記載しました)

続きを読む

How to install FSL on Ubuntu (up to 5.0.9)

N.B.: This is the old post. If you want to install the latest FSL (5.0.10 and later), you need to use fslinstaller.py.

If you use Debian or Ubuntu, you can install FSL easily using neurodebian repository.
Below is what you need to install FSL.

  1. Add the neurodebian repository
  2. Follow the guideline described here.

  3. update the sources.list
  4. 1
    $ sudo apt-get update
  5. install FSL (and related packages)
  6. 1
    $ sudo apt-get install fsl fsl-doc fslview fslview-doc fsl-atlases fsl-possum-data fsl-first-data fsl-feeds dicomnifti libvtk5-dev vtk-examples vtk-doc
  7. Add the following line to .bashrc
  8. This is the thing people often forget. Without this, you can’t run fsl from shell.

    1
    . /etc/fsl/fsl.sh

    That’s it.

A study of FSLUTILS: a script to convert image files into NIFTI format

FSL has a set of many useful command-line utilities. One of the utilities is “fslchfiletype” which can change the file type of an image (e.g. from ANALYZE to NIFTI).

Using this utility, I wrote a very tiny script with which one can convert many types of image files into NIFTI format. This is very effective if you have many ANALYZE format files and want to convert them into NIFTI format in one shot.

image2nii.sh
1
2
3
4
5
6
7
#!/bin/sh
#Image file type converter using fslchfiletype
#This script converts image files into NIFTI format files.
for f in $*
do
  fslchfiletype NIFTI $f
done

Download image2nii.sh