code: def create_settings(self):
      super(FilterObjects, self).create_settings()
  
      self.x_name.text = """Select the objects to filter"""
  
      self.x_name.doc = """\
  Select the set of objects that you want to filter. This setting also
  controls which measurement choices appear for filtering: you can only
  filter based on measurements made on the object you select. Be sure
  the **FilterObjects** module is downstream of the necessary **Measure**
  modules. If you
  intend to use a measurement calculated by the **CalculateMath** module
  to to filter objects, select the first operand’s object here, because
  **CalculateMath** measurements are stored with the first operand’s
  object."""
  
      self.y_name.text = """Name the output objects"""
  
      self.y_name.doc = "Enter a name for the collection of objects that are retained after applying the filter(s)."
  
      self.spacer_1 = Divider(line=False)
  
      self.mode = Choice(
          "Select the filtering mode",
          [
              MODE_MEASUREMENTS,
              MODE_RULES,
              MODE_BORDER,
              MODE_CLASSIFIERS,
          ],
          doc="""\
  You can choose from the following options:
  
  -  *{MODE_MEASUREMENTS}*: Specify a per-object measurement made by an
     upstream module in the pipeline.
  -  *{MODE_BORDER}*: Remove objects touching the border of the image
     and/or the edges of an image mask.
  -  *{MODE_RULES}*: Use a file containing rules generated by
     CellProfiler Analyst. You will need to ensure that the measurements
     specified by the rules file are produced by upstream modules in the
     pipeline. This setting is not compatible with data processed as 3D.
  -  *{MODE_CLASSIFIERS}*: Use a file containing a trained classifier from
     CellProfiler Analyst. You will need to ensure that the measurements
     specified by the file are produced by upstream modules in the
     pipeline. This setting is not compatible with data processed as 3D.""".format(
              **{
                  "MODE_MEASUREMENTS": MODE_MEASUREMENTS,
                  "MODE_RULES": MODE_RULES,
                  "MODE_BORDER": MODE_BORDER,
                  "MODE_CLASSIFIERS": MODE_CLASSIFIERS,
              }
          ),
      )
  
      self.spacer_2 = Divider(line=False)
  
      self.measurements = []
  
      self.measurement_count = HiddenCount(
          self.measurements, "Measurement count"
      )
  
      self.add_measurement(False)
  
      self.add_measurement_button = DoSomething(
          "", "Add another measurement", self.add_measurement
      )
  
      self.filter_choice = Choice(
          "Select the filtering method",
          FI_ALL,
          FI_LIMITS,
          doc="""\
  *(Used only if filtering using measurements)*
  
  There are five different ways to filter objects:
  
  -  *{FI_LIMITS}:* Keep an object if its measurement value falls within
     a range you specify.
  -  *{FI_MAXIMAL}:* Keep the object with the maximum value for the
     measurement of interest. If multiple objects share a maximal value,
     retain one object selected arbitrarily per image.
  -  *{FI_MINIMAL}:* Keep the object with the minimum value for the
     measurement of interest. If multiple objects share a minimal value,
     retain one object selected arbitrarily per image.
  -  *{FI_MAXIMAL_PER_OBJECT}:* This option requires you to choose a
     parent object. The parent object might contain several child objects
     of choice (for instance, mitotic spindles within a cell or FISH probe
     spots within a nucleus). Only the child object whose measurements
     equal the maximum child-measurement value among that set of child
     objects will be kept (for example, the longest spindle in each cell).
     You do not have to explicitly relate objects before using this
     module.
  -  *{FI_MINIMAL_PER_OBJECT}:* Same as *Maximal per object*, except
     filtering is based on the minimum value.""".format(
              **{
                  "FI_LIMITS": FI_LIMITS,
                  "FI_MAXIMAL": FI_MAXIMAL,
                  "FI_MINIMAL": FI_MINIMAL,
                  "FI_MAXIMAL_PER_OBJECT": FI_MAXIMAL_PER_OBJECT,
                  "FI_MINIMAL_PER_OBJECT": FI_MINIMAL_PER_OBJECT,
              }
          ),
      )
  
      self.per_object_assignment = Choice(
          "Assign overlapping child to",
          PO_ALL,
          doc="""\
  *(Used only if filtering per object)*
  
  A child object can overlap two parent objects and can have the
  maximal/minimal measurement of all child objects in both parents. This
  option controls how an overlapping maximal/minimal child affects
  filtering of other children of its parents and to which parent the
  maximal child is assigned. The choices are:
  
  -  *{PO_BOTH}*: The child will be assigned to both parents and all
     other children of both parents will be filtered. Only the maximal
     child per parent will be left, but if **RelateObjects** is used to
     relate the maximal child to its parent, one or the other of the
     overlapping parents will not have a child even though the excluded
     parent may have other child objects. The maximal child can still be
     assigned to both parents using a database join via the relationships
     table if you are using **ExportToDatabase** and separate object
     tables.
  -  *{PO_PARENT_WITH_MOST_OVERLAP}*: The child will be assigned to
     the parent with the most overlap and a child with a less
     maximal/minimal measurement, if available, will be assigned to other
     parents. Use this option to ensure that parents with an alternate
     non-overlapping child object are assigned some child object by a
     subsequent **RelateObjects** module.""".format(
              **{
                  "PO_BOTH": PO_BOTH,
                  "PO_PARENT_WITH_MOST_OVERLAP": PO_PARENT_WITH_MOST_OVERLAP,
              }
          ),
      )
  
      self.enclosing_object_name = LabelSubscriber(
          "Select the objects that contain the filtered objects",
          "None",
          doc="""\
  *(Used only if a per-object filtering method is selected)*
  
  This setting selects the container (i.e., parent) objects for the
  *{FI_MAXIMAL_PER_OBJECT}* and *{FI_MINIMAL_PER_OBJECT}* filtering
  choices.""".format(
              **{
                  "FI_MAXIMAL_PER_OBJECT": FI_MAXIMAL_PER_OBJECT,
                  "FI_MINIMAL_PER_OBJECT": FI_MINIMAL_PER_OBJECT,
              }
          ),
      )
  
      self.rules_directory = Directory(
          "Select the location of the rules or classifier file",
          doc="""\
  *(Used only when filtering using {MODE_RULES} or {MODE_CLASSIFIERS})*
  
  Select the location of the rules or classifier file that will be used for
  filtering.
  
  {IO_FOLDER_CHOICE_HELP_TEXT}
  """.format(
              **{
                  "MODE_CLASSIFIERS": MODE_CLASSIFIERS,
                  "MODE_RULES": MODE_RULES,
                  "IO_FOLDER_CHOICE_HELP_TEXT": _help.IO_FOLDER_CHOICE_HELP_TEXT,
              }
          ),
      )
  
      self.rules_class = Choice(
          "Class number",
          choices=["1", "2"],
          choices_fn=self.get_class_choices,
          doc="""\
  *(Used only when filtering using {MODE_RULES} or {MODE_CLASSIFIERS})*
  
  Select which of the classes to keep when filtering. The CellProfiler
  Analyst classifier user interface lists the names of the classes in
  left-to-right order. **FilterObjects** uses the first class from
  CellProfiler Analyst if you choose “1”, etc.
  
  Please note the following:
  
  -  The object is retained if the object falls into the selected class.
  -  You can make multiple class selections. If you do so, the module will
     retain the object if the object falls into any of the selected
     classes.""".format(
              **{
                  "MODE_CLASSIFIERS": MODE_CLASSIFIERS,
                  "MODE_RULES": MODE_RULES,
              }
          ),
      )
  
      def get_directory_fn():
          """Get the directory for the rules file name"""
          return self.rules_directory.get_absolute_path()
  
      def set_directory_fn(path):
          (
              dir_choice,
              custom_path,
          ) = self.rules_directory.get_parts_from_path(path)
  
          self.rules_directory.join_parts(dir_choice, custom_path)
  
      self.rules_file_name = Filename(
          "Rules or classifier file name",
          "rules.txt",
          get_directory_fn=get_directory_fn,
          set_directory_fn=set_directory_fn,
          doc="""\
  *(Used only when filtering using {MODE_RULES} or {MODE_CLASSIFIERS})*
  
  The name of the rules or classifier file.
  
  A rules file is a plain text file containing the complete set of rules.
  
  Each line of the rules file should be a rule naming a measurement to be made
  on the object you selected, for instance:
  
      IF (Nuclei_AreaShape_Area < 351.3, [0.79, -0.79], [-0.94, 0.94])
  
  The above rule will score +0.79 for the positive category and -0.94
  for the negative category for nuclei whose area is less than 351.3
  pixels and will score the opposite for nuclei whose area is larger.
  The filter adds positive and negative and keeps only objects whose
  positive score is higher than the negative score.
  
  A classifier file is a trained classifier exported from CellProfiler Analyst.
  You will need to ensure that the measurements specified by the file are
  produced by upstream modules in the pipeline. This setting is not compatible
  with data processed as 3D.
  """.format(
              **{
                  "MODE_CLASSIFIERS": MODE_CLASSIFIERS,
                  "MODE_RULES": MODE_RULES,
              }
          ),
      )
  
      self.keep_removed_objects = Binary(
          "Keep removed objects as a separate set?",
          False,
          doc="""
  Select *Yes* to create an object set from objects that did not pass your filter.
              
  This may be useful if you want to make use of the negative (filtered out) population as well.""",
      )
  
      self.removed_objects_name = LabelName(
          "Name the objects removed by the filter",
          "RemovedObjects",
          doc="Enter the name you want to call the objects removed by the filter.",
      )
  
      self.additional_objects = []
  
      self.additional_object_count = HiddenCount(
          self.additional_objects, "Additional object count"
      )
  
      self.spacer_3 = Divider(line=True)
  
      self.spacer_4 = Divider(line=False)
  
      self.additional_object_button = DoSomething(
          "Relabel additional objects to match the filtered object?",
          "Add an additional object",
          self.add_additional_object,
          doc="""\
  Click this button to add an object to receive the same post-filtering labels as
  the filtered object. This is useful in making sure that labeling is maintained
  between related objects (e.g., primary and secondary objects) after filtering.""",
      )
  
      self.rules.create_settings()
  
      self.allow_fuzzy = self.rules.settings()[0]
  
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 2 for calling the FilterObjects obj's underlying member method code with example usage: obj.create_settings() and returns: self