心理のためのMatlabチュートリアル (SPMユーザに役立つMatlab入門)

SPMを使う方々は必ずMatlabを使いますが、世の中のMatlab入門をうたった書籍は、たいていが工学向けで、SPMを使う人がこれを知っておいたらいいというようなMatlab入門はあまりありません。何かいい手引きがないかと探していたら、Andrea Hamilton女史の書いたMatlab for Psychologists: A Tutorialという手引きを見つけました。ざっと見たところ非常によい手引きと感じたので、Hamilton女史に連絡をとり、日本語訳の許可をいただきました。日本語訳ができましたので、公開します。「心理のため」となっていますが、SPMを使う方々には、とても有用だと思います。
 なお、翻訳にあたり、山口大学の松尾幸治先生に多くのアドバイスをいただきました。この場をお借りして深謝いたします。

心理士のためのMatlabチュートリアルをダウンロード

Update of Lin4Neuro (28 Feb 2013)

Lin4Neuro was updated. Some changes are…

  • 3D Slicer was updated to 4.2.2-1 (only in 64bit version).
  • MITK and MITK Diffusion was updated to 2012.12 version (only in 64bit version).
  • nfs-common was added so that it can support NFS filesystem with default settings.

I also stopped developing Lin4Neuro based on Ubuntu 10.04LTS. I focus on developing Lin4Neuro based on Xubuntu 12.04LTS.

You can download latest Lin4Neuro from here.

SPM switcher: Run different versions of SPM in one Matlab

I used to write an article, “Run SPM2, SPM5, and SPM8 concurrently.” Though this is a smart way to run different version of SPM, we need to prepare scripts separately. So I came up with another script, called “SPM switcher”. This script brings up a dialog and you can select the version of SPM you want to run.

  • Make a directory where you want to save scripts. (e.g. C:\Users\foo\Documents\MATLAB\)
  • Add the directory to the path in Matlab. (File -> Set Path -> Add path)
  • put spm_rmpath.m in SPM2 and SPM99 directory.
  • You find this file in SPM5 or SPM8 directory. You can just copy it from SPM5/8 to SPM2/99 directory.

  • save switchspm.m in the directory you prepared.
  • edit switchspm.m and change “spm_path=’C:\spm\’” according to your circumstance.

Typing switchspm in Matlab command window will bring up a dialog below and you can run different version of SPM easily.

switchspm_screenshot

Download switchspm.m (Right click –> Save as)

%switchspm: Run different version of SPM
%This tiny script prompts the dialog which SPM version you want to run.
%Prerequisites
%1. Each version of SPM is supporsed to be located under spm_path.
%2. Please copy spm_rmpath.m from SPM5 or later and put it into SPM99 and
% SPM2 direcotry. Otherwise, Path removal won't work correctly.
%3. Please change the SPM path according to your environment

%%%Please change the path below according to your environment%%%
spm_path='C:\spm\';
%%%

%The path for each version of SPM
spm99_path=fullfile(spm_path,'spm99');
spm2_path=fullfile(spm_path,'spm2');
spm5_path=fullfile(spm_path,'spm5');
spm8_path=fullfile(spm_path,'spm8');
spm12b_path=fullfile(spm_path,'spm12b');

str = ['spm99 '; 'spm2 '; 'spm5 '; 'spm8 '; 'spm12b'];
spmver = listdlg('PromptString','SPM ver you want to run...',...
'SelectionMode','single',...
'ListString',str);

switch spmver
case 1, %spm99
% remove spm path
while true
try
spm_rmpath
catch break;
end;
end;
% add spm99 path
addpath(spm99_path);
% run spm99
spm;

case 2, %spm2
% remove spm path
while true
try
spm_rmpath
catch break;
end;
end;
% add spm2 path
addpath(spm2_path);
% run spm2
spm;

case 3, %spm5
% remove spm path
while true
try
spm_rmpath
catch break;
end;
end;
% add spm5 path
addpath(spm5_path);
% run spm5
spm;

case 4 %spm8
% remove spm path
while true
try
spm_rmpath;
catch break;
end;
end;
% add spm8 path
addpath(spm8_path);
% run spm8
spm;

case 5 %spm12b
% remove spm path
while true
try
spm_rmpath;
catch break;
end;
end;
% add spm12b path
addpath(spm12b_path);
% run spm12
spm;
end

Xubuntuで用紙サイズがLetterになってしまうとき…

Xubuntuでいろいろ印刷するときに、用紙をA4と設定しても、プリンターの方で、「Letterになっています。強制印刷しますか?」のような警告が出ることがいつもでした。
原因は何だろうと思っていたら、次の変数でした。

/etc/environment
の中にLC_PAPERというものがあります。

これが、私の場合、

LC_PAPER="en_US.UTF-8"

となっていました。調べたところ、この設定だと用紙サイズのデフォルトは、Letterになること。
なので、これを

LC_PAPER="ja_JP.UTF-8"

と変えたところ、問題がなくなりました。
locale設定が用紙サイズにも影響しているんですね。
Xubuntuだけでなく、Ubuntuでも同じようなことが起こるのだと思います。

A study of shell script: Convert various image files formats into EPS format

I’m learning shell scripts these days.
Below is a script which converts various image file formats (jpg, png, etc…) into eps format using ImageMagick.
LaTeX user might find this script useful.

#!/bin/sh
#A script which converts various image file formats into EPS format.
#Usage: image2eps.sh filename
#Wild card can be used.

if [ $# = 0 ]
then
echo "Please specify the files you want to convert!"
echo "Usage: image2eps.sh filename"
exit 1
fi

for image in "$@"
do
if [ -f $image ]
then
convert $image `echo eps2:$image | sed 's/\..*$/.eps/'`
else
echo "$image: No such file"
fi
done

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.

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

auto_reorient.m

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.

確かにアップデートされます。便利ですね。

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);

You can download each version from http://www.nemotos.net/l4n-iso/

Hope Lin4Neuro will help you enjoy playing with your images.

VBMの結果を用いて容積を測定する方法

VBMで得られる画像を用いて、灰白質や白質画像の容積を求めることができます。

事前の準備として、以下のことが必要です。

  • get_totals.m
  • Ged Ridgwayが公開している容積算出のためのスクリプトです。http://www0.cs.ucl.ac.uk/staff/g.ridgway/vbm/get_totals.mここから入手できます(右クリックしてリンク先を保存としてください)。これをSPMのディレクトリに保存します。

  • WFU PickAtlas
  • これは、局所容積を求めたい時に便利です。マスク画像を簡単に作成することができます。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)

So if you want to reflect your personal customization in system-wide setting, you just need to type these two commands 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/

p.s. (27 Oct 2012)
I found that the description above is not enough to reflect systemwide settings.
I needed to do the following. (Some of them might not be needed.)

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