code: def make_pipeline(
      image,
      mask,
      subsample_size,
      image_sample_size,
      element_size,
      granular_spectrum_length,
      labels=None,
  ):
      """Make a pipeline with a MeasureGranularity module
  
      image - measure granularity on this image
      mask - exclude / include pixels from measurement. None = no mask
      subsample_size, etc. - values for corresponding settings in the module
      returns tuple of module & workspace
      """
      module = (
          cellprofiler.modules.measuregranularity.MeasureGranularity()
      )
      module.set_module_num(1)
      module.images_list.value = IMAGE_NAME
      module.subsample_size.value = subsample_size
      module.image_sample_size.value = image_sample_size
      module.element_size.value = element_size
      module.granular_spectrum_length.value = granular_spectrum_length
      image_set_list = cellprofiler_core.image.ImageSetList()
      image_set = image_set_list.get_image_set(0)
      img = cellprofiler_core.image.Image(image, mask)
      image_set.add(IMAGE_NAME, img)
      pipeline = cellprofiler_core.pipeline.Pipeline()
  
      def error_callback(event, caller):
          assert not isinstance(
              event, cellprofiler_core.pipeline.event.RunException
          )
  
      pipeline.add_listener(error_callback)
      pipeline.add_module(module)
      object_set = cellprofiler_core.object.ObjectSet()
      if labels is not None:
          objects = cellprofiler_core.object.Objects()
          objects.segmented = labels
          object_set.add_objects(objects, OBJECTS_NAME)
          module.objects_list.value = OBJECTS_NAME
      workspace = cellprofiler_core.workspace.Workspace(
          pipeline,
          module,
          image_set,
          object_set,
          cellprofiler_core.measurement.Measurements(),
          image_set_list,
      )
      return module, workspace
  
imports: import sys
  import numpy
  import six.moves
  import cellprofiler_core.image
  import cellprofiler.modules.measuregranularity
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.workspace
  import tests.frontend.modules
label_desc: Use image node_id 2 for calling a global function with example usage: make_pipeline(image, mask, subsample_size, image_sample_size, element_size, granular_spectrum_length, labels) and returns: module,  workspace