code: def test_intermediate_images():
      """Make sure the average and dilated image flags work"""
      for average_flag, dilated_flag in (
          (False, False),
          (False, True),
          (True, False),
          (True, True),
      ):
          pipeline = cellprofiler_core.pipeline.Pipeline()
          pipeline.add_listener(error_callback)
          inj_module = (
              cellprofiler_core.modules.injectimage.InjectImage(
                  "InputImage", numpy.zeros((10, 10))
              )
          )
          inj_module.set_module_num(1)
          pipeline.add_module(inj_module)
          module = (
              cellprofiler.modules.correctilluminationcalculate.CorrectIlluminationCalculate()
          )
          module.set_module_num(2)
          pipeline.add_module(module)
          module.image_name.value = "InputImage"
          module.illumination_image_name.value = "OutputImage"
          module.save_average_image.value = average_flag
          module.average_image_name.value = "AverageImage"
          module.save_dilated_image.value = dilated_flag
          module.dilated_image_name.value = "DilatedImage"
          measurements = cellprofiler_core.measurement.Measurements()
          image_set_list = cellprofiler_core.image.ImageSetList()
          workspace = cellprofiler_core.workspace.Workspace(
              pipeline, None, None, None, measurements, image_set_list
          )
          pipeline.prepare_run(workspace)
          inj_module.prepare_group(workspace, {}, [1])
          module.prepare_group(workspace, {}, [1])
          image_set = image_set_list.get_image_set(0)
          object_set = cellprofiler_core.object.ObjectSet()
          workspace = cellprofiler_core.workspace.Workspace(
              pipeline,
              inj_module,
              image_set,
              object_set,
              measurements,
              image_set_list,
          )
          inj_module.run(workspace)
          module.run(workspace)
          if average_flag:
              img = image_set.get_image("AverageImage")
          else:
              with pytest.raises(AssertionError):
                  image_set.get_image("AverageImage")
          if dilated_flag:
              img = image_set.get_image("DilatedImage")
          else:
              with pytest.raises(AssertionError):
                  image_set.get_image("DilatedImage")
  
imports: import numpy
  import pytest
  from centrosome.bg_compensate import MODE_AUTO, MODE_BRIGHT, MODE_DARK, MODE_GRAY
  from six.moves import StringIO
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler.modules.correctilluminationcalculate
  import cellprofiler_core.modules.injectimage
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.setting
  import cellprofiler_core.workspace
  import tests.frontend.modules
label_desc: Use image node_id 18 for calling a global function with example usage: test_intermediate_images() without return types