class_docstr: Dictionary-based wrapper of :py:class:`monai.transforms.LoadImage`,
  It can load both image data and metadata. When loading a list of files in one key,
  the arrays will be stacked and a new dimension will be added as the first dimension
  In this case, the metadata of the first image will be used to represent the stacked result.
  The affine transform of all the stacked images should be same.
  The output metadata field will be created as ``meta_keys`` or ``key_{meta_key_postfix}``.
  
  If reader is not specified, this class automatically chooses readers
  based on the supported suffixes and in the following order:
  
      - User-specified reader at runtime when calling this loader.
      - User-specified reader in the constructor of `LoadImage`.
      - Readers from the last to the first in the registered list.
      - Current default readers: (nii, nii.gz -> NibabelReader), (png, jpg, bmp -> PILReader),
        (npz, npy -> NumpyReader), (dcm, DICOM series and others -> ITKReader).
  
  Please note that for png, jpg, bmp, and other 2D formats, readers by default swap axis 0 and 1 after
  loading the array with ``reverse_indexing`` set to ``True`` because the spatial axes definition
  for non-medical specific file formats is different from other common medical packages.
  
  Note:
  
      - If `reader` is specified, the loader will attempt to use the specified readers and the default supported
        readers. This might introduce overheads when handling the exceptions of trying the incompatible loaders.
        In this case, it is therefore recommended setting the most appropriate reader as
        the last item of the `reader` parameter.
  
  See also:
  
      - tutorial: https://github.com/Project-MONAI/tutorials/blob/master/modules/load_medical_images.ipynb
class_docstr_tok: ["Dictionary-based","wrapper","of",":","py",":","class",":","`","monai.transforms.LoadImage","`",",","It","can","load","both","image","data","and","metadata",".","When","loading","a","list","of","files","in","one","key",",","the","arrays","will","be","stacked","and","a","new","dimension","will","be","added","as","the","first","dimension","In","this","case",",","the","metadata","of","the","first","image","will","be","used","to","represent","the","stacked","result",".","The","affine","transform","of","all","the","stacked","images","should","be","same",".","The","output","metadata","field","will","be","created","as","``","meta_keys","``","or","``","key_","{","meta_key_postfix","}","``",".","If","reader","is","not","specified",",","this","class","automatically","chooses","readers","based","on","the","supported","suffixes","and","in","the","following","order",":","-","User-specified","reader","at","runtime","when","calling","this","loader",".","-","User-specified","reader","in","the","constructor","of","`","LoadImage","`",".","-","Readers","from","the","last","to","the","first","in","the","registered","list",".","-","Current","default","readers",":","(","nii",",","nii.gz","-",">","NibabelReader",")",",","(","png",",","jpg",",","bmp","-",">","PILReader",")",",","(","npz",",","npy","-",">","NumpyReader",")",",","(","dcm",",","DICOM","series","and","others","-",">","ITKReader",")",".","Please","note","that","for","png",",","jpg",",","bmp",",","and","other","2D","formats",",","readers","by","default","swap","axis","0","and","1","after","loading","the","array","with","``","reverse_indexing","``","set","to","``","True","``","because","the","spatial","axes","definition","for","non-medical","specific","file","formats","is","different","from","other","common","medical","packages",".","Note",":","-","If","`","reader","`","is","specified",",","the","loader","will","attempt","to","use","the","specified","readers","and","the","default","supported","readers",".","This","might","introduce","overheads","when","handling","the","exceptions","of","trying","the","incompatible","loaders",".","In","this","case",",","it","is","therefore","recommended","setting","the","most","appropriate","reader","as","the","last","item","of","the","`","reader","`","parameter",".","See","also",":","-","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/modules\/load_medical_images.ipynb"]
docstr: Args:
      keys: keys of the corresponding items to be transformed.
          See also: :py:class:`monai.transforms.compose.MapTransform`
      reader: reader to load image file and metadata
          - if `reader` is None, a default set of `SUPPORTED_READERS` will be used.
          - if `reader` is a string, it's treated as a class name or dotted path
          (such as ``"monai.data.ITKReader"``), the supported built-in reader classes are
          ``"ITKReader"``, ``"NibabelReader"``, ``"NumpyReader"``.
          a reader instance will be constructed with the `*args` and `**kwargs` parameters.
          - if `reader` is a reader class/instance, it will be registered to this loader accordingly.
      dtype: if not None, convert the loaded image data to this data type.
      meta_keys: explicitly indicate the key to store the corresponding metadata dictionary.
          the metadata is a dictionary object which contains: filename, original_shape, etc.
          it can be a sequence of string, map to the `keys`.
          if None, will try to construct meta_keys by `key_{meta_key_postfix}`.
      meta_key_postfix: if meta_keys is None, use `key_{postfix}` to store the metadata of the nifti image,
          default is `meta_dict`. The metadata is a dictionary object.
          For example, load nifti file for `image`, store the metadata into `image_meta_dict`.
      overwriting: whether allow overwriting existing metadata of same key.
          default is False, which will raise exception if encountering existing key.
      image_only: if True return dictionary containing just only the image volumes, otherwise return
          dictionary containing image data array and header dict per input key.
      ensure_channel_first: if `True` and loaded both image array and metadata, automatically convert
          the image array shape to `channel first`. default to `False`.
      simple_keys: whether to remove redundant metadata keys, default to False for backward compatibility.
      prune_meta_pattern: combined with `prune_meta_sep`, a regular expression used to match and prune keys
          in the metadata (nested dictionary), default to None, no key deletion.
      prune_meta_sep: combined with `prune_meta_pattern`, used to match and prune keys
          in the metadata (nested dictionary). default is ".", see also :py:class:`monai.transforms.DeleteItemsd`.
          e.g. ``prune_meta_pattern=".*_code$", prune_meta_sep=" "`` removes meta keys that ends with ``"_code"``.
      allow_missing_keys: don't raise exception if key is missing.
      expanduser: if True cast filename to Path and call .expanduser on it, otherwise keep filename as is.
      args: additional parameters for reader if providing a reader name.
      kwargs: additional parameters for reader if providing a reader name.
