code: def merge_objects(labels_x, labels_y, dimensions):
      """
      Make overlapping objects combine into a single object, taking
      on the label of the object from the initial set.
  
      If an object overlaps multiple objects, each pixel of the added
      object will be assigned to the closest object from the initial
      set. This is primarily useful when the same objects appear in
      both sets.
      """
      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)
      if dimensions == 2:
          distances, (i, j) = scipy.ndimage.distance_transform_edt(
              labels_x == 0, return_indices=True
          )
          output[to_segment] = labels_x[i[to_segment], j[to_segment]]
      if dimensions == 3:
          distances, (i, j, v) = scipy.ndimage.distance_transform_edt(
              labels_x == 0, return_indices=True
          )
          output[to_segment] = labels_x[
              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 9 for calling a global function with example usage: merge_objects(labels_x, labels_y, dimensions) and returns: output