docstr: Count the # of pixels at saturation
docstr_tok: ["Count","the","#","of","pixels","at","saturation"]
code: def calculate_saturation(self, image_group, workspace):
      """Count the # of pixels at saturation"""
  
      result = []
      for image_name in self.images_to_process(image_group, workspace):
          image = workspace.image_set.get_image(
              image_name, must_be_grayscale=True
          )
          pixel_data = image.pixel_data
          if image.has_mask:
              pixel_data = pixel_data[image.mask]
          pixel_count = numpy.product(pixel_data.shape)
          if pixel_count == 0:
              percent_maximal = 0
              percent_minimal = 0
          else:
              number_pixels_maximal = numpy.sum(
                  pixel_data == numpy.max(pixel_data)
              )
              number_pixels_minimal = numpy.sum(
                  pixel_data == numpy.min(pixel_data)
              )
              percent_maximal = (
                  100.0
                  * float(number_pixels_maximal)
                  / float(pixel_count)
              )
              percent_minimal = (
                  100.0
                  * float(number_pixels_minimal)
                  / float(pixel_count)
              )
          percent_maximal_name = "{}_{}_{}".format(
              C_IMAGE_QUALITY, F_PERCENT_MAXIMAL, image_name
          )
          percent_minimal_name = "{}_{}_{}".format(
              C_IMAGE_QUALITY, F_PERCENT_MINIMAL, image_name
          )
          workspace.add_measurement(
              "Image",
              percent_maximal_name,
              percent_maximal,
          )
          workspace.add_measurement(
              "Image",
              percent_minimal_name,
              percent_minimal,
          )
          result += [
              [
                  "{} maximal".format(image_name),
                  "{:.1f} %".format(percent_maximal),
              ],
              [
                  "{} minimal".format(image_name),
                  "{:.1f} %".format(percent_minimal),
              ],
          ]
      return result
  
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 30 for calling the MeasureImageQuality obj's underlying member method code with example usage: obj.calculate_saturation(image_group, workspace) and returns: result