File: nipy_4dto3D

package info (click to toggle)
nipy 0.1.2%2B20100526-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,992 kB
  • ctags: 13,434
  • sloc: python: 47,720; ansic: 41,334; makefile: 197
file content (34 lines) | stat: -rwxr-xr-x 962 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
''' Tiny script to write 4D files in any format that we read (nifti,
analyze, MINC, at the moment, as nifti 3D files '''

import os

import nipy.externals.argparse as argparse
import nipy.io.imageformats as nii


def main():
    # create the parser
    parser = argparse.ArgumentParser()
    # add the arguments
    parser.add_argument('filename', type=str,
                        help='4D image filename')
    # parse the command line
    args = parser.parse_args()
    img = nii.load(args.filename)
    imgs = nii.four_to_three(img)
    froot, ext = os.path.splitext(args.filename)
    if ext in ('.gz', '.bz2'):
        froot, ext = os.path.splitext(froot)
    for i, img3d in enumerate(imgs):
        fname3d = '%s_%04d.nii' % (froot, i)
        nii.save(img3d, fname3d)


if __name__ == '__main__':
    main()