We can calculate grey/white matter volume from segmented images.
You need the following script and SPM plugin.
Shell color of Xubuntu
I noticed that Xubuntu overrides color of shell.
I looked for the solution and found the colorcode is in ~/.config/Terminal/terminalrc
[Configuration]
ColorForeground=#000000000000
ColorBackground=#ffffffffffff
ColorCursor=#000000000000
ColorSelection=#e3d6e3d6e3d6
ColorSelectionUseDefault=FALSE
ColorPalette2=#66660a3d0a3d
ColorPalette3=#000066661999
ColorPalette4=#4ecf2e2e6666
ColorPalette5=#171734344d4d
ColorPalette6=#800012d38000
ColorPalette7=#000080008000
ColorPalette8=#35357878b3b3
ColorPalette9=#999999999999
ColorPalette10=#80000ccd0ccd
ColorPalette11=#0000a6662999
ColorPalette12=#9d9d5c5ccccc
ColorPalette13=#262656568080
ColorPalette14=#cccc1e6dcccc
ColorPalette15=#0000aaaaaaaa
ColorPalette16=#52529393cccc
FontName=Droid Sans Mono 10
MiscAlwaysShowTabs=FALSE
MiscBell=FALSE
MiscBordersDefault=TRUE
MiscCursorBlinks=FALSE
MiscCursorShape=TERMINAL_CURSOR_SHAPE_BLOCK
MiscDefaultGeometry=80x24
MiscInheritGeometry=FALSE
MiscMenubarDefault=TRUE
MiscMouseAutohide=FALSE
MiscToolbarsDefault=FALSE
MiscConfirmClose=TRUE
MiscCycleTabs=TRUE
MiscTabCloseButtons=TRUE
MiscTabCloseMiddleClick=TRUE
MiscTabPosition=GTK_POS_TOP
MiscHighlightUrls=TRUE
TabActivityColor=#262656568080
By commenting out the items regarding Color, I got the traditional look of shell.

SPM5およびSPM8でAC-PCを自動で設定できるスクリプト
この記事は、http://www.nemotos.net/?p=17で紹介したものを日本語に訳しただけのものです。
2008年10月18日に、Carlton Chu氏がSPMのメーリングリストに便利なスクリプトを投稿しました。
メーリングリストでは特に反応はなかったのですが、非常に有用だと思いますので、本ブログで紹介させていただきます。
このスクリプトの目的はいたってシンプルです:AC-PCを自動的にあわせてくれます!
若干時間がかかります(1例に数分かかります)が、何百例もAC-PCをあわせなくてはいけないような状況では、大きな時間の節約になります。
もし関心があったら、次のスクリプトを試してみて下さい。SPM5、SPM8でうまく動きます。
オリジナルの投稿では、若干動作しないバグがありました。そこを修正してあります。
使用方法:添付のファイルをダウンロードし、SPM5かSPM8に置いてください。その後、MATLABのコマンドウィンドウから、”auto_reorient”とタイプしてください。ファイル選択のウィンドウが立ち上がりますので、AC-PCを設定したいファイルを選択して下さい(複数選択できます)。
function auto_reorient(p)
spmDir=which('spm');
spmDir=spmDir(1:end-5);
tmpl=[spmDir 'canonical/avg152T1.nii'];
vg=spm_vol(tmpl);
flags.regtype='rigid';
p=spm_select(inf,'image');
for i=1:size(p,1)
f=strtrim(p(i,:));
spm_smooth(f,'temp.nii',[12 12 12]);
vf=spm_vol('temp.nii');
[M,scal] = spm_affreg(vg,vf,flags);
M3=M(1:3,1:3);
[u s v]=svd(M3);
M3=u*v';
M(1:3,1:3)=M3;
N=nifti(f);
N.mat=M*N.mat;
create(N);
end
FSLのMacOSへのインストール方法(FSL 6.0.5以前)
*これは相当古いインストラクションです。新たなインストラクションを別に準備しますので、FSL 6.0.6 以降のインストール方法はそちらをご参照ください。
Mac OSXにFSLをインストールする機会がありました。
いくつか工夫が必要だったので、メモします。
(9/Dec/2014: fslinstaller.pyはスーパーユーザーでなくても大丈夫と気づいたので、修正しました。また、Yosemiteの場合についても追記しました。)
(1/Mar/2014: .bash_profileがない場合の対処を追記しました。また、改行コードについての注意も記載しました)
SPMをオンラインでアップデートする方法
SPMは定期的にアップデートされています。spm_updateというコマンドをうつと、自分のSPMのバージョンが最新かどうかチェックできます。
>> spm_update
A new version of SPM is available on:
ftp://ftp.fil.ion.ucl.ac.uk/spm/spm8_updates/
(Your version: 4290 - New version: 4667)
これまで、FTPでアップデートをとってきていましたが、ある方に、spm_update(1)とやると、自動で最新ファイルを入手してくれるよと教わりました。
自分が使っているSPMがちょうどアップデートが必要だったのでやってみました。
>> spm_update(1)
A new version of SPM is available on:
ftp://ftp.fil.ion.ucl.ac.uk/spm/spm8_updates/
(Your version: 4290 - New version: 4667)
2781 files have been updated.
確かにアップデートされます。便利ですね。
FSLView on Ubuntu 12.04 Precise
I found that now FSLView is available in Ubuntu 12.04
Below is the screenshot I installed in Lin4Neuro.
Now I do not have any hesitation moving from Ubuntu 10.04 to Ubuntu 12.04 (Actually Xubuntu 12.04)
So from now on I will stop developing Lin4Neuro based on Ubuntu 10.04. I keep working on getting Lin4Neuro based on Xubuntu 12.04 better and better.

New Lin4Neuro based on Xubuntu 12.04
I am pleased to announce the new release of Lin4Neuro based on Xubuntu 12.04LTS.
Only 64-bit version is released this time, but I’m working on 32-bit version so hopefully I will be able to release the 32-bit version in the near future.
I chose Xubuntu 12.04 as a base of Lin4Neuro simply because I don’t like Unity. If you look at the screenshot of new Lin4Neuro, you can tell that I made UI as simple as I could.

At the same time, I keep working on Lin4Neuro based on Ubuntu 10.04LTS, because FSLView doesn’t work on Ubuntu 12.04… I know some of users like to use FSLView, so I keep working on it.
Other than FSLView, there are some differences between versions.
- New Lin4Neuro (L4N12.04) includes DSI studio in response to a request by Renaud Nicolas.
- L4N12.04 doesn’t includ N3 tools. I haven’t been able to install the software yet.
So Now you have three options. From now on I will name the each version as following (I do not change the file name of old versions);
- Lin4Neuro-64bit-based-on-Xubuntu-12.04: l4n-12.04-x64-xxxxxxxx.iso
- Lin4Neuro-64bit-based-on-Ubuntu-10.04: l4n-10.04-x64-xxxxxxxx.iso
- Lin4Neuro-32bit-based-on-Ubuntu-10.04: l4n-10.04-x86-xxxxxxxx.iso
You can download each version from http://www.nemotos.net/lin4neuro/
Hope Lin4Neuro will help you enjoy playing with your images.
VBMの結果を用いて容積を測定する方法
VBMで得られる画像を用いて、灰白質や白質画像の容積を求めることができます。
事前の準備として、以下のことが必要です。
- get_totals.m
- WFU PickAtlas
Ged Ridgwayが公開している容積算出のためのスクリプトです。http://www0.cs.ucl.ac.uk/staff/g.ridgway/vbm/get_totals.mここから入手できます(右クリックしてリンク先を保存としてください)。これをSPMのディレクトリに保存します。
これは、局所容積を求めたい時に便利です。マスク画像を簡単に作成することができます。http://fmri.wfubmc.edu/software/PickAtlasここから入手できます。今回はこのセットアップ方法は説明しませんのであしからず。
The location of config file of Menu and Panel of Xubuntu
In the process of remastering customized Xubuntu, I spent lots of time to identify the location of config file of Menu and Panel of Xubuntu. Usually files should be located to /etc/skel, but xfce seems to have different policies.
The menu settings is stored in
~/.config/menus/xfce-applications.menu
and the panel settings is stored in
~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml
And the system-wide settings are stored in the locations below.
/etc/xdg/xdg-xubuntu/menus/xfce-applications.menu (menu)
/etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml (panel)
/etc/xdg/xfce4/panel/* (panel)
You also need to copy some files in home directory to /etc/skel.
So if you want to reflect your personal customization in system-wide setting, you need to type the following from the terminal.
sudo cp ~/.config/menus/xfce-applications.menu /etc/xdg/xdg-xubuntu/menus/ sudo cp ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml \ /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/ sudo cp -r ~/.config/xfce4/panel /etc/xdg/xfce4/ sudo cp -a .config .gconf .gnome2 .local .bashrc /etc/skel sudo cp -a ./Desktop /etc/skel/ cd /etc/skel sudo chown -R root:root .config .gconf .gnome2 .local .bashrc Desktop
Linuxでのファイル・ディレクトリ名一括置換
ときどきファイル名やディレクトリ名を一括で置換したいことがあります。
私の場合、こんなことがありました。
あるデータがこんなディレクトリに入ってきました。
120903
120904
120910
…
120929
しかし、私の管理方法では、
20120903
20120904
20120910
…
20120929
としたいわけです。
端末から簡単に打てるコマンドがないかと探したところ、
その名も rename というコマンドがありました。
rename 's/検索文字列/置換文字列/' ファイル・ディレクトリ名(ワイルドカード可)
となるようです。
私の場合
$ rename 's/^12/2012/' *
で目的を達成することができました。
備忘録として残しておきます。
Lin4Neuro日本語版ページの開設
これまで需要がありましたが、多忙にかまけてさぼっていたLin4Neuroの日本語版のページを作成いたしました。英語が苦手な方やとりあえず、何がどうなってるのと思う方々には多少お役に立てるのではないかと思います。
このブログの上の方にある「Lin4Neuro日本語版」をクリックしていただくか、
こちらからご覧ください。
Update of Lin4Neuro (18Sep2012)
I updated Lin4Neuro. The main changes of this version are the following.
- FSL was updated to 5.0.0.
- Slicer was updated to 4.1.1. (only in 64bit version)
Since FSLView doesn’t work well with Ubuntu 12.04, I stick to Ubuntu 10.04 for the time being.
However, I’m in the process of developing Lin4Neuro based on Ubuntu 12.04 (actually Xubuntu 12.04) now. Hopefully I will be able to release 12.04base version by the end of this year.
You can get the iso images from www.nemotos.net/l4n-iso
How to do Topological FDR
Many ask “how to do Topological FDR” in SPM ML. Below are the posts I found useful.
Originally Guillaume Flandin showed how to do that.
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;44838216.0904
The height threshold you define during the Results procedure is the feature-inducing threshold (used to define local maxima and clusters).
For topological FDR, I would typically choose “none” and a small T-value, for example 3.
The MIP will display all voxels whose T-value is above 3 and the Results table will display all local maxima whose T-value is above 3 (actually, at most 3 local maxima per cluster, more than 8mm apart) and the corresponding FWE p-values and FDR q-values for peaks and clusters.If you want to threshold the MIP to a particular significance level, go through the Results procedure again and enter the corresponding height and extent thresholds (the 0.05 critical thresholds are indicated at the bottom left of the Results table):
(height) FWEp and FDRp for peak-FWE and -FDR.
(extent) FWEc amd FDRc for cluster-FWE and -FDR.
Jonathan Peele also gave a detail instruction of how to do that. This time he focused more on cluster-thresholded FDR.
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;6f4e0139.1110
> How can I see images with a threshold at the cluster-level instead of the peak level with the graphical user interface?
I’m not aware of a way to set a cluster-level threshold when running results the first time (i.e., “show everything that is cluster-level corrected p < .05"). What I would do is this: 1) Run results using some voxelwise threshold. This threshold defines your clusters, and it's fine to use an uncorrected threshold (e.g., p< .001, uncorrected). 2) In the results table, for each cluster you will see the cluster extent (i.e. how many voxels) and the cluster-corrected p value. In SPM8 you will see 2 cluster-corrected p values, one for topological FDR (Chumbley & Friston, 2009), one for random field theory (labeled FWE). You can then look at the size of those clusters, and figure out the cluster extent that divides p < .05 from the others. For example, if a cluster of 300 voxels is p = .10, and a cluster of 400 voxels is p = .04, then you know that any cluster 400 voxels or larger would be p < .05. 3) Re-run the results, selecting the same voxelwise threshold. But now, in the minimum cluster extent, specify the cluster size you just figured out—in the above example, you could specify 400.
4) Now all of the displayed results should be cluster-level corrected.
5) If you want to save this thresholded image for displaying with another program, just click the “save” button, and you can write out a thresholded t map as a nifti file.
In practice this is actually fairly quick to do once you’ve done it a couple of times.
Note the difference between these two. Two-step approach is the same, but Guillaume’s way deals with peak and cluster threshold and Jonathan’s way deals with cluster threshold.
Lin4NeuroをUSBメモリから起動する方法
普段Windowsを使っているけれども、Linuxを使ってみたい。そんな人はある程度いると思います。特に、画像解析をする人は特にそうかもしれません。
そんなとき、3つのオプションがあります。
- WindowsにVMware playerやVirtualboxなどの仮想化ソフトをインストールし、その中にLinuxをインストールする。
- USBメモリにインストール
- Macに乗り換える
これはなかなか便利です。私も普段、これで仕事をしています。Lin4Neuroの開発はVMware上で行なっています。何度も試行錯誤がきくからです。具体的な方法はこちらに記載しましたので、そちらを御覧ください。
これが今から示す方法です。これが便利なのは、自分のPCでなく、手元に転がっているPCで同じ環境を再現できるということです。もしくは、チュートリアルなどで人に何かを伝えたい場合に、自分で環境を準備しておいて、USBメモリを準備することで他の人が全く同一の環境を再現することができます。
Mac OSXはBSDベースで、Bシェルが普通に走ります。これは結構便利で、最近、Macに乗り換えようかどうか真剣に考えています。でも、一つのことに傾倒しすぎるのはどうかなとも思っているので、MacBookProを持ってはいますが、まだメインマシンとはなっていません…。
LinuxをUSBメモリにインストールする方法は知っておくと何かと役に立つことがあります。Windowsのファイルが壊れてしまい、Windowsが立ち上がらなくなった時、LinuxブートのUSBメモリを持っておけば、それから起動してPCから多くのファイルを救出することができます。なので、Lin4Neuroに限ったことではないのですが、便利なのでその起動方法をPDFドキュメントにまとめてみました。下のリンクからどうぞ。
VMware player上でのLin4Neuroの使い方
画像解析に特化したカスタマイズOSのLin4Neuro。一定の需要があるようで、便利という声をいただいております。
画像解析のためだけにWindowsからLinuxに乗り換えることを躊躇している人も多いと思います。正直、私も画像解析のメインマシンはLinuxですが、日頃の雑多な仕事はまだWindows上で行なっています。Linuxは基本いいのですが、つまずいたときにすぐにトラブルシューティングできるだけの能力がまだないからです。
64bitでメモリもたくさんのっかる世の中、仮想環境がずいぶん充実してきました。Lin4Neuroも仮想環境でけっこういい感じで動きます。めちゃくちゃメモリを使う仕事でなければ、ノートPCに8GBのメモリを載せ、そのうち4GBを仮想に割り当ててそこでLin4Neuroを走らせれば、けっこういい感じで解析ができます。
ということで、VMware player(無償で入手できます)上でのLin4Neuroの動かし方をPDFドキュメントにしてみました。必要な方はダウンロードしてください。
Voxel-wise FDR and Topological FDR
In SPM8, voxel-wise FDR was hidden and Topological FDR was introduced. What is Topological FDR? I find some useful notes from SPM8 Release Notes and a post by Tom Nichols to SPM-ML. I quote these two.
Topological False Discovery Rate (FDR)
FDR control is an alternative to the more conservative “family-wise error” control for multiple comparisons. Historically, SPM has aimed to control FDR on voxels (the
expected fraction of false-positive/total-positive decisions made about individual voxels in an image). This is now superseded by FDR control of topological properties of the signal (i.e. control of properties that pertain to the spatial organization of activations – e.g. height and extent – and are not reducible to individual voxels). SPM is now able to identify significantly voluminous blobs according to a decision procedure that controls spatial-extent FDR. Thus, on average, the fraction of blobs falsely deemed to have significant spatial extent is controlled beneath say 5/100 = .05 or 1/100 = .01. More recent work is examining FDR control over local maxima.
A post to SPM-ML by Tom Nichols
In SPM8 FDR topological inference was introduced, and voxel-wise FDR inference hidden. Topological inference means inference on peaks and clusters; voxel-wise inference is based on every individual voxel in the image (instead of spatial features of the image). Thus “Topological FDR” means inference on clusters based on cluster size (or local peaks based on peak height), controlling the fraction of false positive clusters among all clusters (or false positive peaks among all peaks) on average, over many experiments.
While topological FDR results may be easier to interpret, in my experience it is is generally not very sensitivity and yields similar results to FWE-corrected inferences.
If you would like to use voxel-wise FDR in SPM8, edit spm_defaults, changing “topoFDR” line to read
defaults.stats.topoFDR = 0;
(quit and re-start SPM to take effect).
References
Chumbley, J., Worsley, K., Flandin, G., & Friston, K. (2010). Topological FDR for neuroimaging. NeuroImage, 49(4), 3057-64. doi: 10.1016/j.neuroimage.2009.10.090.
Chumbley, J. R., & Friston, K. J. (2009). False discovery rate revisited: FDR and topological inference using Gaussian random fields. Neuroimage, 44(1), 62–70. doi: 10.1016/j.neuroimage.2008.05.021.
Files generated in VBM statistics
When you do VBM analysis, you see many files are generated in your stats directory. Suppose you are doing a two sample t-test. You see files like below.
- beta_0001
- beta_0002
- con_0001
- mask
- ResMS
- RPV
- spmT_001
Ged Ridgway made a clear explanation of these files in NITRC discussion forum. http://www.nitrc.org/forum/message.php?msg_id=6483
It is important to know what these files are, so I quote his post with some modification.
- beta
- con
- mask
- ResMS
- RPV
- spmT
The estimated linear model parameters at each voxel. In a two-sample design, these are just the two group mean images. beta_0001 is a mean image of group A, and beta_0002 is a mean image of group B.
The contrasts of the parameters. If one makes a contrast of [-1 1], the con_0001 will simply be beta_0002 – beta_0001
A binary image indicating which voxels were considered in the analysis. If this mask is too small, you may miss the region you are interested in. If too big, it is less likely to survive multiple comparison. So it is worth checking the mask image before you draw some conclusion from your analysis.
The estimated variance (residual mean squares), from which the above-mentioned standard error is derived.
In more detail, the standard error is proportional to the square root of ResMS and a term that relates to the design matrix X and contrast c as sqrt(c’*pinv(X’*X)*c), which (in two sample t-test) roughly reflects the fact that the standard error is inversely proportional to the number of subjects one has.
The resels-per-voxel image related to the smoothness (roughness)
estimate needed for random field theory.
The t-statistic maps formed by dividing the contrast image by its estimated standard error.
Aterm WM3600Rで無線LANの接続が頻繁に切れる場合の対策
私は普段WiMAXを使っているのですが、最近手に入れたAterm WM3600Rは非常に無線LANの接続が切れていました。
これでは、意味がないじゃん!と思っていましたが、検索すると多くの人が同じ症状で苦しんでいました。
NECが公式に対策を発表しているので、それを備忘録も含めて下に書きます。
出典はこちら。
- クイック設定Webを開きます。
- 左メニューから『無線LAN設定』-『無線LAN設定』を選択します。
- 『無線LAN設定』画面が開きますので、【高度な設定を表示】ボタンを押して「拡張設定」を表示させます。
- [無線LAN端末(子機)との通信設定]で【省電力優先】を選択する。
- [無線優先制御機能]で【使用する】に入っているチェックを外す。
- [送信出力]で【100%】を選択する。
http://aterm.me で開きます。
ここで以下の設定を行います。
メーカーのページには以下のように書かれています。
いずれかの設定を行うのみで改善される場合や、複数の設定を行うことで改善される場合があります。記載された内容を1つずつお試しください。また、これらの設定を行っても原因が別にある場合は、改善されない場合もあります。
※上記設定を行うと、スループット(実行速度)が低下する場合があります。
※上記設定を行うと、11bまたは11gでの通信となり、11nテクノロジーでの通信は行えません。
※上記設定を行うと、他の通信機器が近くにある場合は、電波の干渉が受けやすくなります。
どうもいろんな人のブログを見ると、一番最初にある無線LAN端末との通信設定で省電力優先を選択することがよいようです。
実際、その設定で切断が圧倒的に減りました。
通信速度よりも接続の安定の方がずっと大事なので、そちらでしばらくやってみます。
Shell script to replace a part of filenames
I came across a situation I want to change a part of filenames.
I have many nvXXXX.nii files, and I want to change it to n1vXXXX.nii.
Below is the shell script I came up with.
The point is using sed.
#!/bin/bash # A script to change a part of filenames. for FILE in $* do echo $FILE | sed -e "s/nv/n1v/" # This is optional. I just want to display the filenames on the monitor. mv $FILE `echo $FILE | sed -e "s/nv/n1v/"` done
The below might be better if I want to use the new filenames as some variables.
#!/bin/bash # A script to change a part of filenames. for FILE in $* do echo $FILE | sed -e "s/nv/n1v/" NEWFILE=`echo $FILE | sed -e "s/nv/n1v/"` mv $FILE $NEWFILE done
openSuse 11.1 で Scan Snap S510は使えるか?
*昔に書いた内容ですが、検索でひっかかることが多いようなので、再度アップします。
確定申告の時期で、いろいろな書類のコピーをとるためにScansnapが大活躍しています。
Scansnapを導入したとき、Windowsマシンに様々なドライバをインストールしなければいけなかったので、Linuxでは使えないだろうなぁと勝手に思っていました。
しかし、何気なく”scansnap Linux”でググってみたところ、ubuntuでXSANEを使うとできちゃうみたいなことが書いてある記事を発見しました。
そこで、opensuse 11.1でできるかどうか確認。
xsaneのインストールの確認
YAST -> ソフトウェアの管理 -> xsaneで検索してみると、自分のマシンにはインストールされていました。
scansnap S510をつないでみる。
WindowsマシンにつながれていたS510のUSBコードをLinuxマシンに差し替えます。
どのように認識されるか確認
lsusb でUSBデバイスのリストを一覧で表示できます。
こんな出力がされました。
$lsusb
Bus 005 Device 002: ID 04c5:1155 Fujitsu, Ltd
対応の確認
次の2通りの方法があるかと。
SANEのサイトで確認
http://www.sane-project.org/sane-mfgs.html#Z-FUJITSU
ここには、
S510 USB 0x04c5/0×1155 Good workgroup, current, no TWAIN driver fujitsu
(1.0.55) sane-fujitsu
とかかれています。きちんと動きそうです。
/etc/sane.d/fujitsu.confを確認
$less /etc/sane.d/fujitsu.conf
最後の行にS510があります。
#scansnap S510
usb 0x04c5 0×1155
きちんと動きそうです。
xsaneの起動
メニューから、グラフィックの中にxsaneがあるので、それから起動。
感動したのが、ADFが両面も選べるようになっていること。
(ただし、その場合は、スキャン枚数(一番上の項目)を2以上に設定しなければいけません。)
ScanSnap本体の緑色ボタンは使えないものの、xsane経由で、普通にScansnapが使えるようになりました。
これで、Windowsに依存しなければいけない要素がまた一つ減りました。
それにしても、最近のLinuxは便利になりましたね。