From 48aaf997e1183fa830480b9aa1a2ceb87c56b4b9 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Tue, 24 Mar 2020 18:23:14 +0000 Subject: [PATCH] RF: header example --- advanced_topics/08_fslpy.ipynb | 29 ++++++++++++++++++++++++----- advanced_topics/08_fslpy.md | 21 ++++++++++++++++----- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/advanced_topics/08_fslpy.ipynb b/advanced_topics/08_fslpy.ipynb index dc39b28..acda784 100644 --- a/advanced_topics/08_fslpy.ipynb +++ b/advanced_topics/08_fslpy.ipynb @@ -223,8 +223,8 @@ "# load a FSL image - the file\n", "# suffix is optional, just like\n", "# in real FSL-land!\n", - "img = Image(op.join(stddir, 'MNI152_T1_1mm'))\n", - "print(img)" + "std1mm = Image(op.join(stddir, 'MNI152_T1_1mm'))\n", + "print(std1mm)" ] }, { @@ -243,7 +243,7 @@ "# load a nibabel image, and\n", "# convert it into an FSL image\n", "nibimg = nib.load(op.join(stddir, 'MNI152_T1_1mm.nii.gz'))\n", - "img = Image(nibimg)" + "std1mm = Image(nibimg)" ] }, { @@ -259,10 +259,28 @@ "metadata": {}, "outputs": [], "source": [ - "data = np.zeros((100, 100, 100))\n", + "data = np.zeros((182, 218, 182))\n", "img = Image(data, xform=np.eye(4))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you have generated some data from another `Image` (or from a\n", + "`nibabel.Nifti1Image`) you can use the `header` option to set\n", + "the header information on the new image:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "img = Image(data, header=std1mm.header)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -276,7 +294,8 @@ "metadata": {}, "outputs": [], "source": [ - "img.save('empty.nii.gz')" + "img.save('empty')\n", + "!ls" ] }, { diff --git a/advanced_topics/08_fslpy.md b/advanced_topics/08_fslpy.md index 9cfe1d6..b8fb3b2 100644 --- a/advanced_topics/08_fslpy.md +++ b/advanced_topics/08_fslpy.md @@ -188,8 +188,8 @@ stddir = op.expandvars('${FSLDIR}/data/standard/') # load a FSL image - the file # suffix is optional, just like # in real FSL-land! -img = Image(op.join(stddir, 'MNI152_T1_1mm')) -print(img) +std1mm = Image(op.join(stddir, 'MNI152_T1_1mm')) +print(std1mm) ``` @@ -200,7 +200,7 @@ You can create an `Image` from an existing `nibabel` image: # load a nibabel image, and # convert it into an FSL image nibimg = nib.load(op.join(stddir, 'MNI152_T1_1mm.nii.gz')) -img = Image(nibimg) +std1mm = Image(nibimg) ``` @@ -208,15 +208,26 @@ Or you can create an `Image` from a `numpy` array: ``` -data = np.zeros((100, 100, 100)) +data = np.zeros((182, 218, 182)) img = Image(data, xform=np.eye(4)) ``` +If you have generated some data from another `Image` (or from a +`nibabel.Nifti1Image`) you can use the `header` option to set +the header information on the new image: + + +``` +img = Image(data, header=std1mm.header) +``` + + You can save an image to file via the `save` method: ``` -img.save('empty.nii.gz') +img.save('empty') +!ls ``` -- GitLab