examples/FLIRT_registration.ipynb
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'flirt -in /Users/gkiar/Desktop/KKI2009_113_1_B0.nii -ref /Users/gkiar/Desktop/KKI2009_113_1_MPRAGE.nii -omat /Users/gkiar/Desktop/B0toMPRAGE.mat -cost mutualinfo -bins 256 -dof 12 -searchrx -180 180 -searchry -180 180 -searchrz -180 180'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os.path as op\n",
"b0 = \"/Users/gkiar/Desktop/KKI2009_113_1_B0.nii\"\n",
"mprage = \"/Users/gkiar/Desktop/KKI2009_113_1_MPRAGE.nii\"\n",
"mat1 = '/Users/gkiar/Desktop/B0toMPRAGE.mat'\n",
"mat1\n",
"cmd = 'flirt -in ' + b0 + ' -ref ' + mprage + ' -omat '+ mat1 +\" -cost mutualinfo -bins 256 -dof 12 -searchrx -180 180 -searchry -180 180 -searchrz -180 180\"\n",
"cmd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"('', '')"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from subprocess import Popen, PIPE\n",
"p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)\n",
"p.communicate()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'flirt -in /Users/gkiar/Desktop/KKI2009_113_1_MPRAGE.nii -ref /Users/gkiar/Desktop/MNI152_T1_1mm.nii.gz -omat /Users/gkiar/Desktop/MPRAGEtoMNI.mat -cost mutualinfo -bins 256 -dof 12 -searchrx -180 180 -searchry -180 180 -searchrz -180 180'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mni = \"/Users/gkiar/Desktop/MNI152_T1_1mm.nii.gz\"\n",
"mat2 = '/Users/gkiar/Desktop/MPRAGEtoMNI.mat'\n",
"mat2\n",
"cmd = 'flirt -in ' + mprage + ' -ref ' + mni + ' -omat '+ mat2 +\" -cost mutualinfo -bins 256 -dof 12 -searchrx -180 180 -searchry -180 180 -searchrz -180 180\"\n",
"cmd"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"('', '')"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)\n",
"p.communicate()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'convert_xfm -omat /Users/gkiar/Desktop/B0toMNI.mat -concat /Users/gkiar/Desktop/MPRAGEtoMNI.mat /Users/gkiar/Desktop/B0toMPRAGE.mat'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat3 = '/Users/gkiar/Desktop/B0toMNI.mat'\n",
"cmd = 'convert_xfm -omat '+ mat3 +' -concat '+ mat2 + ' ' + mat1\n",
"cmd"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"('', '')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)\n",
"p.communicate()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'flirt -in /Users/gkiar/Desktop/KKI2009_113_1_DTI.nii -ref /Users/gkiar/Desktop/MNI152_T1_1mm.nii.gz -out /Users/gkiar/Desktop/KKI2009_113_1_DTI_reg.nii.gz -init /Users/gkiar/Desktop/B0toMNI.mat -interp trilinear -applyxfm'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dwi = '/Users/gkiar/Desktop/KKI2009_113_1_DTI.nii'\n",
"reg_dwi = '/Users/gkiar/Desktop/KKI2009_113_1_DTI_reg.nii.gz'\n",
"cmd = 'flirt -in '+ dwi +' -ref '+ mni +' -out '+ reg_dwi +' -init '+ mat3 +' -interp trilinear -applyxfm'\n",
"cmd"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"('', '')"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)\n",
"p.communicate()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}