def to_mgh(obj, like=None, header=None, affine=None, extra=Ellipsis):
obj0 = obj<EOL>if like is not None:<EOL><INDENT>if isinstance(like, nib.analyze.AnalyzeHeader) or isinstance(obj, fsmgh.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>if extra is Ellipsis: extra = like.extra<EOL><DEDENT>elif isinstance(like, mri.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 (isinstance(obj, fsmgh.MGHImage)):<EOL><INDENT>if ((header is None or obj.header is header) and<EOL>(extra is Ellipsis or extra == obj.extra or (extra is None and len(obj.extra) == <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 = None<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 extra is None: extra = {}<EOL>if isinstance(obj, nib.analyze.SpatialImage):<EOL><INDENT>obj = obj.dataobj<EOL><DEDENT>else:<EOL><INDENT>obj = np.asarray(obj)<EOL><DEDENT>if len(obj.shape) < <NUM_LIT:3>: obj = np.asarray([[obj]])<EOL>if np.issubdtype(obj.dtype, np.integer) and obj.dtype.itemsize > <NUM_LIT:4>:<EOL><INDENT>obj = np.asarray(obj, dtype=np.int32)<EOL><DEDENT>elif np.issubdtype(obj.dtype, np.floating) and obj.dtype.itemsize > <NUM_LIT:4>:<EOL><INDENT>obj = np.asarray(obj, dtype=np.float32)<EOL><DEDENT>obj = fsmgh.MGHImage(obj, affine, header=header, extra=extra)<EOL>return obj<EOL>
to_mgh(obj) yields an MGHmage object that is as equivalent as possible to the given object obj.
  If obj is an MGHImage already and no changes are requested, then it is returned unmolested;
  otherwise, the optional arguments can be used to edit the header, affine, and exta.

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.
  * extra (default: Ellipsis) may specify an extra mapping for storage with the image data; the
    default value Ellipsis indicates that such a mapping should be left as is if it already
    exists in the obj or in the like option and should otherwise be empty.