code: def learn_and_apply_gmm_monai(
      image, scrib, scribbles_bg_label, scribbles_fg_label, num_mixtures
  ):
      # this function is limited to binary segmentation at the moment
      n_classes = 2
  
      # make trimap
      trimap = np.zeros_like(scrib).astype(np.int32)
  
      # fetch anything that is not scribbles
      not_scribbles = ~(
          (scrib == scribbles_bg_label) | (scrib == scribbles_fg_label)
      )
  
      # set these to -1 == unused
      trimap[not_scribbles] = -1
  
      # set background scrib to 0
      trimap[scrib == scribbles_bg_label] = 0
      # set foreground scrib to 1
      trimap[scrib == scribbles_fg_label] = 1
  
      # add empty channel to image and scrib to be inline with pytorch layout
      image = np.expand_dims(image, axis=0)
      trimap = np.expand_dims(trimap, axis=0)
  
      # transfer everything to pytorch tensor
      # we use CUDA as GMM from MONAI is only available on CUDA atm (29/04/2022)
      # if no cuda device found, then exit now
      if not torch.cuda.is_available():
          raise OSError(
              "Unable to find CUDA device, check your torch/monai installation"
          )
  
      from torch.utils.cpp_extension import CUDA_HOME
  
      if not CUDA_HOME:
          raise OSError(
              "Unable to find CUDA_HOME.  Install CUDA Toolkit: https://developer.nvidia.com/cuda-downloads\n"
              "Example for Ubuntu: \n"
              "  1) wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda_11.7.0_515.43.04_linux.run\n"
              "  2) sudo sh cuda_11.7.0_515.43.04_linux.run --silent --toolkit"
          )
  
      device = "cuda"
      image = torch.from_numpy(image).type(torch.float32).to(device)
      trimap = torch.from_numpy(trimap).type(torch.int32).to(device)
  
      # initialise our GMM
      gmm = GaussianMixtureModel(
          image.size(1),
          mixture_count=n_classes,
          mixture_size=num_mixtures,
          verbose_build=False,
      )
  
      # learn gmm from image and trimap
      gmm.learn(image, trimap)
  
      # apply gmm on image
      gmm_output = gmm.apply(image)
  
      # return output
      return gmm_output.squeeze(0).cpu().numpy()
  
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 6 for calling a global function with example usage: learn_and_apply_gmm_monai(image, scrib, scribbles_bg_label, scribbles_fg_label, num_mixtures) and returns: gmm_output