code: def rebuild_worm_from_control_points_approx(
      control_coords, worm_radii, labels, idx
  ):
      """Rebuild a worm from its control coordinates
  
      Given a worm specified by some control points along its spline,
      reconstructs an approximate binary image representing the worm.
  
      Specifically, this function generates an image where successive control
      points have been joined by line segments, and then dilates that by a
      certain (specified) radius.
  
      Inputs:
  
      control_coords: A N x 2 double array, where each column contains the x
      and y coordinates for a control point.
  
      worm_radius: Scalar double. Approximate radius of a typical worm; the
      radius by which the reconstructed worm spline is dilated to form the
      final worm.
  
      Outputs:
      The coordinates of all pixels in the worm in an N x 2 array"""
      index, count, i, j = centrosome.cpmorphology.get_line_pts(
          control_coords[:-1, 0],
          control_coords[:-1, 1],
          control_coords[1:, 0],
          control_coords[1:, 1],
      )
      #
      # Get rid of the last point for the middle elements - these are
      # duplicated by the first point in the next line
      #
      i = numpy.delete(i, index[1:])
      j = numpy.delete(j, index[1:])
      index = index - numpy.arange(len(index))
      count -= 1
      #
      # Find the control point and within-control-point index of each point
      #
      label = numpy.zeros(len(i), int)
      label[index[1:]] = 1
      label = numpy.cumsum(label)
      order = numpy.arange(len(i)) - index[label]
      frac = order.astype(float) / count[label].astype(float)
      radius = (
          worm_radii[label] * (1 - frac) + worm_radii[label + 1] * frac
      )
      iworm_radius = int(numpy.max(numpy.ceil(radius)))
      #
      # Get dilation coordinates
      #
      ii, jj = numpy.mgrid[
          -iworm_radius : iworm_radius + 1,
          -iworm_radius : iworm_radius + 1,
      ]
      dd = numpy.sqrt((ii * ii + jj * jj).astype(float))
      mask = ii * ii + jj * jj <= iworm_radius * iworm_radius
      ii = ii[mask]
      jj = jj[mask]
      dd = dd[mask]
      #
      # All points (with repeats)
      #
      i = (i[:, numpy.newaxis] + ii[numpy.newaxis, :]).flatten()
      j = (j[:, numpy.newaxis] + jj[numpy.newaxis, :]).flatten()
      #
      # We further mask out any dilation coordinates outside of
      # the radius at our point in question
      #
      m = (radius[:, numpy.newaxis] >= dd[numpy.newaxis, :]).flatten()
      i = i[m]
      j = j[m]
      #
      # Find repeats by sorting and comparing against next
      #
      order = numpy.lexsort((i, j))
      i = i[order]
      j = j[order]
      mask = numpy.hstack(
          [[True], (i[:-1] != i[1:]) | (j[:-1] != j[1:])]
      )
      i = i[mask]
      j = j[mask]
      mask = (
          (i >= 0)
          & (j >= 0)
          & (i < labels.shape[0])
          & (j < labels.shape[1])
      )
      labels[i[mask], j[mask]] = idx
  
imports: import centrosome.cpmorphology
  import numpy
  import six.moves
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler_core.modules
  from cellprofiler_core.constants.measurement import C_COUNT, M_LOCATION_CENTER_X, M_LOCATION_CENTER_Y, M_NUMBER_OBJECT_NUMBER, C_LOCATION, C_NUMBER, FTR_CENTER_X, FTR_CENTER_Y, FTR_OBJECT_NUMBER, COLTYPE_FLOAT
  import cellprofiler.modules.straightenworms
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.setting
  import cellprofiler_core.workspace
  import cellprofiler_core.preferences
  import tests.frontend.modules
label_desc: Use image node_id 4 for calling a global function with example usage: rebuild_worm_from_control_points_approx(control_coords, worm_radii, labels, idx) without return types