Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
9f3074cb
Commit
9f3074cb
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New MGHImage class, for loading .mgz/mgh files.
parent
fae775a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/data/mghimage.py
+64
-0
64 additions, 0 deletions
fsl/data/mghimage.py
with
64 additions
and
0 deletions
fsl/data/mghimage.py
0 → 100644
+
64
−
0
View file @
9f3074cb
#!/usr/bin/env python
#
# mghimage.py - The MGHImage class
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""
This module provides the :class:`MGHImage` class, which can be used to load
Freesurfer ``mgh``/``mgz`` image files.
.. autosummary::
:nosignatures:
looksLikeMGHImage
"""
import
six
import
nibabel
as
nib
import
fsl.data.image
as
fslimage
class
MGHImage
(
fslimage
.
Image
):
"""
The ``MGHImage`` class is a NIFTI :class:`Image` which has been converted
from a Freesurfer ``.mgh`` file.
.. see:: https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat
.. see:: http://nipy.org/nibabel/reference/nibabel.freesurfer.html
"""
def
__init__
(
self
,
image
,
*
args
,
**
kwargs
):
"""
Create a ``MGHImage``.
:arg image: Name of MGH file, or a
``nibabel.freesurfer.mghformat.MGHImage`` instance.
All other arguments are passed through to :meth:`Image.__init__`
"""
if
isinstance
(
image
,
six
.
string_types
):
image
=
nib
.
load
(
image
)
data
=
image
.
get_data
()
affine
=
image
.
affine
fslimage
.
Image
.
__init__
(
self
,
data
,
xform
=
affine
)
ALLOWED_EXTENSIONS
=
[
'
.mgz
'
,
'
.mgh
'
]
"""
List of file extensions interpreted as MGH image files.
"""
EXTENSION_DESCRIPTIONS
=
[
'
Compressed MGH image
'
,
'
MGH image
'
]
"""
A description for each of the :attr:`ALLOWED_EXTENSIONS`.
"""
def
looksLikeMGHImage
(
filename
):
"""
Returns ``True`` if the given file looks like a MGH image, ``False``
otherwise.
"""
return
fslimage
.
looksLikeImage
(
filename
,
ALLOWED_EXTENSIONS
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment