class_docstr: Template class for volumetric (3D/4D) images
class_docstr_tok: ["Template","class","for","volumetric","(","3D\/4D",")","images"]
docstr: Initialize image
  
  The image is a combination of (array-like, affine matrix, header), with
  optional metadata in `extra`, and filename / file-like objects
  contained in the `file_map` mapping.
  
  Parameters
  ----------
  dataobj : object
     Object containing image data.  It should be some object that returns an
     array from ``np.asanyarray``.  It should have a ``shape`` attribute
     or property
  affine : None or (4,4) array-like
     homogeneous affine giving relationship between voxel coordinates and
     world coordinates.  Affine can also be None.  In this case,
     ``obj.affine`` also returns None, and the affine as written to disk
     will depend on the file format.
  header : None or mapping or header instance, optional
     metadata for this image format
  extra : None or mapping, optional
     metadata to associate with image that cannot be stored in the
     metadata of this image type
  file_map : mapping, optional
     mapping giving file information for this image format
docstr_tok: ["Initialize","image","The","image","is","a","combination","of","(","array-like",",","affine","matrix",",","header",")",",","with","optional","metadata","in","`","extra","`",",","and","filename","\/","file-like","objects","contained","in","the","`","file_map","`","mapping",".","Parameters","--","--","--","--","--","dataobj",":","object","Object","containing","image","data",".","It","should","be","some","object","that","returns","an","array","from","``","np.asanyarray","``",".","It","should","have","a","``","shape","``","attribute","or","property","affine",":","None","or","(","4,4",")","array-like","homogeneous","affine","giving","relationship","between","voxel","coordinates","and","world","coordinates",".","Affine","can","also","be","None",".","In","this","case",",","``","obj.affine","``","also","returns","None",",","and","the","affine","as","written","to","disk","will","depend","on","the","file","format",".","header",":","None","or","mapping","or","header","instance",",","optional","metadata","for","this","image","format","extra",":","None","or","mapping",",","optional","metadata","to","associate","with","image","that","can","not","be","stored","in","the","metadata","of","this","image","type","file_map",":","mapping",",","optional","mapping","giving","file","information","for","this","image","format"]
code: def __init__(
      self,
      dataobj: ArrayLike,
      affine: np.ndarray | None,
      header: FileBasedHeader | ty.Mapping | None = None,
      extra: ty.Mapping | None = None,
      file_map: FileMap | None = None,
  ):
      """Initialize image
  
      The image is a combination of (array-like, affine matrix, header), with
      optional metadata in `extra`, and filename / file-like objects
      contained in the `file_map` mapping.
  
      Parameters
      ----------
      dataobj : object
         Object containing image data.  It should be some object that returns an
         array from ``np.asanyarray``.  It should have a ``shape`` attribute
         or property
      affine : None or (4,4) array-like
         homogeneous affine giving relationship between voxel coordinates and
         world coordinates.  Affine can also be None.  In this case,
         ``obj.affine`` also returns None, and the affine as written to disk
         will depend on the file format.
      header : None or mapping or header instance, optional
         metadata for this image format
      extra : None or mapping, optional
         metadata to associate with image that cannot be stored in the
         metadata of this image type
      file_map : mapping, optional
         mapping giving file information for this image format
      """
      super().__init__(
          dataobj, header=header, extra=extra, file_map=file_map
      )
      if affine is not None:
          # Check that affine is array-like 4,4.  Maybe this is too strict at
          # this abstract level, but so far I think all image formats we know
          # do need 4,4.
          # Copy affine to isolate from environment.  Specify float type to
          # avoid surprising integer rounding when setting values into affine
          affine = np.array(affine, dtype=np.float64, copy=True)
          if not affine.shape == (4, 4):
              raise ValueError("Affine should be shape 4,4")
      self._affine = affine
  
      # if header not specified, get data type from input array
      if header is None:
          if hasattr(dataobj, "dtype"):
              self._header.set_data_dtype(dataobj.dtype)
      # make header correspond with image and affine
      self.update_header()
      self._data_cache = None
  
imports: from __future__ import annotations
  import io
  import typing
  from collections.abc import Sequence
  from typing import Literal
  import numpy
  from .arrayproxy import ArrayLike
  from .casting import sctypes_aliases
  from .dataobj_images import DataobjImage
  from .filebasedimages import FileBasedHeader, FileBasedImage
  from .fileholders import FileMap
  from .fileslice import canonical_slicers
  from .orientations import apply_orientation, inv_ornt_aff
  from .viewers import OrthoSlicer3D
  from .volumeutils import shape_zoom_affine
label_desc: Use image node_id 1 to create a new SpatialImage object from inherited base classes: DataobjImage with example: obj = SpatialImage(dataobj, affine, header, extra, file_map)