Esempio n. 1
0
def test_01_01_combine():
    img = get_my_image()
    inj = cellprofiler.modules.injectimage.InjectImage("my_image", img)
    inj.module_num = 1
    ctg = cellprofiler.modules.colortogray.ColorToGray()
    ctg.module_num = 2
    ctg.image_name.value = "my_image"
    ctg.combine_or_split.value = cellprofiler.modules.colortogray.COMBINE
    ctg.red_contribution.value = 1
    ctg.green_contribution.value = 2
    ctg.blue_contribution.value = 3
    ctg.grayscale_name.value = "my_grayscale"
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(inj)
    pipeline.add_module(ctg)
    pipeline.test_valid()

    measurements = cellprofiler.measurement.Measurements()
    object_set = cellprofiler.object.ObjectSet()
    image_set_list = cellprofiler.image.ImageSetList()
    workspace = Workspace(pipeline, inj, None, None, measurements,
                          image_set_list, None)
    inj.prepare_run(workspace)
    inj.prepare_group(workspace, {}, [1])
    image_set = image_set_list.get_image_set(0)
    inj.run(Workspace(pipeline, inj, image_set, object_set, measurements, None))
    ctg.run(Workspace(pipeline, ctg, image_set, object_set, measurements, None))
    grayscale = image_set.get_image("my_grayscale")
    assert grayscale
    img = grayscale.image
    numpy.testing.assert_almost_equal(img[0, 0], 1.0 / 6.0)
    numpy.testing.assert_almost_equal(img[0, 25], 1.0 / 3.0)
    numpy.testing.assert_almost_equal(img[25, 0], 1.0 / 2.0)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
Esempio n. 2
0
def test_split_all():
    img = get_my_image()
    inj = cellprofiler.modules.injectimage.InjectImage("my_image", img)
    inj.set_module_num(1)
    ctg = cellprofiler.modules.colortogray.ColorToGray()
    ctg.set_module_num(2)
    ctg.image_name.value = "my_image"
    ctg.combine_or_split.value = cellprofiler.modules.colortogray.SPLIT
    ctg.use_red.value = True
    ctg.use_blue.value = True
    ctg.use_green.value = True
    ctg.red_name.value = "my_red"
    ctg.green_name.value = "my_green"
    ctg.blue_name.value = "my_blue"
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(inj)
    pipeline.add_module(ctg)
    pipeline.test_valid()

    measurements = cellprofiler.measurement.Measurements()
    object_set = cellprofiler.object.ObjectSet()
    image_set_list = cellprofiler.image.ImageSetList()
    workspace = cellprofiler.workspace.Workspace(
        pipeline, inj, None, None, measurements, image_set_list, None
    )
    inj.prepare_run(workspace)
    inj.prepare_group(workspace, {}, [1])
    image_set = image_set_list.get_image_set(0)
    inj.run(
        cellprofiler.workspace.Workspace(
            pipeline, inj, image_set, object_set, measurements, None
        )
    )
    ctg.run(
        cellprofiler.workspace.Workspace(
            pipeline, ctg, image_set, object_set, measurements, None
        )
    )
    red = image_set.get_image("my_red")
    assert red
    img = red.image
    numpy.testing.assert_almost_equal(img[0, 0], 1)
    numpy.testing.assert_almost_equal(img[0, 25], 0)
    numpy.testing.assert_almost_equal(img[25, 0], 0)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
    green = image_set.get_image("my_green")
    assert green
    img = green.image
    numpy.testing.assert_almost_equal(img[0, 0], 0)
    numpy.testing.assert_almost_equal(img[0, 25], 1)
    numpy.testing.assert_almost_equal(img[25, 0], 0)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
    blue = image_set.get_image("my_blue")
    assert blue
    img = blue.image
    numpy.testing.assert_almost_equal(img[0, 0], 0)
    numpy.testing.assert_almost_equal(img[0, 25], 0)
    numpy.testing.assert_almost_equal(img[25, 0], 1)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
