docstr: Run the module on the image set
docstr_tok: ["Run","the","module","on","the","image","set"]
code: def run(self, workspace):
      """Run the module on the image set"""
      seed_objects_name = self.seed_objects_name.value
      skeleton_name = self.image_name.value
      seed_objects = workspace.object_set.get_objects(seed_objects_name)
      labels = seed_objects.segmented
      labels_count = numpy.max(labels)
      label_range = numpy.arange(labels_count, dtype=numpy.int32) + 1
  
      skeleton_image = workspace.image_set.get_image(
          skeleton_name, must_be_binary=True
      )
      skeleton = skeleton_image.pixel_data
      if skeleton_image.has_mask:
          skeleton = skeleton & skeleton_image.mask
      try:
          labels = skeleton_image.crop_image_similarly(labels)
      except:
          labels, m1 = size_similarly(skeleton, labels)
          labels[~m1] = 0
      #
      # The following code makes a ring around the seed objects with
      # the skeleton trunks sticking out of it.
      #
      # Create a new skeleton with holes at the seed objects
      # First combine the seed objects with the skeleton so
      # that the skeleton trunks come out of the seed objects.
      #
      # Erode the labels once so that all of the trunk branchpoints
      # will be within the labels
      #
      #
      # Dilate the objects, then subtract them to make a ring
      #
      my_disk = centrosome.cpmorphology.strel_disk(1.5).astype(int)
      dilated_labels = grey_dilation(labels, footprint=my_disk)
      seed_mask = dilated_labels > 0
      combined_skel = skeleton | seed_mask
  
      closed_labels = grey_erosion(dilated_labels, footprint=my_disk)
      seed_center = closed_labels > 0
      combined_skel = combined_skel & (~seed_center)
      #
      # Fill in single holes (but not a one-pixel hole made by
      # a one-pixel image)
      #
      if self.wants_to_fill_holes:
  
          def size_fn(area, is_object):
              return (~is_object) and (
                  area <= self.maximum_hole_size.value
              )
  
          combined_skel = centrosome.cpmorphology.fill_labeled_holes(
              combined_skel, ~seed_center, size_fn
          )
      #
      # Reskeletonize to make true branchpoints at the ring boundaries
      #
      combined_skel = centrosome.cpmorphology.skeletonize(combined_skel)
      #
      # The skeleton outside of the labels
      #
      outside_skel = combined_skel & (dilated_labels == 0)
      #
      # Associate all skeleton points with seed objects
      #
      dlabels, distance_map = propagate.propagate(
          numpy.zeros(labels.shape), dilated_labels, combined_skel, 1
      )
      #
      # Get rid of any branchpoints not connected to seeds
      #
      combined_skel[dlabels == 0] = False
      #
      # Find the branchpoints
      #
      branch_points = centrosome.cpmorphology.branchpoints(
          combined_skel
      )
      #
      # Odd case: when four branches meet like this, branchpoints are not
      # assigned because they are arbitrary. So assign them.
      #
      # .  .
      #  B.
      #  .B
      # .  .
      #
      odd_case = (
          combined_skel[:-1, :-1]
          & combined_skel[1:, :-1]
          & combined_skel[:-1, 1:]
          & combined_skel[1, 1]
      )
      branch_points[:-1, :-1][odd_case] = True
      branch_points[1:, 1:][odd_case] = True
      #
      # Find the branching counts for the trunks (# of extra branches
      # emanating from a point other than the line it might be on).
      #
      branching_counts = centrosome.cpmorphology.branchings(
          combined_skel
      )
      branching_counts = numpy.array([0, 0, 0, 1, 2])[branching_counts]
      #
      # Only take branches within 1 of the outside skeleton
      #
      dilated_skel = scipy.ndimage.binary_dilation(
          outside_skel, centrosome.cpmorphology.eight_connect
      )
      branching_counts[~dilated_skel] = 0
      #
      # Find the endpoints
      #
      end_points = centrosome.cpmorphology.endpoints(combined_skel)
      #
      # We use two ranges for classification here:
      # * anything within one pixel of the dilated image is a trunk
      # * anything outside of that range is a branch
      #
      nearby_labels = dlabels.copy()
      nearby_labels[distance_map > 1.5] = 0
  
      outside_labels = dlabels.copy()
      outside_labels[nearby_labels > 0] = 0
      #
      # The trunks are the branchpoints that lie within one pixel of
      # the dilated image.
      #
      if labels_count > 0:
          trunk_counts = fix(
              scipy.ndimage.sum(
                  branching_counts, nearby_labels, label_range
              )
          ).astype(int)
      else:
          trunk_counts = numpy.zeros((0,), int)
      #
      # The branches are the branchpoints that lie outside the seed objects
      #
      if labels_count > 0:
          branch_counts = fix(
              scipy.ndimage.sum(
                  branch_points, outside_labels, label_range
              )
          )
      else:
          branch_counts = numpy.zeros((0,), int)
      #
      # Save the endpoints
      #
      if labels_count > 0:
          end_counts = fix(
              scipy.ndimage.sum(end_points, outside_labels, label_range)
          )
      else:
          end_counts = numpy.zeros((0,), int)
      #
      # Calculate the distances
      #
      total_distance = centrosome.cpmorphology.skeleton_length(
          dlabels * outside_skel, label_range
      )
      #
      # Save measurements
      #
      m = workspace.measurements
      assert isinstance(m, Measurements)
      feature = "_".join(
          (C_OBJSKELETON, F_NUMBER_TRUNKS, skeleton_name)
      )
      m.add_measurement(seed_objects_name, feature, trunk_counts)
      feature = "_".join(
          (C_OBJSKELETON, F_NUMBER_NON_TRUNK_BRANCHES, skeleton_name)
      )
      m.add_measurement(seed_objects_name, feature, branch_counts)
      feature = "_".join(
          (C_OBJSKELETON, F_NUMBER_BRANCH_ENDS, skeleton_name)
      )
      m.add_measurement(seed_objects_name, feature, end_counts)
      feature = "_".join(
          (C_OBJSKELETON, F_TOTAL_OBJSKELETON_LENGTH, skeleton_name)
      )
      m[seed_objects_name, feature] = total_distance
      #
      # Collect the graph information
      #
      if self.wants_objskeleton_graph:
          trunk_mask = (branching_counts > 0) & (nearby_labels != 0)
          intensity_image = workspace.image_set.get_image(
              self.intensity_image_name.value
          )
          edge_graph, vertex_graph = self.make_objskeleton_graph(
              combined_skel,
              dlabels,
              trunk_mask,
              branch_points & ~trunk_mask,
              end_points,
              intensity_image.pixel_data,
          )
  
          image_number = workspace.measurements.image_set_number
  
          edge_path, vertex_path = self.get_graph_file_paths(
              m, m.image_number
          )
          workspace.interaction_request(
              self,
              m.image_number,
              edge_path,
              edge_graph,
              vertex_path,
              vertex_graph,
              headless_ok=True,
          )
  
          if self.show_window:
              workspace.display_data.edge_graph = edge_graph
              workspace.display_data.vertex_graph = vertex_graph
              workspace.display_data.intensity_image = (
                  intensity_image.pixel_data
              )
      #
      # Make the display image
      #
      if self.show_window or self.wants_branchpoint_image:
          branchpoint_image = numpy.zeros(
              (skeleton.shape[0], skeleton.shape[1], 3)
          )
          trunk_mask = (branching_counts > 0) & (nearby_labels != 0)
          branch_mask = branch_points & (outside_labels != 0)
          end_mask = end_points & (outside_labels != 0)
          branchpoint_image[outside_skel, :] = 1
          branchpoint_image[trunk_mask | branch_mask | end_mask, :] = 0
          branchpoint_image[trunk_mask, 0] = 1
          branchpoint_image[branch_mask, 1] = 1
          branchpoint_image[end_mask, 2] = 1
          branchpoint_image[dilated_labels != 0, :] *= 0.875
          branchpoint_image[dilated_labels != 0, :] += 0.1
          if self.show_window:
              workspace.display_data.branchpoint_image = (
                  branchpoint_image
              )
          if self.wants_branchpoint_image:
              bi = Image(branchpoint_image, parent_image=skeleton_image)
              workspace.image_set.add(
                  self.branchpoint_image_name.value, bi
              )
  
