class_docstr: Load image file or files from provided path based on reader.
  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), (nrrd -> NrrdReader), (DICOM file -> 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.
  
  See also:
  
      - tutorial: https://github.com/Project-MONAI/tutorials/blob/master/modules/load_medical_images.ipynb
class_docstr_tok: ["Load","image","file","or","files","from","provided","path","based","on","reader",".","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",")",",","(","nrrd","-",">","NrrdReader",")",",","(","DICOM","file","-",">","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",".","See","also",":","-","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/modules\/load_medical_images.ipynb"]
docstr: Args:
      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"``, ``"PydicomReader"``.
          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.
      image_only: if True return only the image MetaTensor, otherwise return image and header dict.
      dtype: if not None convert the loaded image to this data type.
      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"``.
      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.
  
  Note:
  
      - The transform returns a MetaTensor, unless `set_track_meta(False)` has been used, in which case, a
        `torch.Tensor` will be returned.
      - 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.
docstr_tok: ["Args",":","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","''","``",",","``","``","PydicomReader","''","``",".","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",".","image_only",":","if","True","return","only","the","image","MetaTensor",",","otherwise","return","image","and","header","dict",".","dtype",":","if","not","None","convert","the","loaded","image","to","this","data","type",".","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","''","``",".","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",".","Note",":","-","The","transform","returns","a","MetaTensor",",","unless","`","set_track_meta","(","False",")","`","has","been","used",",","in","which","case",",","a","`","torch.Tensor","`","will","be","returned",".","-","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","."]
code: def __init__(
      self,
      reader=None,
      image_only: bool = True,
      dtype: DtypeLike | None = np.float32,
      ensure_channel_first: bool = False,
      simple_keys: bool = False,
      prune_meta_pattern: str | None = None,
      prune_meta_sep: str = ".",
      expanduser: bool = True,
      *args,
      **kwargs,
  ) -> None:
      """
      Args:
          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"``, ``"PydicomReader"``.
              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.
          image_only: if True return only the image MetaTensor, otherwise return image and header dict.
          dtype: if not None convert the loaded image to this data type.
          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"``.
          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.
  
      Note:
  
          - The transform returns a MetaTensor, unless `set_track_meta(False)` has been used, in which case, a
            `torch.Tensor` will be returned.
          - 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.
  
      """
  
      self.auto_select = reader is None
      self.image_only = image_only
      self.dtype = dtype
      self.ensure_channel_first = ensure_channel_first
      self.simple_keys = simple_keys
      self.pattern = prune_meta_pattern
      self.sep = prune_meta_sep
      self.expanduser = expanduser
  
      self.readers: list[ImageReader] = []
      for r in SUPPORTED_READERS:  # set predefined readers as default
          try:
              self.register(SUPPORTED_READERS[r](*args, **kwargs))
          except OptionalImportError:
              logging.getLogger(self.__class__.__name__).debug(
                  f"required package for reader {r} is not installed, or the version doesn't match requirement."
              )
          except (
              TypeError
          ):  # the reader doesn't have the corresponding args/kwargs
              logging.getLogger(self.__class__.__name__).debug(
                  f"{r} is not supported with the given parameters {args} {kwargs}."
              )
              self.register(SUPPORTED_READERS[r]())
      if reader is None:
          return  # no user-specified reader, no need to register
  
      for _r in ensure_tuple(reader):
          if isinstance(_r, str):
              the_reader, has_built_in = optional_import(
                  "monai.data", name=f"{_r}"
              )  # search built-in
              if not has_built_in:
                  the_reader = locate(f"{_r}")  # search dotted path
              if the_reader is None:
                  the_reader = look_up_option(
                      _r.lower(), SUPPORTED_READERS
                  )
              try:
                  self.register(the_reader(*args, **kwargs))
              except OptionalImportError:
                  warnings.warn(
                      f"required package for reader {_r} is not installed, or the version doesn't match requirement."
                  )
              except (
                  TypeError
              ):  # the reader doesn't have the corresponding args/kwargs
                  warnings.warn(
                      f"{_r} is not supported with the given parameters {args} {kwargs}."
                  )
                  self.register(the_reader())
          elif inspect.isclass(_r):
              self.register(_r(*args, **kwargs))
          else:
              self.register(
                  _r
              )  # reader instance, ignoring the constructor args/kwargs
      return
  
imports: from __future__ import annotations
  import inspect
  import logging
  import sys
  import traceback
  import warnings
  from collections.abc import Sequence
  from pathlib import Path
  from pydoc import locate
  from typing import Callable
  import numpy
  import torch
  from monai.config import DtypeLike, NdarrayOrTensor, PathLike
  from monai.data import image_writer
  from monai.data.folder_layout import FolderLayout, FolderLayoutBase, default_name_formatter
  from monai.data.image_reader import ImageReader, ITKReader, NibabelReader, NrrdReader, NumpyReader, PILReader, PydicomReader
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import is_no_channel
  from monai.transforms.transform import Transform
  from monai.transforms.utility.array import EnsureChannelFirst
  from monai.utils import GridSamplePadMode
  from monai.utils import ImageMetaKey
  from monai.utils import OptionalImportError, convert_to_dst_type, ensure_tuple, look_up_option, optional_import
label_desc: Use image node_id 1 to create a new LoadImage object from inherited base classes: Transform with example: obj = LoadImage(reader, image_only, dtype, ensure_channel_first, simple_keys, prune_meta_pattern, prune_meta_sep, expanduser)