docstr: Apply the function once to the image, returning the result
docstr_tok: ["Apply","the","function","once","to","the","image",",","returning","the","result"]
code: def run_function(self, function, pixel_data, mask):
      """Apply the function once to the image, returning the result"""
      count = function.repeat_count
      function_name = function.function.value
      custom_repeats = function.custom_repeats.value
  
      is_binary = pixel_data.dtype.kind == "b"
  
      if (
          function_name
          in (
              F_BRANCHPOINTS,
              F_BRIDGE,
              F_CLEAN,
              F_DIAG,
              F_CONVEX_HULL,
              F_DISTANCE,
              F_ENDPOINTS,
              F_FILL,
              F_HBREAK,
              F_MAJORITY,
              F_REMOVE,
              F_SHRINK,
              F_SKELPE,
              F_SPUR,
              F_THICKEN,
              F_THIN,
              F_VBREAK,
          )
          and not is_binary
      ):
          # Apply a very crude threshold to the image for binary algorithms
          LOGGER.warning(
              "Warning: converting image to binary for %s\n"
              % function_name
          )
          pixel_data = pixel_data != 0
  
      if function_name in (
          F_BRANCHPOINTS,
          F_BRIDGE,
          F_CLEAN,
          F_DIAG,
          F_CONVEX_HULL,
          F_DISTANCE,
          F_ENDPOINTS,
          F_FILL,
          F_HBREAK,
          F_MAJORITY,
          F_REMOVE,
          F_SHRINK,
          F_SKELPE,
          F_SPUR,
          F_THICKEN,
          F_THIN,
          F_VBREAK,
          F_OPENLINES,
      ):
          # All of these have an iterations argument or it makes no
          # sense to iterate
          if function_name == F_BRANCHPOINTS:
              return centrosome.cpmorphology.branchpoints(
                  pixel_data, mask
              )
          elif function_name == F_BRIDGE:
              return centrosome.cpmorphology.bridge(
                  pixel_data, mask, count
              )
          elif function_name == F_CLEAN:
              return centrosome.cpmorphology.clean(
                  pixel_data, mask, count
              )
          elif function_name == F_CONVEX_HULL:
              if mask is None:
                  return centrosome.cpmorphology.convex_hull_image(
                      pixel_data
                  )
              else:
                  return centrosome.cpmorphology.convex_hull_image(
                      pixel_data & mask
                  )
          elif function_name == F_DIAG:
              return centrosome.cpmorphology.diag(
                  pixel_data, mask, count
              )
          elif function_name == F_DISTANCE:
              image = scipy.ndimage.distance_transform_edt(pixel_data)
              if function.rescale_values.value:
                  image = image / numpy.max(image)
              return image
          elif function_name == F_ENDPOINTS:
              return centrosome.cpmorphology.endpoints(pixel_data, mask)
          elif function_name == F_FILL:
              return centrosome.cpmorphology.fill(
                  pixel_data, mask, count
              )
          elif function_name == F_HBREAK:
              return centrosome.cpmorphology.hbreak(
                  pixel_data, mask, count
              )
          elif function_name == F_MAJORITY:
              return centrosome.cpmorphology.majority(
                  pixel_data, mask, count
              )
          elif function_name == F_OPENLINES:
              return centrosome.cpmorphology.openlines(
                  pixel_data, linelength=custom_repeats, mask=mask
              )
          elif function_name == F_REMOVE:
              return centrosome.cpmorphology.remove(
                  pixel_data, mask, count
              )
          elif function_name == F_SHRINK:
              return centrosome.cpmorphology.binary_shrink(
                  pixel_data, count
              )
          elif function_name == F_SKELPE:
              return centrosome.cpmorphology.skeletonize(
                  pixel_data,
                  mask,
                  scipy.ndimage.distance_transform_edt(pixel_data)
                  * centrosome.filter.poisson_equation(pixel_data),
              )
          elif function_name == F_SPUR:
              return centrosome.cpmorphology.spur(
                  pixel_data, mask, count
              )
          elif function_name == F_THICKEN:
              return centrosome.cpmorphology.thicken(
                  pixel_data, mask, count
              )
          elif function_name == F_THIN:
              return centrosome.cpmorphology.thin(
                  pixel_data, mask, count
              )
          elif function_name == F_VBREAK:
              return centrosome.cpmorphology.vbreak(pixel_data, mask)
          else:
              raise NotImplementedError(
                  "Unimplemented morphological function: %s"
                  % function_name
              )
          return pixel_data
  
imports: import logging
  import centrosome.cpmorphology
  import centrosome.filter
  import numpy
  import scipy.ndimage
  from cellprofiler_core.image import Image
  from cellprofiler_core.module import Module
  from cellprofiler_core.setting import Binary
  from cellprofiler_core.setting import Divider
  from cellprofiler_core.setting import SettingsGroup
  from cellprofiler_core.setting.choice import Choice
  from cellprofiler_core.setting.do_something import DoSomething
  from cellprofiler_core.setting.do_something import RemoveSettingButton
  from cellprofiler_core.setting.subscriber import ImageSubscriber
  from cellprofiler_core.setting.text import ImageName, Integer
label_desc: Use image node_id 8 for calling the Morph obj's underlying member method code with example usage: obj.run_function(function, pixel_data, mask) and returns: pixel_data, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome, image, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome, centrosome