class_docstr: Implements forming 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.
  This unary term along with a pairwise term (e.g. input image volume) form Equation 5 in the paper,
  which defines an energy to be minimised. Equation 5 can be optimised using an appropriate
  optimisation method (e.g. CRF, GraphCut etc), which is implemented here as an additional transform.
  
  Usage Example::
  
      Compose(
          [
              # unary term maker
              MakeISegUnaryd(
                  image="image",
                  logits="logits",
                  scribbles="label",
                  unary="unary",
                  scribbles_bg_label=2,
                  scribbles_fg_label=3,
              ),
              # optimiser
              ApplyCRFOptimisationd(unary="unary", pairwise="image", post_proc_label="pred"),
          ]
      )
class_docstr_tok: ["Implements","forming","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",".","This","unary","term","along","with","a","pairwise","term","(","e.g",".","input","image","volume",")","form","Equation","5","in","the","paper",",","which","defines","an","energy","to","be","minimised",".","Equation","5","can","be","optimised","using","an","appropriate","optimisation","method","(","e.g",".","CRF",",","GraphCut","etc",")",",","which","is","implemented","here","as","an","additional","transform",".","Usage","Example",":",":","Compose","(","[","#","unary","term","maker","MakeISegUnaryd","(","image=","''","image","''",",","logits=","''","logits","''",",","scribbles=","''","label","''",",","unary=","''","unary","''",",","scribbles_bg_label=2",",","scribbles_fg_label=3",",",")",",","#","optimiser","ApplyCRFOptimisationd","(","unary=","''","unary","''",",","pairwise=","''","image","''",",","post_proc_label=","''","pred","''",")",",","]",")"]
code: def __call__(self, data):
      d = dict(data)
  
      # load scribbles idx from labels_info (if available)
      self._set_scribbles_idx_from_labelinfo(d)
  
      # copy affine meta data from image input
      self._copy_affine(d, self.image, self.unary)
  
      # read relevant terms from data
      logits = self._fetch_data(d, self.logits)
      scribbles = self._fetch_data(d, self.scribbles)
  
      # check if input logits are compatible with ISeg opt
      if logits.shape[0] > 2:
          raise ValueError(
              f"ISeg can only be applied to binary probabilities for now, received {logits.shape[0]}"
          )
  
      # convert logits to probability
      prob = self._normalise_logits(logits, axis=0)
  
      # make ISeg Unaries following Equation 7 from:
      # https://arxiv.org/pdf/1710.04043.pdf
      unary_term = make_iseg_unary(
          prob=prob,
          scribbles=scribbles,
          scribbles_bg_label=self.scribbles_bg_label,
          scribbles_fg_label=self.scribbles_fg_label,
      )
  
      d = self._save_data(d, self.unary, unary_term)
  
      return d
  
imports: import logging
  from copy import deepcopy
  from typing import Optional
  import numpy
  import torch
  from monai.data import MetaTensor
  from monai.networks.blocks import CRF
  from monai.transforms import Transform
  from scipy.special import softmax
  from .utils import make_iseg_unary, make_likelihood_image_gmm, make_likelihood_image_histogram, maxflow
label_desc: Use image node_id 2 for calling the MakeISegUnaryd obj's underlying member method code with example usage: obj.__call__(data) and returns: d