Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to load single volumes from 4D images #9

Closed
mih opened this issue Aug 31, 2010 · 1 comment
Closed

Support to load single volumes from 4D images #9

mih opened this issue Aug 31, 2010 · 1 comment

Comments

@mih
Copy link
Member

mih commented Aug 31, 2010

Dave Flitney requested a leaner way to get access to parts of a 4D image (NIfTI in his case), i.e. the ability to get data of a single volume or timeseries. He sent the following sketch::

class FSLNiftiImage(nb.Nifti1Image):
#    def __init__(self):
#       super(FSLNiftiImage, self).__init__()

    @memoized
        def get_fileobj(self):
        fileobj = allopen(self.get_filename())
        return fileobj

    def get_volume(self, v):
        dtype = self.get_data_dtype()
        s = self.get_header().get_data_shape()
        shape = (s[0], s[1], s[2])
        offset = self.get_header().get_data_offset() + (v * np.prod(shape))
        data = array_from_file(shape, dtype, self.get_fileobj(), offset)
        return data

Usage:

image = nb.load(fname)
image.__class__ = FSLNiftiImage
v27 = image.get_volume(27)
matthew-brett pushed a commit to matthew-brett/nibabel that referenced this issue Jun 7, 2016
matthew-brett pushed a commit to matthew-brett/nibabel that referenced this issue Aug 10, 2016
More improvements. All done but refactoring
@effigies
Copy link
Member

Closed by #258.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants