class_docstr: Only calculate the unknown region if trimap provided.
  Refer to: Refer to: https://github.com/open-mlab/mmediting/blob/master/mmedit/core/evaluation/metrics.py
docstr: update metric.
  Args:
      pred (np.ndarray): The value range is [0., 1.].
      gt (np.ndarray): The value range is [0, 255].
      trimap (np.ndarray, optional)L The value is in {0, 128, 255}. Default: None.
      step (float, optional): Step of threshold when computing intersection between
      `gt` and `pred`. Default: 0.1.
docstr_tok: ["update","metric",".","Args",":","pred","(","np.ndarray",")",":","The","value","range","is","[","0.",",","1.","]",".","gt","(","np.ndarray",")",":","The","value","range","is","[","0",",","255","]",".","trimap","(","np.ndarray",",","optional",")","L","The","value","is","in","{","0",",","128",",","255","}",".","Default",":","None",".","step","(","float",",","optional",")",":","Step","of","threshold","when","computing","intersection","between","`","gt","`","and","`","pred","`",".","Default",":","0.1","."]
code: def update(self, pred, gt, trimap=None, step=0.1):
      """
      update metric.
      Args:
          pred (np.ndarray): The value range is [0., 1.].
          gt (np.ndarray): The value range is [0, 255].
          trimap (np.ndarray, optional)L The value is in {0, 128, 255}. Default: None.
          step (float, optional): Step of threshold when computing intersection between
          `gt` and `pred`. Default: 0.1.
      """
      if trimap is None:
          trimap = np.ones_like(gt) * 128
      if not (pred.shape == gt.shape == trimap.shape):
          raise ValueError(
              "The shape of `pred`, `gt` and `trimap` should be equal. "
              "but they are {}, {} and {}".format(
                  pred.shape, gt.shape, trimap.shape
              )
          )
      pred[trimap == 0] = 0
      pred[trimap == 255] = 255
  
      gt = gt.squeeze()
      pred = pred.squeeze()
      gt = gt.astype(np.float32) / 255
      pred = pred.astype(np.float32) / 255
  
      thresh_steps = np.arange(0, 1 + step, step)
      round_down_map = -np.ones_like(gt)
      for i in range(1, len(thresh_steps)):
          gt_thresh = gt >= thresh_steps[i]
          pred_thresh = pred >= thresh_steps[i]
          intersection = (gt_thresh & pred_thresh).astype(np.uint8)
  
          # connected components
          _, output, stats, _ = cv2.connectedComponentsWithStats(
              intersection, connectivity=4
          )
          # start from 1 in dim 0 to exclude background
          size = stats[1:, -1]
  
          # largest connected component of the intersection
          omega = np.zeros_like(gt)
          if len(size) != 0:
              max_id = np.argmax(size)
              # plus one to include background
              omega[output == max_id + 1] = 1
  
          mask = (round_down_map == -1) & (omega == 0)
          round_down_map[mask] = thresh_steps[i - 1]
      round_down_map[round_down_map == -1] = 1
  
      gt_diff = gt - round_down_map
      pred_diff = pred - round_down_map
      # only calculate difference larger than or equal to 0.15
      gt_phi = 1 - gt_diff * (gt_diff >= 0.15)
      pred_phi = 1 - pred_diff * (pred_diff >= 0.15)
  
      conn_diff = np.sum(np.abs(gt_phi - pred_phi) * (trimap == 128))
  
      conn_diff /= 1000
      self.conn_diffs += conn_diff
      self.count += 1
  
      return conn_diff
  
imports: import cv2
  import numpy
  from scipy.ndimage.filters import convolve
  from scipy.special import gamma
  from skimage.measure import label
label_desc: Use image node_id 2 for calling the Conn obj's underlying member method code with example usage: obj.update(pred, gt, trimap, step) and returns: conn_diff