class_docstr: Compute confidence map from an ultrasound image.
  This transform uses the method introduced by Karamalis et al. in https://doi.org/10.1016/j.media.2012.07.005.
  It generates a confidence map by setting source and sink points in the image and computing the probability
  for random walks to reach the source for each pixel.
  
  Args:
      alpha (float, optional): Alpha parameter. Defaults to 2.0.
      beta (float, optional): Beta parameter. Defaults to 90.0.
      gamma (float, optional): Gamma parameter. Defaults to 0.05.
      mode (str, optional): 'RF' or 'B' mode data. Defaults to 'B'.
      sink_mode (str, optional): Sink mode. Defaults to 'all'. If 'mask' is selected, a mask must be when calling
          the transform. Can be 'all', 'mid', 'min', or 'mask'.
docstr: Compute 6-Connected Laplacian for confidence estimation problem
  
  Args:
      padded_index (NDArray): The index matrix of the image with boundary padding.
      padded_image (NDArray): The padded image.
      beta (float): Random walks parameter that defines the sensitivity of the Gaussian weighting function.
      gamma (float): Horizontal penalty factor that adjusts the weight of horizontal edges in the Laplacian.
  
  Returns:
      L (csc_matrix): The 6-connected Laplacian matrix used for confidence map estimation.
docstr_tok: ["Compute","6-Connected","Laplacian","for","confidence","estimation","problem","Args",":","padded_index","(","NDArray",")",":","The","index","matrix","of","the","image","with","boundary","padding",".","padded_image","(","NDArray",")",":","The","padded","image",".","beta","(","float",")",":","Random","walks","parameter","that","defines","the","sensitivity","of","the","Gaussian","weighting","function",".","gamma","(","float",")",":","Horizontal","penalty","factor","that","adjusts","the","weight","of","horizontal","edges","in","the","Laplacian",".","Returns",":","L","(","csc_matrix",")",":","The","6-connected","Laplacian","matrix","used","for","confidence","map","estimation","."]
code: def confidence_laplacian(
      self,
      padded_index: NDArray,
      padded_image: NDArray,
      beta: float,
      gamma: float,
  ):
      """Compute 6-Connected Laplacian for confidence estimation problem
  
      Args:
          padded_index (NDArray): The index matrix of the image with boundary padding.
          padded_image (NDArray): The padded image.
          beta (float): Random walks parameter that defines the sensitivity of the Gaussian weighting function.
          gamma (float): Horizontal penalty factor that adjusts the weight of horizontal edges in the Laplacian.
  
      Returns:
          L (csc_matrix): The 6-connected Laplacian matrix used for confidence map estimation.
      """
  
      m, _ = padded_index.shape
  
      padded_index = padded_index.T.flatten()
      padded_image = padded_image.T.flatten()
  
      p = np.where(padded_index > 0)[0]
  
      i = padded_index[p] - 1  # Index vector
      j = padded_index[p] - 1  # Index vector
      # Entries vector, initially for diagonal
      s = np.zeros_like(p, dtype="float64")
  
      edge_templates = [
          -1,  # Vertical edges
          1,
          m - 1,  # Diagonal edges
          m + 1,
          -m - 1,
          -m + 1,
          m,  # Horizontal edges
          -m,
      ]
  
      vertical_end = None
  
      for iter_idx, k in enumerate(edge_templates):
          neigh_idxs = padded_index[p + k]
  
          q = np.where(neigh_idxs > 0)[0]
  
          ii = padded_index[p[q]] - 1
          i = np.concatenate((i, ii))
          jj = neigh_idxs[q] - 1
          j = np.concatenate((j, jj))
          w = np.abs(
              padded_image[p[ii]] - padded_image[p[jj]]
          )  # Intensity derived weight
          s = np.concatenate((s, w))
  
          if iter_idx == 1:
              vertical_end = s.shape[0]  # Vertical edges length
          elif iter_idx == 5:
              s.shape[0]  # Diagonal edges length
  
      # Normalize weights
      s = self.normalize(s)
  
      # Horizontal penalty
      s[:vertical_end] += gamma
      # s[vertical_end:diagonal_end] += gamma * np.sqrt(2) # --> In the paper it is sqrt(2)
      # since the diagonal edges are longer yet does not exist in the original code
  
      # Normalize differences
      s = self.normalize(s)
  
      # Gaussian weighting function
      s = -(
          (np.exp(-beta * s, dtype="float64")) + 1.0e-6
      )  # --> This epsilon changes results drastically default: 1.e-6
  
      # Create Laplacian, diagonal missing
      lap = csc_matrix((s, (i, j)))
  
      # Reset diagonal weights to zero for summing
      # up the weighted edge degree in the next step
      lap.setdiag(0)
  
      # Weighted edge degree
      diag = np.abs(lap.sum(axis=0).A)[0]
  
      # Finalize Laplacian by completing the diagonal
      lap.setdiag(diag)
  
      return lap
  
file_path: MONAI/monai/data/ultrasound_confidence_map.py
imports: from __future__ import annotations
  import numpy
  from numpy.typing import NDArray
  from monai.utils import min_version, optional_import
label_desc: Use image node_id 6 for calling the UltrasoundConfidenceMap obj's underlying member method code with example usage: obj.confidence_laplacian(padded_index, padded_image, beta, gamma) and returns: lap