code: def run(self, workspace):
      workspace.display_data.statistics = []
      input_image = workspace.image_set.get_image(
          self.x_name.value, must_be_grayscale=True
      )
  
      (
          final_threshold,
          orig_threshold,
          guide_threshold,
          binary_image,
          sigma,
      ) = self.threshold.get_threshold(
          input_image, workspace, automatic=self.basic
      )
  
      self.threshold.add_threshold_measurements(
          self.y_name.value,
          workspace.measurements,
          final_threshold,
          orig_threshold,
          guide_threshold,
      )
  
      self.threshold.add_fg_bg_measurements(
          self.y_name.value,
          workspace.measurements,
          input_image,
          binary_image,
      )
  
      global_threshold = numpy.mean(numpy.atleast_1d(final_threshold))
  
      #
      # Fill background holes inside foreground objects
      #
      def size_fn(size, is_foreground):
          return size < self.size_range.max * self.size_range.max
  
      if self.basic or self.fill_holes.value == FH_THRESHOLDING:
          binary_image = centrosome.cpmorphology.fill_labeled_holes(
              binary_image, size_fn=size_fn
          )
  
      labeled_image, object_count = scipy.ndimage.label(
          binary_image, numpy.ones((3, 3), bool)
      )
  
      (
          labeled_image,
          object_count,
          maxima_suppression_size,
      ) = self.separate_neighboring_objects(
          workspace, labeled_image, object_count
      )
  
      unedited_labels = labeled_image.copy()
  
      # Filter out objects touching the border or mask
      border_excluded_labeled_image = labeled_image.copy()
      labeled_image = self.filter_on_border(input_image, labeled_image)
      border_excluded_labeled_image[labeled_image > 0] = 0
  
      # Filter out small and large objects
      size_excluded_labeled_image = labeled_image.copy()
      labeled_image, small_removed_labels = self.filter_on_size(
          labeled_image, object_count
      )
      size_excluded_labeled_image[labeled_image > 0] = 0
  
      #
      # Fill holes again after watershed
      #
      if self.basic or self.fill_holes != FH_NEVER:
          labeled_image = centrosome.cpmorphology.fill_labeled_holes(
              labeled_image
          )
  
      # Relabel the image
      labeled_image, object_count = centrosome.cpmorphology.relabel(
          labeled_image
      )
  
      if self.advanced and self.limit_choice.value == LIMIT_ERASE:
          if object_count > self.maximum_object_count.value:
              labeled_image = numpy.zeros(labeled_image.shape, int)
              border_excluded_labeled_image = numpy.zeros(
                  labeled_image.shape, int
              )
              size_excluded_labeled_image = numpy.zeros(
                  labeled_image.shape, int
              )
              object_count = 0
  
      # Make an outline image
      outline_image = centrosome.outline.outline(labeled_image)
      outline_size_excluded_image = centrosome.outline.outline(
          size_excluded_labeled_image
      )
      outline_border_excluded_image = centrosome.outline.outline(
          border_excluded_labeled_image
      )
  
      if self.show_window:
          statistics = workspace.display_data.statistics
          statistics.append(
              ["# of accepted objects", "%d" % object_count]
          )
          if object_count > 0:
              areas = scipy.ndimage.sum(
                  numpy.ones(labeled_image.shape),
                  labeled_image,
                  numpy.arange(1, object_count + 1),
              )
              areas.sort()
              low_diameter = (
                  math.sqrt(float(areas[object_count // 10]) / numpy.pi)
                  * 2
              )
              median_diameter = (
                  math.sqrt(float(areas[object_count // 2]) / numpy.pi)
                  * 2
              )
              high_diameter = (
                  math.sqrt(
                      float(areas[object_count * 9 // 10]) / numpy.pi
                  )
                  * 2
              )
              statistics.append(
                  ["10th pctile diameter", "%.1f pixels" % low_diameter]
              )
              statistics.append(
                  ["Median diameter", "%.1f pixels" % median_diameter]
              )
              statistics.append(
                  [
                      "90th pctile diameter",
                      "%.1f pixels" % high_diameter,
                  ]
              )
              object_area = numpy.sum(areas)
              total_area = numpy.product(labeled_image.shape[:2])
              statistics.append(
                  [
                      "Area covered by objects",
                      "%.1f %%"
                      % (
                          100.0 * float(object_area) / float(total_area)
                      ),
                  ]
              )
              statistics.append(
                  ["Thresholding filter size", "%.1f" % sigma]
              )
              statistics.append(
                  ["Threshold", "%0.3g" % global_threshold]
              )
              if self.basic or self.unclump_method != UN_NONE:
                  statistics.append(
                      [
                          "Declumping smoothing filter size",
                          "%.1f" % (self.calc_smoothing_filter_size()),
                      ]
                  )
                  statistics.append(
                      [
                          "Maxima suppression size",
                          "%.1f" % maxima_suppression_size,
                      ]
                  )
          else:
              statistics.append(
                  ["Threshold", "%0.3g" % global_threshold]
              )
          workspace.display_data.image = input_image.pixel_data
          workspace.display_data.labeled_image = labeled_image
          workspace.display_data.size_excluded_labels = (
              size_excluded_labeled_image
          )
          workspace.display_data.border_excluded_labels = (
              border_excluded_labeled_image
          )
  
      # Add image measurements
      objname = self.y_name.value
      measurements = workspace.measurements
  
      # Add label matrices to the object set
      objects = cellprofiler_core.object.Objects()
      objects.segmented = labeled_image
      objects.unedited_segmented = unedited_labels
      objects.small_removed_segmented = small_removed_labels
      objects.parent_image = input_image
  
      workspace.object_set.add_objects(objects, self.y_name.value)
  
      self.add_measurements(workspace)
  
imports: import math
  import cellprofiler_core.module.image_segmentation
  import cellprofiler_core.object
  import centrosome.cpmorphology
  import centrosome.outline
  import centrosome.propagate
  import centrosome.threshold
  import numpy
  import scipy.ndimage
  import scipy.sparse
  import skimage.morphology
  import skimage.segmentation
  from cellprofiler_core.setting import Binary, Color
  from cellprofiler_core.setting.choice import Choice
  from cellprofiler_core.setting.range import IntegerRange
  from cellprofiler_core.setting.text import Integer, Float
  import cellprofiler.gui.help
  import cellprofiler.gui.help.content
  from cellprofiler.modules import _help, threshold
label_desc: Use image node_id 10 for calling the IdentifyPrimaryObjects obj's underlying member method code with example usage: obj.run(workspace) and returns: unknown