code: def make_iseg_unary(
      prob,
      scribbles,
      scribbles_bg_label=2,
      scribbles_fg_label=3,
  ):
      """
      Implements ISeg unary term from the following paper:
      Wang, Guotai, et al. "Interactive medical image segmentation using deep learning with image-specific fine tuning."
      IEEE transactions on medical imaging 37.7 (2018): 1562-1573. (preprint: https://arxiv.org/pdf/1710.04043.pdf)
      ISeg unary term is constructed using Equation 7 on page 4 of the above mentioned paper.
      """
  
      # fetch the data for probabilities and scribbles
      prob_shape = list(prob.shape)
      scrib_shape = list(scribbles.shape)
  
      # check if they have compatible shapes
      if prob_shape[1:] != scrib_shape[1:]:
          raise ValueError("shapes for prob and scribbles dont match")
  
      # expected input shape is [1, X, Y, [Z]], exit if first dimension doesnt comply
      if scrib_shape[0] != 1:
          raise ValueError(
              f"scribbles should have single channel first, received {scrib_shape[0]}"
          )
  
      # unfold a single prob for background into bg/fg prob (if needed)
      if prob_shape[0] == 1:
          prob = np.concatenate([prob, 1.0 - prob], axis=0)
  
      mask = np.concatenate(
          [
              scribbles == scribbles_bg_label,
              scribbles == scribbles_fg_label,
          ],
          axis=0,
      )
  
      # issue a warning if no scribbles detected, the algorithm will still work
      # just need to inform user/researcher - in case it is unexpected
      if not np.any(mask[0, ...]):
          logging.info(
              "warning: no background scribbles received with label {}, available in scribbles {}".format(
                  scribbles_bg_label, np.unique(scribbles)
              )
          )
  
      if not np.any(mask[1, ...]):
          logging.info(
              "warning: no foreground scribbles received with label {}, available in scribbles {}".format(
                  scribbles_fg_label, np.unique(scribbles)
              )
          )
  
      # copy probabilities
      unary_term = np.copy(prob)
  
      # for numerical stability, get rid of zeros
      eps = get_eps(unary_term)
  
      equal_term = 1.0 - eps
      no_equal_term = eps
  
      # update unary with Equation 7
      unary_term[mask] = equal_term
      mask = np.flip(mask, axis=0)
      unary_term[mask] = no_equal_term
  
      return unary_term
  
file_path: MONAILabel/monailabel/scribbles/utils.py
imports: import logging
  import numpy
  import numpymaxflow
  import torch
  from monai.networks.layers import GaussianMixtureModel
label_desc: Use image node_id 3 for calling a global function with example usage: make_iseg_unary(prob, scribbles, scribbles_bg_label, scribbles_fg_label) and returns: unary_term