def to_nifti(obj, like=None, header=None, affine=None, extensions=Ellipsis, version=<NUM_LIT:1>):
from neuropythy.mri import Subject<EOL>obj0 = obj<EOL>if like is not None:<EOL><INDENT>if isinstance(like, nib.analyze.AnalyzeHeader) orisinstance(like, nib.freesurfer.mghformat.MGHHeader):<EOL><INDENT>if header is None: header = like<EOL><DEDENT>elif isinstance(like, nib.analyze.SpatialImage):<EOL><INDENT>if header is None: header = like.header<EOL>if affine is None: affine = like.affine<EOL><DEDENT>elif isinstance(like, Subject):<EOL><INDENT>if affine is None: affine = like.voxel_to_native_matrix<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % type(like))<EOL><DEDENT><DEDENT>elif ((version == <NUM_LIT:1> and isinstance(obj, nib.nifti1.Nifti1Image)) or<EOL>(version == <NUM_LIT:2> and isinstance(obj, nib.nifti2.Nifti2Image))):<EOL><INDENT>if ((header is None or obj.header is header) and<EOL>(extensions is Ellipsis or extensions is obj.header.extensions or<EOL>(extensions is None and len(obj.header.extensions) == <NUM_LIT:0>))):<EOL><INDENT>return obj<EOL><DEDENT><DEDENT>if header is None:<EOL><INDENT>if isinstance(obj, nib.analyze.SpatialImage):<EOL><INDENT>header = obj.header<EOL><DEDENT>else:<EOL><INDENT>header = nib.nifti1.Nifti1Header() if version == <NUM_LIT:1> else nib.nifti2.Nifti2Header()<EOL><DEDENT><DEDENT>if affine is None:<EOL><INDENT>if isinstance(obj, nib.analyze.SpatialImage):<EOL><INDENT>affine = obj.affine<EOL><DEDENT>else:<EOL><INDENT>affine = np.eye(<NUM_LIT:4>)<EOL><DEDENT><DEDENT>if extensions is None:<EOL><INDENT>extensions = nib.nifti1.Nifti1Extensions()<EOL><DEDENT>if isinstance(obj, nib.analyze.SpatialImage):<EOL><INDENT>obj = obj.dataobj<EOL><DEDENT>elif not pimms.is_nparray(obj):<EOL><INDENT>obj = np.asarray(obj)<EOL><DEDENT>if len(obj.shape) < <NUM_LIT:3>: obj = np.asarray([[obj]])<EOL>if version == <NUM_LIT:1>:<EOL><INDENT>obj = nib.nifti1.Nifti1Image(obj, affine, header)<EOL><DEDENT>elif version == <NUM_LIT:2>:<EOL><INDENT>obj = nib.nifti2.Nifti2Image(obj, affine, header)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % version)<EOL><DEDENT>if extensions is not Ellipsis and (len(extensions) > <NUM_LIT:0> or len(obj.header.extensions) > <NUM_LIT:0>):<EOL><INDENT>obj.header.extensions = extensions<EOL><DEDENT>return obj<EOL>
to_nifti(obj) yields a Nifti2Image object that is as equivalent as possible to the given object
  obj. If obj is a Nifti2Image already, then it is returned unmolested; other deduction rules
  are described below.

The following options are accepted:
  * like (default: None) may be provided to give a guide for the various header- and meta-data
    that is included in the image. If this is a nifti image object, its meta-data are used; if
    this is a subject, then the meta-data are deduced from the subject's voxel and native
    orientation matrices. All other specific options below override anything deduced from the
    like argument.
  * header (default: None) may be a Nifti1 or Niti2 image header to be used as the nifti header
    or to replace the header in a new image.
  * affine (default: None) may specify the affine transform to be given to the image object.
  * extensions (default: Ellipsis) may specify a nifti extensions object that should be included
    in the header. The default value, Ellipsis, indicates that the extensions should not be
    changed, and that None should be used if extensions are not implied in obj (if, for example,
    obj is a data array rather than an image object with a header already.
  * version (default: 2) may be specified as 1 or 2 for a Nifti1Image or Nifti2Image object,
    respectively.