Skip to content
Snippets Groups Projects
Commit 97fb4b59 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

imagewrapper.canonicalShape moved to image module

parent cc702436
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ and file names: ...@@ -22,6 +22,7 @@ and file names:
.. autosummary:: .. autosummary::
:nosignatures: :nosignatures:
canonicalShape
looksLikeImage looksLikeImage
addExt addExt
splitExt splitExt
...@@ -311,10 +312,10 @@ class Nifti(notifier.Notifier, meta.Meta): ...@@ -311,10 +312,10 @@ class Nifti(notifier.Notifier, meta.Meta):
- A sequence/tuple containing the zooms/pixdims. - A sequence/tuple containing the zooms/pixdims.
""" """
# The canonicalShape method figures out # The canonicalShape function figures out
# the data shape that we should use. # the data shape that we should use.
origShape = list(header.get_data_shape()) origShape = list(header.get_data_shape())
shape = imagewrapper.canonicalShape(origShape) shape = canonicalShape(origShape)
pixdims = list(header.get_zooms()) pixdims = list(header.get_zooms())
# if get_zooms() doesn't return at # if get_zooms() doesn't return at
...@@ -1318,6 +1319,29 @@ class Image(Nifti): ...@@ -1318,6 +1319,29 @@ class Image(Nifti):
self.notify(topic='dataRange') self.notify(topic='dataRange')
def canonicalShape(shape):
"""Calculates a *canonical* shape, how the given ``shape`` should
be presented. The shape is forced to be at least three dimensions,
with any other trailing dimensions of length 1 ignored.
"""
shape = list(shape)
# Squeeze out empty dimensions, as
# 3D image can sometimes be listed
# as having 4 or more dimensions
for i in reversed(range(len(shape))):
if shape[i] == 1: shape = shape[:i]
else: break
# But make sure the shape
# has at 3 least dimensions
if len(shape) < 3:
shape = shape + [1] * (3 - len(shape))
return shape
def looksLikeImage(filename, allowedExts=None): def looksLikeImage(filename, allowedExts=None):
"""Returns ``True`` if the given file looks like a NIFTI image, ``False`` """Returns ``True`` if the given file looks like a NIFTI image, ``False``
otherwise. otherwise.
......
...@@ -766,27 +766,13 @@ def canonicalSliceObj(sliceobj, shape): ...@@ -766,27 +766,13 @@ def canonicalSliceObj(sliceobj, shape):
return nib.fileslice.canonical_slicers(sliceobj, shape) return nib.fileslice.canonical_slicers(sliceobj, shape)
@deprecation.deprecated(deprecated_in='1.7.0',
removed_in='2.0.0',
details='moved to the fsl.data.image module')
def canonicalShape(shape): def canonicalShape(shape):
"""Calculates a *canonical* shape, how the given ``shape`` should """Deprecated - moved to the :mod:`fsl.data.image` module. """
be presented. The shape is forced to be at least three dimensions, from fsl.data.image import canonicalShape
with any other trailing dimensions of length 1 ignored. return canonicalShape(shape)
"""
shape = list(shape)
# Squeeze out empty dimensions, as
# 3D image can sometimes be listed
# as having 4 or more dimensions
for i in reversed(range(len(shape))):
if shape[i] == 1: shape = shape[:i]
else: break
# But make sure the shape
# has at 3 least dimensions
if len(shape) < 3:
shape = shape + [1] * (3 - len(shape))
return shape
def expectedShape(sliceobj, shape): def expectedShape(sliceobj, shape):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment