class_docstr: Create image instance according to number of dimensions
  specified in image headers.
class_docstr_tok: ["Create","image","instance","according","to","number","of","dimensions","specified","in","image","headers","."]
docstr: Read image headers and create image instance.
  
  :param file_path: a file path or a sequence of file paths
  :param kwargs: output properties for transforming the image data
      array into a desired format
  :return: an image instance
code: def create_instance(cls, file_path, **kwargs):
      """
      Read image headers and create image instance.
  
      :param file_path: a file path or a sequence of file paths
      :param kwargs: output properties for transforming the image data
          array into a desired format
      :return: an image instance
      """
      if file_path is None:
          tf.logging.fatal(
              "No file_path provided, "
              "please check input sources in config file"
          )
          raise ValueError
  
      ndims = 0
      image_type = None
      home_folder = NiftyNetGlobalConfig().get_niftynet_home_folder()
      try:
          file_path = resolve_file_name(file_path, (".", home_folder))
          if os.path.isfile(file_path):
              loader = kwargs.get("loader", None) or None
              ndims = misc.infer_ndims_from_file(file_path, loader)
              image_type = cls.INSTANCE_DICT.get(ndims, None)
      except (TypeError, IOError, AttributeError):
          pass
  
      if image_type is None:
          try:
              file_path = [
                  resolve_file_name(path, (".", home_folder))
                  for path in file_path
              ]
              loader = kwargs.get("loader", None) or (None,)
              ndims = misc.infer_ndims_from_file(
                  file_path[0], loader[0]
              )
              ndims = ndims + (1 if len(file_path) > 1 else 0)
              image_type = cls.INSTANCE_DICT.get(ndims, None)
          except (AssertionError, TypeError, IOError, AttributeError):
              tf.logging.fatal("Could not load file: %s", file_path)
              raise IOError
      if image_type is None:
          tf.logging.fatal(
              "Not supported image type from:\n%s", file_path
          )
          raise NotImplementedError(
              "unrecognised spatial rank {}".format(ndims)
          )
      return image_type(file_path, **kwargs)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from abc import ABCMeta, abstractmethod
  import nibabel
  import numpy
  import tensorflow
  from six import with_metaclass, string_types
  import niftynet.io.misc_io
  from niftynet.io.image_loader import load_image_obj
  from niftynet.io.misc_io import resolve_file_name, dtype_casting
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
label_desc: Use image node_id 1 for calling the ImageFactory obj's underlying member method code with example usage: obj.create_instance(cls, file_path) and returns: image_type