imports: import os
  import centrosome.cpmorphology
  import centrosome.propagate
  import numpy
  import scipy.ndimage
  from cellprofiler_core.constants.measurement import COLTYPE_FLOAT
  from cellprofiler_core.constants.measurement import COLTYPE_INTEGER
  from cellprofiler_core.image import Image
  from cellprofiler_core.measurement import Measurements
  from cellprofiler_core.module import Module
  from cellprofiler_core.preferences import ABSOLUTE_FOLDER_NAME
  from cellprofiler_core.preferences import DEFAULT_INPUT_FOLDER_NAME
  from cellprofiler_core.preferences import DEFAULT_INPUT_SUBFOLDER_NAME
  from cellprofiler_core.preferences import DEFAULT_OUTPUT_FOLDER_NAME
  from cellprofiler_core.preferences import DEFAULT_OUTPUT_SUBFOLDER_NAME
  from cellprofiler_core.preferences import get_default_colormap
  from cellprofiler_core.setting import Binary
  from cellprofiler_core.setting.subscriber import LabelSubscriber, ImageSubscriber
  from cellprofiler_core.setting.text import ImageName, Directory
  from cellprofiler_core.setting.text import Integer
  from cellprofiler_core.setting.text import Text
  from cellprofiler_core.utilities.core.object import size_similarly
  from centrosome.cpmorphology import fixup_scipy_ndimage_result
  from scipy.ndimage import grey_dilation, grey_erosion
label_desc: Use image node_id 6 for calling the MeasureObjectSkeleton obj's underlying member method code with example usage: obj.run(workspace) and returns: unknown