class_docstr: This masks out image regions with blurring or inpainting.
      
class_docstr_tok: ["This","masks","out","image","regions","with","blurring","or","inpainting","."]
docstr: Build a new Image masker with the given masking value.
  Parameters
  ----------
  mask_value : np.array, "blur(kernel_xsize, kernel_xsize)", "inpaint_telea", or "inpaint_ns"
      The value used to mask hidden regions of the image.
  shape : None or tuple
      If the mask_value is an auto-generated masker instead of a dataset then the input
      image shape needs to be provided.
docstr_tok: ["Build","a","new","Image","masker","with","the","given","masking","value",".","Parameters","--","--","--","--","--","mask_value",":","np.array",",","``","blur","(","kernel_xsize",",","kernel_xsize",")","''",",","``","inpaint_telea","''",",","or","``","inpaint_ns","''","The","value","used","to","mask","hidden","regions","of","the","image",".","shape",":","None","or","tuple","If","the","mask_value","is","an","auto-generated","masker","instead","of","a","dataset","then","the","input","image","shape","needs","to","be","provided","."]
code: def __init__(self, mask_value, shape=None):
      """Build a new Image masker with the given masking value.
      Parameters
      ----------
      mask_value : np.array, "blur(kernel_xsize, kernel_xsize)", "inpaint_telea", or "inpaint_ns"
          The value used to mask hidden regions of the image.
      shape : None or tuple
          If the mask_value is an auto-generated masker instead of a dataset then the input
          image shape needs to be provided.
      """
      if shape is None:
          if isinstance(mask_value, str):
              raise TypeError(
                  "When the mask_value is a string the shape parameter must be given!"
              )
          self.input_shape = (
              mask_value.shape
          )  # the (1,) is because we only return a single masked sample to average over
      else:
          self.input_shape = shape
  
      self.input_mask_value = mask_value
  
      # This is the shape of the masks we expect
      self.shape = (
          1,
          np.prod(self.input_shape),
      )  # the (1, ...) is because we only return a single masked sample to average over
  
      self.image_data = True
  
      self.blur_kernel = None
      self._blur_value_cache = None
      if issubclass(type(mask_value), np.ndarray):
          self.mask_value = mask_value.flatten()
      elif isinstance(mask_value, str):
          assert_import("cv2")
          self.mask_value = mask_value
          if mask_value.startswith("blur("):
              self.blur_kernel = tuple(
                  map(int, mask_value[5:-1].split(","))
              )
      else:
          self.mask_value = (
              np.ones(self.input_shape).flatten() * mask_value
          )
      self.build_partition_tree()
  
      # note if this masker can use different background for different samples
      self.fixed_background = not isinstance(self.mask_value, str)
  
      # self.scratch_mask = np.zeros(self.input_shape[:-1], dtype=bool)
      self.last_xid = None
  
      # flag that we return outputs that will not get changed by later masking calls
      self.immutable_outputs = True
  
file_path: shap/shap/maskers/_image.py
imports: import heapq
  import warnings
  import numba.typed
  import numpy
  from numba import njit
  from numba.core.errors import NumbaPendingDeprecationWarning
  from .._serializable import Deserializer, Serializer
  from ..utils import assert_import, record_import_error, safe_isinstance
  from ..utils._exceptions import DimensionError
  from ._masker import Masker
label_desc: Use image node_id 1 to create a new Image object from inherited base classes: Masker with example: obj = Image(mask_value, shape)