Esempio n. 3
0
def test_01_02_split_all():
    img = get_my_image()
    inj = cellprofiler.modules.injectimage.InjectImage("my_image", img)
    inj.module_num = 1
    ctg = cellprofiler.modules.colortogray.ColorToGray()
    ctg.module_num = 2
    ctg.image_name.value = "my_image"
    ctg.combine_or_split.value = cellprofiler.modules.colortogray.SPLIT
    ctg.use_red.value = True
    ctg.use_blue.value = True
    ctg.use_green.value = True
    ctg.red_name.value = "my_red"
    ctg.green_name.value = "my_green"
    ctg.blue_name.value = "my_blue"
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(inj)
    pipeline.add_module(ctg)
    pipeline.test_valid()

    measurements = cellprofiler.measurement.Measurements()
    object_set = cellprofiler.object.ObjectSet()
    image_set_list = cellprofiler.image.ImageSetList()
    workspace = Workspace(pipeline, inj, None, None, measurements,
                          image_set_list, None)
    inj.prepare_run(workspace)
    inj.prepare_group(workspace, {}, [1])
    image_set = image_set_list.get_image_set(0)
    inj.run(Workspace(pipeline, inj, image_set, object_set, measurements, None))
    ctg.run(Workspace(pipeline, ctg, image_set, object_set, measurements, None))
    red = image_set.get_image("my_red")
    assert red
    img = red.image
    numpy.testing.assert_almost_equal(img[0, 0], 1)
    numpy.testing.assert_almost_equal(img[0, 25], 0)
    numpy.testing.assert_almost_equal(img[25, 0], 0)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
    green = image_set.get_image("my_green")
    assert green
    img = green.image
    numpy.testing.assert_almost_equal(img[0, 0], 0)
    numpy.testing.assert_almost_equal(img[0, 25], 1)
    numpy.testing.assert_almost_equal(img[25, 0], 0)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
    blue = image_set.get_image("my_blue")
    assert blue
    img = blue.image
    numpy.testing.assert_almost_equal(img[0, 0], 0)
    numpy.testing.assert_almost_equal(img[0, 25], 0)
    numpy.testing.assert_almost_equal(img[25, 0], 1)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
Esempio n. 4
0
def test_combine():
    img = get_my_image()
    inj = cellprofiler.modules.injectimage.InjectImage("my_image", img)
    inj.set_module_num(1)
    ctg = cellprofiler.modules.colortogray.ColorToGray()
    ctg.set_module_num(2)
    ctg.image_name.value = "my_image"
    ctg.combine_or_split.value = cellprofiler.modules.colortogray.COMBINE
    ctg.red_contribution.value = 1
    ctg.green_contribution.value = 2
    ctg.blue_contribution.value = 3
    ctg.grayscale_name.value = "my_grayscale"
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(inj)
    pipeline.add_module(ctg)
    pipeline.test_valid()

    measurements = cellprofiler.measurement.Measurements()
    object_set = cellprofiler.object.ObjectSet()
    image_set_list = cellprofiler.image.ImageSetList()
    workspace = cellprofiler.workspace.Workspace(
        pipeline, inj, None, None, measurements, image_set_list, None
    )
    inj.prepare_run(workspace)
    inj.prepare_group(workspace, {}, [1])
    image_set = image_set_list.get_image_set(0)
    inj.run(
        cellprofiler.workspace.Workspace(
            pipeline, inj, image_set, object_set, measurements, None
        )
    )
    ctg.run(
        cellprofiler.workspace.Workspace(
            pipeline, ctg, image_set, object_set, measurements, None
        )
    )
    grayscale = image_set.get_image("my_grayscale")
    assert grayscale
    img = grayscale.image
    numpy.testing.assert_almost_equal(img[0, 0], 1.0 / 6.0)
    numpy.testing.assert_almost_equal(img[0, 25], 1.0 / 3.0)
    numpy.testing.assert_almost_equal(img[25, 0], 1.0 / 2.0)
    numpy.testing.assert_almost_equal(img[25, 25], 0)
def test_module_must_be_last():
    """Make sure that the pipeline is invalid if CreateBatchFiles is not last"""
    #
    # First, make sure that a naked CPModule tests valid
    #
    pipeline = cellprofiler.pipeline.Pipeline()
    module = cellprofiler.module.Module()
    module.set_module_num(len(pipeline.modules()) + 1)
    pipeline.add_module(module)
    pipeline.test_valid()
    #
    # Make sure that CreateBatchFiles on its own tests valid
    #
    pipeline = cellprofiler.pipeline.Pipeline()
    module = cellprofiler.modules.createbatchfiles.CreateBatchFiles()
    module.set_module_num(len(pipeline.modules()) + 1)
    pipeline.add_module(module)
    pipeline.test_valid()

    module = cellprofiler.module.Module()
    module.set_module_num(len(pipeline.modules()) + 1)
    pipeline.add_module(module)
    with pytest.raises(cellprofiler.setting.ValidationError):
        pipeline.test_valid()