code: def add_threshold_group(self, image_group=None, can_remove=True):
      group = ImageQualitySettingsGroup()
  
      if image_group is not None:
          image_group.threshold_groups.append(group)
          group.image_names = image_group.image_names
  
      group.append("divider", Divider(line=False))
  
      group.append(
          "threshold_method",
          Choice(
              "Select a thresholding method",
              centrosome.threshold.TM_METHODS,
              centrosome.threshold.TM_OTSU,
              doc="""\
  *(Used only if particular thresholds are to be calculated)*
  
  This setting allows you to apply automatic thresholding methods used in
  the **Identify** modules. Only the global methods are applied. For more
  help on thresholding, see the **Identify** modules.""",
          ),
      )
  
      group.append(
          "object_fraction",
          Float(
              text="Typical fraction of the image covered by objects",
              value=0.1,
              minval=0,
              maxval=1,
              doc="""\
  *(Used only if thresholds are calculated and {TM_MOG} thresholding is
  chosen)*
  
  Enter the approximate fraction of the typical image in the set that is
  covered by objects.
  """.format(
                  **{"TM_MOG": centrosome.threshold.TM_MOG}
              ),
          ),
      )
  
      group.append(
          "two_class_otsu",
          Choice(
              text="Two-class or three-class thresholding?",
              choices=[O_TWO_CLASS, O_THREE_CLASS],
              doc="""\
  *(Used only if thresholds are calculated and the {TM_OTSU}
  thresholding method is used)*
  
  Select *{O_TWO_CLASS}* if the grayscale levels are readily
  distinguishable into foreground (i.e., objects) and background. Select
  *{O_THREE_CLASS}* if there is a middle set of grayscale levels
  that belongs to neither the foreground nor background.
  
  For example, three-class thresholding may be useful for images in which
  you have nuclear staining along with a low-intensity non-specific cell
  staining. Where two-class thresholding might incorrectly assign this
  intermediate staining to the nuclei objects, three-class thresholding
  allows you to assign it to the foreground or background as desired.
  However, in extreme cases where either there are almost no objects or
  the entire field of view is covered with objects, three-class
  thresholding may perform worse than two-class.
  """.format(
                  **{
                      "TM_OTSU": centrosome.threshold.TM_OTSU,
                      "O_TWO_CLASS": O_TWO_CLASS,
                      "O_THREE_CLASS": O_THREE_CLASS,
                  }
              ),
          ),
      )
  
      group.append(
          "use_weighted_variance",
          Choice(
              text="Minimize the weighted variance or the entropy?",
              choices=[O_WEIGHTED_VARIANCE, O_ENTROPY],
              doc="""\
  Choose whether to minimize the weighted variance or the entropy when selecting
  the threshold.""",
          ),
      )
  
      group.append(
          "assign_middle_to_foreground",
          Choice(
              text="Assign pixels in the middle intensity class to the foreground or the background?",
              choices=[O_FOREGROUND, O_BACKGROUND],
              doc="""\
  *(Used only if thresholds are calculated and the {TM_OTSU}
  thresholding method with {O_THREE_CLASS} is used)*
  
  Choose whether you want the middle grayscale intensities to be assigned
  to the foreground pixels or the background pixels.
  """.format(
                  **{
                      "TM_OTSU": centrosome.threshold.TM_OTSU,
                      "O_THREE_CLASS": O_THREE_CLASS,
                  }
              ),
          ),
      )
  
      group.can_remove = can_remove
      if can_remove and image_group is not None:
          group.append(
              "remove_button",
              RemoveSettingButton(
                  "",
                  "Remove this threshold method",
                  image_group.threshold_groups,
                  group,
              ),
          )
  
      if image_group is None:
          return group
  
imports: import itertools
  import logging
  import cellprofiler_core.utilities.image
  import centrosome.cpmorphology
  import centrosome.haralick
  import centrosome.radial_power_spectrum
  import centrosome.threshold
  import centrosome.threshold
  import numpy
  import scipy.linalg.basic
  import scipy.ndimage
  from cellprofiler_core.constants.image import C_SCALING
  from cellprofiler_core.constants.measurement import COLTYPE_FLOAT, EXPERIMENT, MCA_AVAILABLE_POST_RUN
  from cellprofiler_core.constants.module._identify import O_WEIGHTED_VARIANCE, O_ENTROPY, O_FOREGROUND, O_BACKGROUND
  from cellprofiler_core.module import Module
  from cellprofiler_core.preferences import get_headless
  from cellprofiler_core.setting import Divider, HiddenCount, SettingsGroup, Binary, ValidationError
  from cellprofiler_core.setting.choice import Choice
  from cellprofiler_core.setting.do_something import DoSomething, RemoveSettingButton
  from cellprofiler_core.setting.subscriber import ImageListSubscriber
  from cellprofiler_core.setting.text import ImageName, Integer, Float
  from cellprofiler.modules.threshold import O_THREE_CLASS, O_TWO_CLASS
label_desc: Use image node_id 4 for calling the MeasureImageQuality obj's underlying member method code with example usage: obj.add_threshold_group(image_group, can_remove) and returns: group