class_docstr: This masks out image regions with blurring or inpainting.
      
class_docstr_tok: ["This","masks","out","image","regions","with","blurring","or","inpainting","."]
code: def __call__(self, mask, x):
      if safe_isinstance(x, "torch.Tensor"):
          x = x.cpu().numpy()
  
      if np.prod(x.shape) != np.prod(self.input_shape):
          raise DimensionError(
              "The length of the image to be masked must match the shape given in the "
              + "ImageMasker constructor: "
              + " * ".join([str(i) for i in x.shape])
              + " != "
              + " * ".join([str(i) for i in self.input_shape])
          )
  
      # unwrap single element lists (which are how single input models look in multi-input format)
      if isinstance(x, list) and len(x) == 1:
          x = x[0]
  
      # we preserve flattened inputs as flattened and full-shaped inputs as their original shape
      in_shape = x.shape
      if len(x.shape) > 1:
          x = x.ravel()
  
      # if mask is not given then we mask the whole image
      if mask is None:
          mask = np.zeros(np.prod(x.shape), dtype=bool)
  
      if isinstance(self.mask_value, str):
          if self.blur_kernel is not None:
              if self.last_xid != id(x):
                  self._blur_value_cache = cv2.blur(
                      x.reshape(self.input_shape), self.blur_kernel
                  ).ravel()
                  self.last_xid = id(x)
              out = x.copy()
              out[~mask] = self._blur_value_cache[~mask]
  
          elif self.mask_value == "inpaint_telea":
              out = self.inpaint(x, ~mask, "INPAINT_TELEA")
          elif self.mask_value == "inpaint_ns":
              out = self.inpaint(x, ~mask, "INPAINT_NS")
      else:
          out = x.copy()
          out[~mask] = self.mask_value[~mask]
  
      return (out.reshape(1, *in_shape),)
  
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 2 for calling the Image obj's underlying member method code with example usage: obj.__call__(mask, x) and returns: out