code: def create_probability_weights(candidates, mean_counts_size):
      """
      This functions creates the probability weighting given the valid
      candidates and the size of connected components associated to this candidate
      :param candidates: binary map of the valid candidates
      :param mean_counts_size: counts attributed to each candidate
      :return: probability map for the selection of any voxel as candidate
      """
      proba_weight = np.ones_like(candidates)
      for i in range(0, len(mean_counts_size)):
          # print(candidates.shape, mean_counts_size[i].shape, np.max(candidates),
          #       np.max(mean_counts_size[i]))
  
          possible_mean_count = np.nan_to_num(
              candidates * mean_counts_size[i]
          )
          max_count = np.ceil(np.max(possible_mean_count))
          print(max_count, "is max_count")
          unique, counts = np.unique(
              np.round(possible_mean_count), return_counts=True
          )
          reciprocal_hist = np.sum(counts[1:]) * np.reciprocal(
              np.asarray(counts[1:], dtype=np.float32)
          )
          sum_rec = np.sum(reciprocal_hist)
          proba_hist = np.divide(reciprocal_hist, sum_rec)
          print(unique, counts, sum_rec, len(proba_hist))
          e_start = unique[1:]
          e_end = unique[2:]
          e_end.tolist().append(max_count + 1)
          # print(e_start.shape, e_end.shape, e_start[-1], e_end[-1], len(
          #     proba_hist))
          candidates_proba = np.zeros_like(candidates)
          if len(unique) == 2:
              proba_weight = (
                  np.ones_like(candidates, dtype=np.float32)
                  * 1.0
                  / np.sum(candidates)
              )
              proba_weight = np.multiply(proba_weight, candidates)
          else:
              for e_s, e_e, size in zip(e_start, e_end, proba_hist):
                  prob_selector = (possible_mean_count >= e_s) & (
                      possible_mean_count < e_e
                  )
                  candidates_proba[prob_selector.astype(np.bool)] = size
              proba_weight = np.multiply(proba_weight, candidates_proba)
          print("Finished probability calculation")
      return np.divide(proba_weight, np.sum(proba_weight))
  
file_path: NiftyNet/niftynet/contrib/segmentation_selective_sampler/sampler_selective.py
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import tensorflow
  from scipy import ndimage
  from scipy.signal import fftconvolve
  from niftynet.engine.image_window import N_SPATIAL
  from niftynet.engine.sampler_uniform_v2 import UniformSampler
label_desc: Use image node_id 3 for calling a global function with example usage: create_probability_weights(candidates, mean_counts_size) and returns: np