docstr_tok: ["Args",":","keys",":","keys","of","the","corresponding","items","to","be","transformed",".","See","also",":",":","py",":","class",":","`","monai.transforms.compose.MapTransform","`","reader",":","reader","to","load","image","file","and","metadata","-","if","`","reader","`","is","None",",","a","default","set","of","`","SUPPORTED_READERS","`","will","be","used",".","-","if","`","reader","`","is","a","string",",","it","'s","treated","as","a","class","name","or","dotted","path","(","such","as","``","``","monai.data.ITKReader","''","``",")",",","the","supported","built-in","reader","classes","are","``","``","ITKReader","''","``",",","``","``","NibabelReader","''","``",",","``","``","NumpyReader","''","``",".","a","reader","instance","will","be","constructed","with","the","`","*","args","`","and","`","*","*","kwargs","`","parameters",".","-","if","`","reader","`","is","a","reader","class\/instance",",","it","will","be","registered","to","this","loader","accordingly",".","dtype",":","if","not","None",",","convert","the","loaded","image","data","to","this","data","type",".","meta_keys",":","explicitly","indicate","the","key","to","store","the","corresponding","metadata","dictionary",".","the","metadata","is","a","dictionary","object","which","contains",":","filename",",","original_shape",",","etc",".","it","can","be","a","sequence","of","string",",","map","to","the","`","keys","`",".","if","None",",","will","try","to","construct","meta_keys","by","`","key_","{","meta_key_postfix","}","`",".","meta_key_postfix",":","if","meta_keys","is","None",",","use","`","key_","{","postfix","}","`","to","store","the","metadata","of","the","nifti","image",",","default","is","`","meta_dict","`",".","The","metadata","is","a","dictionary","object",".","For","example",",","load","nifti","file","for","`","image","`",",","store","the","metadata","into","`","image_meta_dict","`",".","overwriting",":","whether","allow","overwriting","existing","metadata","of","same","key",".","default","is","False",",","which","will","raise","exception","if","encountering","existing","key",".","image_only",":","if","True","return","dictionary","containing","just","only","the","image","volumes",",","otherwise","return","dictionary","containing","image","data","array","and","header","dict","per","input","key",".","ensure_channel_first",":","if","`","True","`","and","loaded","both","image","array","and","metadata",",","automatically","convert","the","image","array","shape","to","`","channel","first","`",".","default","to","`","False","`",".","simple_keys",":","whether","to","remove","redundant","metadata","keys",",","default","to","False","for","backward","compatibility",".","prune_meta_pattern",":","combined","with","`","prune_meta_sep","`",",","a","regular","expression","used","to","match","and","prune","keys","in","the","metadata","(","nested","dictionary",")",",","default","to","None",",","no","key","deletion",".","prune_meta_sep",":","combined","with","`","prune_meta_pattern","`",",","used","to","match","and","prune","keys","in","the","metadata","(","nested","dictionary",")",".","default","is","``",".","``",",","see","also",":","py",":","class",":","`","monai.transforms.DeleteItemsd","`",".","e.g",".","``","prune_meta_pattern=","''",".","*","_code","$","''",",","prune_meta_sep=","''","``","``","removes","meta","keys","that","ends","with","``","``","_code","''","``",".","allow_missing_keys",":","do","n't","raise","exception","if","key","is","missing",".","expanduser",":","if","True","cast","filename","to","Path","and","call",".expanduser","on","it",",","otherwise","keep","filename","as","is",".","args",":","additional","parameters","for","reader","if","providing","a","reader","name",".","kwargs",":","additional","parameters","for","reader","if","providing","a","reader","name","."]
code: def __init__(
      self,
      keys: KeysCollection,
      reader: type[ImageReader] | str | None = None,
      dtype: DtypeLike = np.float32,
      meta_keys: KeysCollection | None = None,
      meta_key_postfix: str = DEFAULT_POST_FIX,
      overwriting: bool = False,
      image_only: bool = True,
      ensure_channel_first: bool = False,
      simple_keys: bool = False,
      prune_meta_pattern: str | None = None,
      prune_meta_sep: str = ".",
      allow_missing_keys: bool = False,
      expanduser: bool = True,
      *args,
      **kwargs,
  ) -> None:
      """
      Args:
          keys: keys of the corresponding items to be transformed.
              See also: :py:class:`monai.transforms.compose.MapTransform`
          reader: reader to load image file and metadata
              - if `reader` is None, a default set of `SUPPORTED_READERS` will be used.
              - if `reader` is a string, it's treated as a class name or dotted path
              (such as ``"monai.data.ITKReader"``), the supported built-in reader classes are
              ``"ITKReader"``, ``"NibabelReader"``, ``"NumpyReader"``.
              a reader instance will be constructed with the `*args` and `**kwargs` parameters.
              - if `reader` is a reader class/instance, it will be registered to this loader accordingly.
          dtype: if not None, convert the loaded image data to this data type.
          meta_keys: explicitly indicate the key to store the corresponding metadata dictionary.
              the metadata is a dictionary object which contains: filename, original_shape, etc.
              it can be a sequence of string, map to the `keys`.
              if None, will try to construct meta_keys by `key_{meta_key_postfix}`.
          meta_key_postfix: if meta_keys is None, use `key_{postfix}` to store the metadata of the nifti image,
              default is `meta_dict`. The metadata is a dictionary object.
              For example, load nifti file for `image`, store the metadata into `image_meta_dict`.
          overwriting: whether allow overwriting existing metadata of same key.
              default is False, which will raise exception if encountering existing key.
          image_only: if True return dictionary containing just only the image volumes, otherwise return
              dictionary containing image data array and header dict per input key.
          ensure_channel_first: if `True` and loaded both image array and metadata, automatically convert
              the image array shape to `channel first`. default to `False`.
          simple_keys: whether to remove redundant metadata keys, default to False for backward compatibility.
          prune_meta_pattern: combined with `prune_meta_sep`, a regular expression used to match and prune keys
              in the metadata (nested dictionary), default to None, no key deletion.
          prune_meta_sep: combined with `prune_meta_pattern`, used to match and prune keys
              in the metadata (nested dictionary). default is ".", see also :py:class:`monai.transforms.DeleteItemsd`.
              e.g. ``prune_meta_pattern=".*_code$", prune_meta_sep=" "`` removes meta keys that ends with ``"_code"``.
          allow_missing_keys: don't raise exception if key is missing.
          expanduser: if True cast filename to Path and call .expanduser on it, otherwise keep filename as is.
          args: additional parameters for reader if providing a reader name.
          kwargs: additional parameters for reader if providing a reader name.
      """
      super().__init__(keys, allow_missing_keys)
      self._loader = LoadImage(
          reader,
          image_only,
          dtype,
          ensure_channel_first,
          simple_keys,
          prune_meta_pattern,
          prune_meta_sep,
          expanduser,
          *args,
          **kwargs,
      )
      if not isinstance(meta_key_postfix, str):
          raise TypeError(
              f"meta_key_postfix must be a str but is {type(meta_key_postfix).__name__}."
          )
      self.meta_keys = (
          ensure_tuple_rep(None, len(self.keys))
          if meta_keys is None
          else ensure_tuple(meta_keys)
      )
      if len(self.keys) != len(self.meta_keys):
          raise ValueError(
              f"meta_keys should have the same length as keys, got {len(self.keys)} and {len(self.meta_keys)}."
          )
      self.meta_key_postfix = ensure_tuple_rep(
          meta_key_postfix, len(self.keys)
      )
      self.overwriting = overwriting
  
imports: from __future__ import annotations
  from pathlib import Path
  from typing import Callable
  import numpy
  import monai
  from monai.config import DtypeLike, KeysCollection
  from monai.data import image_writer
  from monai.data.image_reader import ImageReader
  from monai.transforms.io.array import LoadImage, SaveImage
  from monai.transforms.transform import MapTransform, Transform
  from monai.utils import GridSamplePadMode, ensure_tuple, ensure_tuple_rep
  from monai.utils.enums import PostFix
label_desc: Use image node_id 1 to create a new LoadImaged object from inherited base classes: MapTransform with example: obj = LoadImaged(keys, reader, dtype, meta_keys, meta_key_postfix, overwriting, image_only, ensure_channel_first, simple_keys, prune_meta_pattern, prune_meta_sep, allow_missing_keys, expanduser)