code: def segment_objects(labels_x, labels_y, dimensions):
      """
      Combine object sets and re-draw segmentation for overlapping
      objects.
      """
      output = numpy.zeros_like(labels_x)
      labels_y[labels_y > 0] += labels_x.max()
      indices_x = numpy.unique(labels_x)
      indices_x = indices_x[indices_x > 0]
      indices_y = numpy.unique(labels_y)
      indices_y = indices_y[indices_y > 0]
      # Resolve non-conflicting labels first
      undisputed = numpy.logical_xor(labels_x > 0, labels_y > 0)
      undisputed_x = numpy.setdiff1d(indices_x, labels_x[~undisputed])
      mask = numpy.isin(labels_x, undisputed_x)
      output = numpy.where(mask, labels_x, output)
      labels_x[mask] = 0
      undisputed_y = numpy.setdiff1d(indices_y, labels_y[~undisputed])
      mask = numpy.isin(labels_y, undisputed_y)
      output = numpy.where(mask, labels_y, output)
      labels_y[mask] = 0
  
      to_segment = numpy.logical_or(labels_x > 0, labels_y > 0)
      disputed = numpy.logical_and(labels_x > 0, labels_y > 0)
      seeds = numpy.add(labels_x, labels_y)
      # Find objects which will be completely removed due to 100% overlap.
      will_be_lost = numpy.setdiff1d(
          labels_x[disputed], labels_x[~disputed]
      )
      # Check whether this was because an identical object is in both arrays.
      for label in will_be_lost:
          x_mask = labels_x == label
          y_lab = numpy.unique(labels_y[x_mask])
          if not y_lab or len(y_lab) > 1:
              # Labels are not identical
              continue
          else:
              # Get mask of object on y, check if identical to x
              y_mask = labels_y == y_lab[0]
              if numpy.array_equal(x_mask, y_mask):
                  # Label is identical
                  output[x_mask] = label
                  to_segment[x_mask] = False
      seeds[disputed] = 0
      if dimensions == 2:
          distances, (i, j) = scipy.ndimage.distance_transform_edt(
              seeds == 0, return_indices=True
          )
          output[to_segment] = seeds[i[to_segment], j[to_segment]]
      elif dimensions == 3:
          distances, (i, j, v) = scipy.ndimage.distance_transform_edt(
              seeds == 0, return_indices=True
          )
          output[to_segment] = seeds[
              i[to_segment], j[to_segment], v[to_segment]
          ]
  
      return output
  
imports: from typing import Literal
  import centrosome.cpmorphology
  import numpy
  import scipy.ndimage
  import skimage.morphology
  import mahotas
label_desc: Use image node_id 12 for calling a global function with example usage: segment_objects(labels_x, labels_y, dimensions) and returns: output