docstr: Initialize anchor image sampler.
  
  Parameters
  ----------
  predictor
      A callable that takes a `numpy` array of `N` data points as inputs and returns `N` outputs.
  segmentation_fn
      Function used to segment the images. The segmentation function is expected to return a segmentation mask
      containing all integer values from `0` to `K-1`, where `K` is the number of image segments (superpixels).
  image
      Image to be explained.
  images_background
      Images to overlay superpixels on.
  p_sample
      Probability for a pixel to be represented by the average value of its superpixel.
  n_covered_ex
      How many examples where anchors apply to store for each anchor sampled during search
      (both examples where prediction on samples agrees/disagrees with `desired_label` are stored).
docstr_tok: ["Initialize","anchor","image","sampler",".","Parameters","--","--","--","--","--","predictor","A","callable","that","takes","a","`","numpy","`","array","of","`","N","`","data","points","as","inputs","and","returns","`","N","`","outputs",".","segmentation_fn","Function","used","to","segment","the","images",".","The","segmentation","function","is","expected","to","return","a","segmentation","mask","containing","all","integer","values","from","`","0","`","to","`","K-1","`",",","where","`","K","`","is","the","number","of","image","segments","(","superpixels",")",".","image","Image","to","be","explained",".","images_background","Images","to","overlay","superpixels","on",".","p_sample","Probability","for","a","pixel","to","be","represented","by","the","average","value","of","its","superpixel",".","n_covered_ex","How","many","examples","where","anchors","apply","to","store","for","each","anchor","sampled","during","search","(","both","examples","where","prediction","on","samples","agrees\/disagrees","with","`","desired_label","`","are","stored",")","."]
code: def __init__(
      self,
      predictor: Callable,
      segmentation_fn: Callable,
      custom_segmentation: bool,
      image: np.ndarray,
      images_background: Optional[np.ndarray] = None,
      p_sample: float = 0.5,
      n_covered_ex: int = 10,
  ):
      """
      Initialize anchor image sampler.
  
      Parameters
      ----------
      predictor
          A callable that takes a `numpy` array of `N` data points as inputs and returns `N` outputs.
      segmentation_fn
          Function used to segment the images. The segmentation function is expected to return a segmentation mask
          containing all integer values from `0` to `K-1`, where `K` is the number of image segments (superpixels).
      image
          Image to be explained.
      images_background
          Images to overlay superpixels on.
      p_sample
          Probability for a pixel to be represented by the average value of its superpixel.
      n_covered_ex
          How many examples where anchors apply to store for each anchor sampled during search
          (both examples where prediction on samples agrees/disagrees with `desired_label` are stored).
      """
      self.predictor = predictor
      self.segmentation_fn = segmentation_fn
      self.custom_segmentation = custom_segmentation
      self.image = image
      self.images_background = images_background
      self.n_covered_ex = n_covered_ex
      self.p_sample = p_sample
      self.segments = self.generate_superpixels(image)
      self.segment_labels = list(np.unique(self.segments))
      self.instance_label = self.predictor(image[np.newaxis, ...])[0]
  
imports: import copy
  import logging
  from functools import partial
  from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
  import numpy
  from skimage.segmentation import felzenszwalb, quickshift, slic
  from alibi.api.defaults import DEFAULT_DATA_ANCHOR_IMG, DEFAULT_META_ANCHOR
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.exceptions import PredictorCallError, PredictorReturnTypeError
  from alibi.utils.wrappers import ArgmaxTransformer
  from .anchor_base import AnchorBaseBeam
  from .anchor_explanation import AnchorExplanation
label_desc: Use image node_id 1 to create a new AnchorImageSampler object  with example: obj = AnchorImageSampler(predictor, segmentation_fn, custom_segmentation, image, images_background, p_sample, n_covered_ex)