code: def create_settings(self):
      super(IdentifyPrimaryObjects, self).create_settings()
  
      self.x_name.text = "Select the input image"
      self.x_name.doc = (
          "Select the image that you want to use to identify objects."
      )
  
      self.y_name.text = "Name the primary objects to be identified"
      self.y_name.doc = "Enter the name that you want to call the objects identified by this module."
  
      self.size_range = IntegerRange(
          SIZE_RANGE_SETTING_TEXT,
          (10, 40),
          minval=1,
          doc="""\
  This setting is crucial for two reasons: first, the module uses it to
  calculate certain automatic settings in order to identify your objects
  of interest properly (see below). Second, when used in conjunction with the
  *{EXCLUDE_SIZE_SETTING_TEXT}* setting below, you can choose to remove
  objects outside the size range you provide here.
  
  |image0| The units used here are pixels so that it is easy to zoom in
  on objects and determine typical diameters. {HELP_ON_MEASURING_DISTANCES}
  
  A few important notes:
  
  -  The other settings that make use of the minimum object size entered
     here (whether the "*{EXCLUDE_SIZE_SETTING_TEXT}*" setting is used or
     not) are:
  
     -  "*{AUTOMATIC_SMOOTHING_SETTING_TEXT}*"
     -  "*{AUTOMATIC_MAXIMA_SUPPRESSION_SETTING_TEXT}*"
  
  -  For non-round objects, the diameter you should enter here is actually
     the “equivalent diameter”, i.e., the diameter of a circle with the
     same area as the object.
  
  .. |image0| image:: {PROTIP_RECOMMEND_ICON}
              """.format(
              **{
                  "EXCLUDE_SIZE_SETTING_TEXT": EXCLUDE_SIZE_SETTING_TEXT,
                  "PROTIP_RECOMMEND_ICON": _help.PROTIP_RECOMMEND_ICON,
                  "HELP_ON_MEASURING_DISTANCES": _help.HELP_ON_MEASURING_DISTANCES,
                  "AUTOMATIC_SMOOTHING_SETTING_TEXT": AUTOMATIC_SMOOTHING_SETTING_TEXT,
                  "AUTOMATIC_MAXIMA_SUPPRESSION_SETTING_TEXT": AUTOMATIC_MAXIMA_SUPPRESSION_SETTING_TEXT,
              }
          ),
      )
  
      self.exclude_size = Binary(
          EXCLUDE_SIZE_SETTING_TEXT,
          True,
          doc="""\
  Select "*{YES}*" to discard objects outside the range you specified in the
  *{SIZE_RANGE_SETTING_TEXT}* setting. Select "*{NO}*" to ignore this
  criterion.
  
  Objects discarded based on size are outlined in magenta in the module’s
  display. See also the **FilterObjects** module to further discard
  objects based on some other measurement.
  
  |image0| Select "*{YES}*" to exclude small objects (e.g.,
  dust, noise, and debris) or large objects (e.g., large clumps) if
  desired.
  
  .. |image0| image:: {PROTIP_RECOMMEND_ICON}
              """.format(
              **{
                  "YES": "Yes",
                  "SIZE_RANGE_SETTING_TEXT": SIZE_RANGE_SETTING_TEXT,
                  "NO": "No",
                  "PROTIP_RECOMMEND_ICON": _help.PROTIP_RECOMMEND_ICON,
              }
          ),
      )
  
      self.exclude_border_objects = Binary(
          "Discard objects touching the border of the image?",
          True,
          doc="""\
  Choose "*{YES}*" to discard objects that touch the border of the image.
  Choose "*{NO}*" to ignore this criterion.
  
  Objects discarded because they touch the border are outlined in yellow in the
  module’s display. Note that if a per-object thresholding method is used
  or if the image has been previously cropped or masked, objects that
  touch the border of the cropped or masked region may also discarded.
  
  |image0| Removing objects that touch the image border is useful when
  you do not want to make downstream measurements of objects that are not
  fully within the field of view. For example, measuring the area of a
  partial object would not be accurate.
  
  .. |image0| image:: {PROTIP_RECOMMEND_ICON}
              """.format(
              **{
                  "YES": "Yes",
                  "NO": "No",
                  "PROTIP_RECOMMEND_ICON": _help.PROTIP_RECOMMEND_ICON,
              }
          ),
      )
  
      self.unclump_method = Choice(
          "Method to distinguish clumped objects",
          [UN_INTENSITY, UN_SHAPE, UN_NONE],
          doc="""\
  This setting allows you to choose the method that is used to distinguish
  between individual objects that are touching each other (and not properly
  delineated as two objects by thresholding alone). In other words, this
  setting allows you to “declump” a large, merged object into individual objects
  of interest. To decide between these methods, you can run Test mode to
  see the results of each.
  
     +--------------------------------------+--------------------------------------+
     | *{UN_INTENSITY}:* For objects that        | |image1|                             |
     | tend to have only a single peak of   |                                      |
     | brightness (e.g., objects that are   |                                      |
     | brighter towards their interiors and |                                      |
     | dimmer towards their edges), this    |                                      |
     | option counts each intensity peak as |                                      |
     | a separate object. The objects can   |                                      |
     | be any shape, so they need not be    |                                      |
     | round and uniform in size as would   |                                      |
     | be required for the *{UN_SHAPE}*          |                                      |
     | option.                              |                                      |
     |                                      |                                      |
     | |image0|  This choice is more        |                                      |
     | successful when the objects have a   |                                      |
     | smooth texture. By default, the      |                                      |
     | image is automatically blurred to    |                                      |
     | attempt to achieve appropriate       |                                      |
     | smoothness (see *Smoothing filter*   |                                      |
     | options), but overriding the default |                                      |
     | value can improve the outcome on     |                                      |
     | lumpy-textured objects.              |                                      |
     |                                      |                                      |
     | |image2|  The object centers are     |                                      |
     | defined as local intensity maxima in |                                      |
     | the smoothed image.                  |                                      |
     +--------------------------------------+--------------------------------------+
     | *{UN_SHAPE}:* For cases when there        | |image4|                             |
     | are definite indentations separating |                                      |
     | objects. The image is converted to   |                                      |
     | black and white (binary) and the     |                                      |
     | shape determines whether clumped     |                                      |
     | objects will be distinguished. The   |                                      |
     | declumping results of this method    |                                      |
     | are affected by the thresholding     |                                      |
     | method you choose.                   |                                      |
     |                                      |                                      |
     | |image3|  This choice works best for |                                      |
     | objects that are round. In this      |                                      |
     | case, the intensity patterns         |                                      |
     | (i.e., lumpy texture) in the         |                                      |
     | original image are largely           |                                      |
     | irrelevant. Therefore, the cells     |                                      |
     | need not be brighter towards the     |                                      |
     | interior as is required for the      |                                      |
     | *{UN_INTENSITY}* option.                  |                                      |
     |                                      |                                      |
     | |image5|  The binary thresholded     |                                      |
     | image is distance-transformed and    |                                      |
     | object centers are defined as peaks  |                                      |
     | in this image. A distance-transform  |                                      |
     | gives each pixel a value equal to    |                                      |
     | the nearest pixel below a certain    |                                      |
     | threshold, so it indicates the       |                                      |
     | *{UN_SHAPE}* of the object.               |                                      |
     +--------------------------------------+--------------------------------------+
     | *{UN_NONE}:* If objects are well separated and bright relative to the            |
     | background, it may be unnecessary to attempt to separate clumped objects.   |
     | Using the very fast *{UN_NONE}* option, a simple threshold will be used to       |
     | identify objects.                                                           |
     +--------------------------------------+--------------------------------------+
  
  .. |image0| image:: {PROTIP_RECOMMEND_ICON}
  .. |image1| image:: {INTENSITY_DECLUMPING_ICON}
  .. |image2| image:: {TECH_NOTE_ICON}
  .. |image3| image:: {PROTIP_RECOMMEND_ICON}
  .. |image4| image:: {SHAPE_DECLUMPING_ICON}
  .. |image5| image:: {TECH_NOTE_ICON}
              """.format(
              **{
                  "UN_INTENSITY": UN_INTENSITY,
                  "UN_SHAPE": UN_SHAPE,
                  "PROTIP_RECOMMEND_ICON": _help.PROTIP_RECOMMEND_ICON,
                  "INTENSITY_DECLUMPING_ICON": INTENSITY_DECLUMPING_ICON,
                  "TECH_NOTE_ICON": _help.TECH_NOTE_ICON,
                  "SHAPE_DECLUMPING_ICON": SHAPE_DECLUMPING_ICON,
                  "UN_NONE": UN_NONE,
              }
          ),
      )
  
      self.watershed_method = Choice(
          "Method to draw dividing lines between clumped objects",
          [WA_INTENSITY, WA_SHAPE, WA_PROPAGATE, WA_NONE],
          doc="""\
  This setting allows you to choose the method that is used to draw the
  line between segmented objects, provided that you have chosen to declump
  the objects. To decide between these methods, you can run Test mode to
  see the results of each.
  
  -  *{WA_INTENSITY}:* Works best where the dividing lines between
     clumped objects are dimmer than the remainder of the objects.
  
     **Technical description:** Using the previously identified local
     maxima as seeds, this method is a watershed (*Vincent and Soille,
     1991*) on the intensity image.
  
  -  *{WA_SHAPE}:* Dividing lines between clumped objects are based on
     the shape of the clump. For example, when a clump contains two
     objects, the dividing line will be placed where indentations occur
     between the two objects. The intensity patterns in the original image
     are largely irrelevant: the cells need not be dimmer along the lines
     between clumped objects. Technical description: Using the previously
     identified local maxima as seeds, this method is a watershed on the
     distance-transformed thresholded image.
  -  *{WA_PROPAGATE}:* This method uses a propagation algorithm instead
     of a watershed. The image is ignored and the pixels are assigned to
     the objects by repeatedly adding unassigned pixels to the objects
     that are immediately adjacent to them. This method is suited in cases
     such as objects with branching extensions, for instance neurites,
     where the goal is to trace outward from the cell body along the
     branch, assigning pixels in the branch along the way. See the help
     for the **IdentifySecondaryObjects** module for more details on this
     method.
  -  *{WA_NONE}*: If objects are well separated and bright relative to
     the background, it may be unnecessary to attempt to separate clumped
     objects. Using the very fast *{WA_NONE}* option, a simple threshold
     will be used to identify objects.
  """.format(
              **{
                  "WA_INTENSITY": WA_INTENSITY,
                  "WA_SHAPE": WA_SHAPE,
                  "WA_PROPAGATE": WA_PROPAGATE,
                  "WA_NONE": WA_NONE,
              }
          ),
      )
  
      self.automatic_smoothing = Binary(
          AUTOMATIC_SMOOTHING_SETTING_TEXT,
          True,
          doc="""\
  *(Used only when distinguishing between clumped objects)*
  
  Select "*{YES}*" to automatically calculate the amount of smoothing
  applied to the image to assist in declumping. Select "*{NO}*" to
  manually enter the smoothing filter size.
  
  This setting, along with the *Minimum allowed distance between local
  maxima* setting, affects whether objects close to each other are
  considered a single object or multiple objects. It does not affect the
  dividing lines between an object and the background.
  
  Please note that this smoothing setting is applied after thresholding,
  and is therefore distinct from the threshold smoothing method setting
  above, which is applied *before* thresholding.
  
  The size of the smoothing filter is automatically calculated based on
  the *{SIZE_RANGE_SETTING_TEXT}* setting above. If you see too many
  objects merged that ought to be separate or too many objects split up
  that ought to be merged, you may want to override the automatically
  calculated value.""".format(
              **{
                  "YES": "Yes",
                  "NO": "No",
                  "SIZE_RANGE_SETTING_TEXT": SIZE_RANGE_SETTING_TEXT,
              }
          ),
      )
  
      self.smoothing_filter_size = Integer(
          SMOOTHING_FILTER_SIZE_SETTING_TEXT,
          10,
          doc="""\
  *(Used only when distinguishing between clumped objects)*
  
  If you see too many objects merged that ought to be separated
  (under-segmentation), this value should be lower. If you see too many
  objects split up that ought to be merged (over-segmentation), the
  value should be higher.
  
  Note that splitting and merging is also
  affected by your choice of settings for the setting,
  *{AUTOMATIC_MAXIMA_SUPPRESSION_SETTING_TEXT}* It is an art to balance
  these two settings; read the help carefully for both.
  
  Reducing the texture of objects by increasing the smoothing increases
  the chance that each real, distinct object has only one peak of
  intensity but also increases the chance that two distinct objects will
  be recognized as only one object. Note that increasing the size of the
  smoothing filter increases the processing time exponentially.
  
  Enter 0 to prevent any image smoothing in certain cases; for example,
  for low resolution images with small objects ( < ~5 pixels in
  diameter).
  """.format(
              **{
                  "AUTOMATIC_MAXIMA_SUPPRESSION_SETTING_TEXT": AUTOMATIC_MAXIMA_SUPPRESSION_SETTING_TEXT
              }
          ),
      )
  
      self.automatic_suppression = Binary(
          AUTOMATIC_MAXIMA_SUPPRESSION_SETTING_TEXT,
          True,
          doc="""\
  *(Used only when distinguishing between clumped objects)*
  
  Select "*{YES}*" to automatically calculate the distance between
  intensity maxima to assist in declumping. Select "*{NO}*" to manually
  enter the permissible maxima distance.
  
  This setting, along with the *{SMOOTHING_FILTER_SIZE_SETTING_TEXT}*
  setting, affects whether objects close to each other are considered a
  single object or multiple objects. It does not affect the dividing lines
  between an object and the background. Local maxima that are closer
  together than the minimum allowed distance will be suppressed (the local
  intensity histogram is smoothed to remove the peaks within that
  distance).
  
  The distance can be automatically calculated based on the
  minimum entered for the *{SIZE_RANGE_SETTING_TEXT}* setting above,
  but if you see too many objects merged that ought to be separate, or too
  many objects split up that ought to be merged, you may want to override
  the automatically calculated value.""".format(
              **{
                  "YES": "Yes",
                  "NO": "No",
                  "SMOOTHING_FILTER_SIZE_SETTING_TEXT": SMOOTHING_FILTER_SIZE_SETTING_TEXT,
                  "SIZE_RANGE_SETTING_TEXT": SIZE_RANGE_SETTING_TEXT,
              }
          ),
      )
  
      self.maxima_suppression_size = Float(
          "Suppress local maxima that are closer than this minimum allowed distance",
          7,
          minval=0,
          doc="""\
  *(Used only when distinguishing between clumped objects)*
  
  Enter a positive integer, in pixel units. If you see too many objects
  merged that ought to be separated (under-segmentation), the value
  should be lower. If you see too many objects split up that ought to be
  merged (over-segmentation), the value should be higher.
  
  The maxima suppression distance should be set to be roughly equivalent
  to the radius of the smallest object of interest that you would expect
  to see in the experiment. Any distinct
  “objects” that are found but are within two times this distance from
  each other will be assumed to be actually two lumpy parts of the same
  object, and they will be merged.
  
  Note that splitting and merging is also
  affected by your choice of settings for the setting,
  *{SMOOTHING_FILTER_SIZE_SETTING_TEXT}* It is an art to balance
  these two settings; read the help carefully for both.
  """.format(
              **{
                  "SMOOTHING_FILTER_SIZE_SETTING_TEXT": SMOOTHING_FILTER_SIZE_SETTING_TEXT
              }
          ),
      )
  
      self.low_res_maxima = Binary(
          "Speed up by using lower-resolution image to find local maxima?",
          True,
          doc="""\
  *(Used only when distinguishing between clumped objects)*
  
  Select "*{YES}*" to down-sample the image for declumping. This can be
  helpful for saving processing time on large images.
  
  Note that if you have entered a minimum object diameter of 10 or less,
  checking this box will have no effect.""".format(
              **{"YES": "Yes"}
          ),
      )
  
      self.fill_holes = Choice(
          "Fill holes in identified objects?",
          FH_ALL,
          value=FH_THRESHOLDING,
          doc="""\
  This option controls how holes (regions of background surrounded by one
  or more objects) are filled in:
  
  -  *{FH_THRESHOLDING}:* Fill in holes that are smaller than
     the maximum object size prior to declumping and to fill in any holes
     after declumping.
  -  *{FH_DECLUMP}:* Fill in holes located within identified
     objects after declumping.
  -  *{FH_NEVER}:* Leave holes within objects.
     Please note that if an object is located within a hole and
     this option is enabled, the object will be lost when the hole is
     filled in.""".format(
              **{
                  "FH_THRESHOLDING": FH_THRESHOLDING,
                  "FH_DECLUMP": FH_DECLUMP,
                  "FH_NEVER": FH_NEVER,
              }
          ),
      )
  
      self.limit_choice = Choice(
          "Handling of objects if excessive number of objects identified",
          [LIMIT_NONE, LIMIT_ERASE],
          doc="""\
  This setting deals with images that are segmented into an unreasonable
  number of objects. This might happen if the module calculates a low
  threshold or if the image has unusual artifacts.
  **IdentifyPrimaryObjects** can handle this condition in one of three
  ways:
  
  -  *{LIMIT_NONE}*: Continue processing regardless if large numbers of
     objects are found.
  -  *{LIMIT_ERASE}*: Erase all objects if the number of objects exceeds
     the maximum. This results in an image with no primary objects. This
     option is a good choice if a large number of objects indicates that
     the image should not be processed; it can save a lot of time in
     subsequent **Measure** modules.""".format(
              **{"LIMIT_NONE": LIMIT_NONE, "LIMIT_ERASE": LIMIT_ERASE}
          ),
      )
  
      self.maximum_object_count = Integer(
          "Maximum number of objects",
          value=500,
          minval=2,
          doc="""\
  *(Used only when handling images with large numbers of objects by
  erasing)*
  
  This setting limits the number of objects in the image. See the
  documentation for the previous setting for details.""",
      )
  
      self.want_plot_maxima = Binary(
          "Display accepted local maxima?",
          False,
          doc="""\
  *(Used only when distinguishing between clumped objects)*
              
  Note: As this only effects figure previews, maxima display settings will not be saved to the pipeline.
  
  Select "*{YES}*" to display detected local maxima on the object outlines plot. This can be
  helpful for fine-tuning segmentation parameters.
  
  Local maxima are small cluster of pixels from which objects are 'grown' during segmentation.
  Each object in a declumped segmentation will have a single maxima.
  
  For example, for intensity-based declumping, maxima should appear at the brightest points in an object.
  If obvious intensity peaks are missing they were probably removed by the filters set above.""".format(
              **{"YES": "Yes"}
          ),
      )
  
      self.maxima_color = Color(
          "Select maxima color",
          DEFAULT_MAXIMA_COLOR,
          doc="Maxima will be displayed in this color.",
      )
  
      self.maxima_size = Integer(
          "Select maxima size",
          value=1,
          minval=1,
          doc="Radius of the visible marker for each maxima."
          "You may want to increase this when working with large images.",
      )
  
      self.use_advanced = Binary(
          "Use advanced settings?",
          value=False,
          doc="""\
  Select "*{YES}*" to use advanced module settings.
  If "*{NO}*" is selected, the following settings are used:
  
  -  *{THRESHOLD_SCOPE_TEXT}*: {THRESHOLD_SCOPE_VALUE}
  -  *{THRESHOLD_METHOD_TEXT}*: {THRESHOLD_METHOD_VALUE}
  -  *{THRESHOLD_SMOOTHING_SCALE_TEXT}*:
     {THRESHOLD_SMOOTHING_SCALE_VALUE} (sigma = 1)
  -  *{THRESHOLD_CORRECTION_FACTOR_TEXT}*:
     {THRESHOLD_CORRECTION_FACTOR_VALUE}
  -  *{THRESHOLD_RANGE_TEXT}*: minimum {THRESHOLD_RANGE_MIN}, maximum
     {THRESHOLD_RANGE_MAX}
  -  *{UNCLUMP_METHOD_TEXT}*: {UNCLUMP_METHOD_VALUE}
  -  *{WATERSHED_METHOD_TEXT}*: {WATERSHED_METHOD_VALUE}
  -  *{AUTOMATIC_SMOOTHING_TEXT}*: *{YES}*
  -  *{AUTOMATIC_SUPPRESSION_TEXT}*: *{YES}*
  -  *{LOW_RES_MAXIMA_TEXT}*: *{YES}*
  -  *{FILL_HOLES_TEXT}*: {FILL_HOLES_VALUE}
  -  *{LIMIT_CHOICE_TEXT}*: {LIMIT_CHOICE_VALUE}""".format(
              **{
                  "AUTOMATIC_SMOOTHING_TEXT": self.automatic_smoothing.get_text(),
                  "AUTOMATIC_SUPPRESSION_TEXT": self.automatic_suppression.get_text(),
                  "FILL_HOLES_TEXT": self.fill_holes.get_text(),
                  "FILL_HOLES_VALUE": FH_THRESHOLDING,
                  "LIMIT_CHOICE_TEXT": self.limit_choice.get_text(),
                  "LIMIT_CHOICE_VALUE": LIMIT_NONE,
                  "LOW_RES_MAXIMA_TEXT": self.low_res_maxima.get_text(),
                  "NO": "No",
                  "THRESHOLD_CORRECTION_FACTOR_TEXT": self.threshold.threshold_correction_factor.get_text(),
                  "THRESHOLD_CORRECTION_FACTOR_VALUE": 1.0,
                  "THRESHOLD_METHOD_TEXT": self.threshold.global_operation.get_text(),
                  "THRESHOLD_METHOD_VALUE": threshold.TM_LI,
                  "THRESHOLD_RANGE_MAX": 1.0,
                  "THRESHOLD_RANGE_MIN": 0.0,
                  "THRESHOLD_RANGE_TEXT": self.threshold.threshold_range.get_text(),
                  "THRESHOLD_SCOPE_TEXT": self.threshold.threshold_scope.get_text(),
                  "THRESHOLD_SCOPE_VALUE": threshold.TS_GLOBAL,
                  "THRESHOLD_SMOOTHING_SCALE_TEXT": self.threshold.threshold_smoothing_scale.get_text(),
                  "THRESHOLD_SMOOTHING_SCALE_VALUE": 1.3488,
                  "UNCLUMP_METHOD_TEXT": self.unclump_method.get_text(),
                  "UNCLUMP_METHOD_VALUE": UN_INTENSITY,
                  "WATERSHED_METHOD_TEXT": self.watershed_method.get_text(),
                  "WATERSHED_METHOD_VALUE": WA_INTENSITY,
                  "YES": "Yes",
              }
          ),
      )
  
      self.threshold_setting_version = Integer(
          "Threshold setting version",
          value=self.threshold.variable_revision_number,
      )
  
      self.threshold.create_settings()
  
      self.threshold.threshold_smoothing_scale.value = 1.3488
  
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 3 for calling the IdentifyPrimaryObjects obj's underlying member method code with example usage: obj.create_settings() without return types