code: def make_workspace(image, mask=None, labels=None):
      """Make a workspace and IdentifyPrimaryObjects module
  
      image - the intensity image for thresholding
  
      mask - if present, the "don't analyze" mask of the intensity image
  
      labels - if thresholding per-object, the labels matrix needed
      """
      module = (
          cellprofiler.modules.identifyprimaryobjects.IdentifyPrimaryObjects()
      )
      module.set_module_num(1)
      module.x_name.value = IMAGE_NAME
      module.y_name.value = OBJECTS_NAME
  
      pipeline = cellprofiler_core.pipeline.Pipeline()
      pipeline.add_module(module)
      m = cellprofiler_core.measurement.Measurements()
      cpimage = cellprofiler_core.image.Image(image, mask=mask)
      m.add(IMAGE_NAME, cpimage)
      object_set = cellprofiler_core.object.ObjectSet()
      if labels is not None:
          o = cellprofiler_core.object.Objects()
          o.segmented = labels
          object_set.add_objects(o, MASKING_OBJECTS_NAME)
      workspace = cellprofiler_core.workspace.Workspace(
          pipeline, module, m, object_set, m, None
      )
      return workspace, module
  
imports: import io
  import os
  import centrosome.threshold
  import numpy
  import pytest
  import scipy.ndimage
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  from cellprofiler_core.constants.measurement import FF_COUNT, COLTYPE_INTEGER, FF_FINAL_THRESHOLD, COLTYPE_FLOAT, FF_ORIG_THRESHOLD, M_NUMBER_OBJECT_NUMBER, M_LOCATION_CENTER_X, M_LOCATION_CENTER_Y, M_LOCATION_CENTER_Z, FF_SUM_OF_ENTROPIES, FF_WEIGHTED_VARIANCE
  from cellprofiler_core.constants.module._identify import TS_GLOBAL, TS_ADAPTIVE, O_TWO_CLASS, O_FOREGROUND, O_THREE_CLASS, O_BACKGROUND, RB_MODE, RB_SD, RB_MEAN, RB_MEDIAN, RB_MAD, TS_MANUAL, TS_MEASUREMENT
  from cellprofiler_core.image import VanillaImage
  import cellprofiler.modules.identifyprimaryobjects
  import cellprofiler.modules.threshold
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.setting
  import cellprofiler_core.workspace
  import tests.frontend
  import tests.frontend.modules
label_desc: Use image node_id 2 for calling a global function with example usage: make_workspace(image, mask, labels) and returns: workspace,  module