docstr: Filter objects for this image set, display results
docstr_tok: ["Filter","objects","for","this","image","set",",","display","results"]
code: def run(self, workspace):
      """Filter objects for this image set, display results"""
      src_objects = workspace.get_objects(self.x_name.value)
      if self.mode == MODE_RULES:
          indexes = self.keep_by_rules(workspace, src_objects)
      elif self.mode == MODE_MEASUREMENTS:
          if self.filter_choice in (FI_MINIMAL, FI_MAXIMAL):
              indexes = self.keep_one(workspace, src_objects)
          if self.filter_choice in (
              FI_MINIMAL_PER_OBJECT,
              FI_MAXIMAL_PER_OBJECT,
          ):
              indexes = self.keep_per_object(workspace, src_objects)
          if self.filter_choice == FI_LIMITS:
              indexes = self.keep_within_limits(workspace, src_objects)
      elif self.mode == MODE_BORDER:
          indexes = self.discard_border_objects(src_objects)
      elif self.mode == MODE_CLASSIFIERS:
          indexes = self.keep_by_class(workspace, src_objects)
      else:
          raise ValueError(
              "Unknown filter choice: %s" % self.mode.value
          )
  
      #
      # Create an array that maps label indexes to their new values
      # All labels to be deleted have a value in this array of zero
      #
      new_object_count = len(indexes)
      max_label = numpy.max(src_objects.segmented)
      label_indexes = numpy.zeros((max_label + 1,), int)
      label_indexes[indexes] = numpy.arange(1, new_object_count + 1)
      #
      # Loop over both the primary and additional objects
      #
      object_list = [(self.x_name.value, self.y_name.value)] + [
          (x.object_name.value, x.target_name.value)
          for x in self.additional_objects
      ]
      m = workspace.measurements
      first_set = True
      for src_name, target_name in object_list:
          src_objects = workspace.get_objects(src_name)
          target_labels = src_objects.segmented.copy()
          #
          # Reindex the labels of the old source image
          #
          target_labels[target_labels > max_label] = 0
          target_labels = label_indexes[target_labels]
          #
          # Make a new set of objects - retain the old set's unedited
          # segmentation for the new and generally try to copy stuff
          # from the old to the new.
          #
          target_objects = cellprofiler_core.object.Objects()
          target_objects.segmented = target_labels
          target_objects.unedited_segmented = (
              src_objects.unedited_segmented
          )
          #
          # Remove the filtered objects from the small_removed_segmented
          # if present. "small_removed_segmented" should really be
          # "filtered_removed_segmented".
          #
          small_removed = src_objects.small_removed_segmented.copy()
          small_removed[
              (target_labels == 0) & (src_objects.segmented != 0)
          ] = 0
          target_objects.small_removed_segmented = small_removed
          if src_objects.has_parent_image:
              target_objects.parent_image = src_objects.parent_image
          workspace.object_set.add_objects(target_objects, target_name)
  
          self.add_measurements(workspace, src_name, target_name)
          if self.show_window and first_set:
              workspace.display_data.src_objects_segmented = (
                  src_objects.segmented
              )
              workspace.display_data.target_objects_segmented = (
                  target_objects.segmented
              )
              workspace.display_data.dimensions = src_objects.dimensions
              first_set = False
  
      if self.keep_removed_objects.value:
          # Isolate objects removed by the filter
          removed_indexes = [
              x for x in range(1, max_label + 1) if x not in indexes
          ]
          removed_object_count = len(removed_indexes)
          removed_label_indexes = numpy.zeros((max_label + 1,), int)
          removed_label_indexes[removed_indexes] = numpy.arange(
              1, removed_object_count + 1
          )
  
          src_objects = workspace.get_objects(self.x_name.value)
          removed_labels = src_objects.segmented.copy()
          #
          # Reindex the labels of the old source image
          #
          removed_labels[removed_labels > max_label] = 0
          removed_labels = removed_label_indexes[removed_labels]
          #
          # Make a new set of objects - retain the old set's unedited
          # segmentation for the new and generally try to copy stuff
          # from the old to the new.
          #
          removed_objects = cellprofiler_core.object.Objects()
          removed_objects.segmented = removed_labels
          removed_objects.unedited_segmented = (
              src_objects.unedited_segmented
          )
          #
          # Remove the filtered objects from the small_removed_segmented
          # if present. "small_removed_segmented" should really be
          # "filtered_removed_segmented".
          #
          small_removed = src_objects.small_removed_segmented.copy()
          small_removed[
              (removed_labels == 0) & (src_objects.segmented != 0)
          ] = 0
          removed_objects.small_removed_segmented = small_removed
          if src_objects.has_parent_image:
              removed_objects.parent_image = src_objects.parent_image
          workspace.object_set.add_objects(
              removed_objects, self.removed_objects_name.value
          )
  
          self.add_measurements(
              workspace,
              self.x_name.value,
              self.removed_objects_name.value,
          )
          if self.show_window:
              workspace.display_data.removed_objects_segmented = (
                  removed_objects.segmented
              )
  
imports: from cellprofiler_core.constants.measurement import M_LOCATION_CENTER_X, M_LOCATION_CENTER_Y, C_CHILDREN, C_PARENT, C_LOCATION, C_NUMBER, FTR_OBJECT_NUMBER, C_COUNT, FTR_CENTER_X, FTR_CENTER_Y, FTR_CENTER_Z
  from cellprofiler_core.module.image_segmentation import ObjectProcessing
  from cellprofiler_core.preferences import DEFAULT_INPUT_FOLDER_NAME, ABSOLUTE_FOLDER_NAME, DEFAULT_INPUT_SUBFOLDER_NAME, DEFAULT_OUTPUT_SUBFOLDER_NAME
  from cellprofiler_core.setting import Divider, HiddenCount, SettingsGroup, Measurement, Binary, ValidationError
  from cellprofiler_core.setting.choice import Choice
  from cellprofiler_core.setting.do_something import DoSomething, RemoveSettingButton
  from cellprofiler_core.setting.subscriber import LabelSubscriber
  from cellprofiler_core.setting.text import Directory, Filename, Float, LabelName
  from cellprofiler.modules import _help
  import logging
  import os
  import numpy
  import scipy
  import scipy.ndimage
  import scipy.sparse
  import cellprofiler.gui.help
  import cellprofiler_core.object
  from cellprofiler.utilities.rules import Rules
label_desc: Use image node_id 12 for calling the FilterObjects obj's underlying member method code with example usage: obj.run(workspace) without return types