How to use CellProfiler - 10 common examples

To help you get started, we’ve selected a few CellProfiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CellProfiler / CellProfiler / tests / modules / test_loadsingleimage.py View on Github external
pipeline = cellprofiler.pipeline.Pipeline()
        lsi = cellprofiler.modules.loadsingleimage.LoadSingleImage()
        lsi.set_module_num(1)
        lsi.directory.dir_choice = cellprofiler.setting.ABSOLUTE_FOLDER_NAME
        lsi.directory.custom_path = path
        lsi.file_settings[0].image_name.value = get_image_name(0)
        lsi.file_settings[0].file_name.value = filename
        pipeline.add_module(lsi)
        li = cellprofiler.modules.loadimages.LoadImages()
        li.set_module_num(2)
        pipeline.add_module(li)
        li.match_method.value = cellprofiler.modules.loadimages.MS_EXACT_MATCH
        li.location.dir_choice = cellprofiler.setting.ABSOLUTE_FOLDER_NAME
        li.location.custom_path = path
        li.images[0].common_text.value = "Channel2-"
        m = cellprofiler.measurement.Measurements()
        workspace = cellprofiler.workspace.Workspace(
            pipeline,
            lsi,
            m,
            cellprofiler.object.ObjectSet(),
            m,
            cellprofiler.image.ImageSetList(),
        )
        assert pipeline.prepare_run(workspace)
        assert m.image_set_count > 1
        pipeline.prepare_group(workspace, {}, m.get_image_numbers())
        #
        # Skip to the second image set
        #
        m.next_image_set(2)
        lsi.run(workspace)
github CellProfiler / CellProfiler / tests / modules / test_labelimages.py View on Github external
module = cellprofiler.modules.labelimages.LabelImages()
    pipeline = cellprofiler.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.RunExceptionEvent)

    pipeline.add_listener(callback)
    module.set_module_num(1)
    pipeline.add_module(module)

    workspace = cellprofiler.workspace.Workspace(
        pipeline,
        module,
        image_set_list.get_image_set(0),
        cellprofiler.object.ObjectSet(),
        cellprofiler.measurement.Measurements(),
        image_set_list,
    )
    return workspace, module
github CellProfiler / CellProfiler / tests / modules / test_loadimages.py View on Github external
return
    file_name = "DrosophilaEmbryo_GFPHistone.avi"
    avi_path = tests.modules.testimages_directory()
    tests.modules.maybe_download_tesst_image(file_name)
    module = cellprofiler.modules.loadimages.LoadImages()
    module.file_types.value = cellprofiler.modules.loadimages.FF_AVI_MOVIES
    module.images[0].common_text.value = file_name
    module.images[0].channels[0].image_name.value = "MyImage"
    module.location.dir_choice = cellprofiler.setting.ABSOLUTE_FOLDER_NAME
    module.location.custom_path = avi_path
    module.set_module_num(1)
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(module)
    pipeline.add_listener(error_callback)
    image_set_list = cellprofiler.image.ImageSetList()
    m = cellprofiler.measurement.Measurements()
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, None, None, m, image_set_list
    )
    module.prepare_run(workspace)
    assert m.image_set_count == 65
    module.prepare_group(workspace, (), [1, 2, 3])
    image_set = image_set_list.get_image_set(0)
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, image_set, cellprofiler.object.ObjectSet(), m, image_set_list
    )
    module.run(workspace)
    assert "MyImage" in image_set.names
    image = image_set.get_image("MyImage")
    img1 = image.pixel_data
    assert tuple(img1.shape) == (264, 542, 3)
    t = m.get_current_image_measurement(
github CellProfiler / CellProfiler / tests / modules / test_flipandrotate.py View on Github external
image_set = image_set_list.get_image_set(0)
    image_set.add(IMAGE_NAME, img)
    module = cellprofiler.modules.flipandrotate.FlipAndRotate()
    module.image_name.value = IMAGE_NAME
    module.output_name.value = OUTPUT_IMAGE
    module.set_module_num(1)
    if fn is not None:
        fn(module)
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(module)

    def error_callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.RunExceptionEvent)

    pipeline.add_listener(error_callback)
    measurements = cellprofiler.measurement.Measurements()
    workspace = cellprofiler.workspace.Workspace(
        pipeline,
        module,
        image_set,
        cellprofiler.object.ObjectSet(),
        measurements,
        image_set_list,
    )
    module.run(workspace)
    feature = cellprofiler.modules.flipandrotate.M_ROTATION_F % OUTPUT_IMAGE
    assert feature in measurements.get_feature_names(cellprofiler.measurement.IMAGE)
    angle = measurements.get_current_image_measurement(feature)
    output_image = image_set.get_image(OUTPUT_IMAGE)
    return output_image, angle
github CellProfiler / CellProfiler / tests / modules / test_identifyobjectsingrid.py View on Github external
my_objects = cellprofiler.object.Objects()
        my_objects.segmented = labels
        object_set.add_objects(my_objects, GUIDING_OBJECTS_NAME)
    pipeline = cellprofiler.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.RunExceptionEvent)

    pipeline.add_listener(callback)
    pipeline.add_module(module)
    workspace = cellprofiler.workspace.Workspace(
        pipeline,
        module,
        image_set_list.get_image_set(0),
        object_set,
        cellprofiler.measurement.Measurements(),
        image_set_list,
    )
    workspace.set_grid(GRID_NAME, gridding)
    return workspace, module
github CellProfiler / CellProfiler / tests / modules / test_matchtemplate.py View on Github external
def measurements():
    return cellprofiler.measurement.Measurements()
github CellProfiler / CellProfiler / tests / modules / test_loadimages.py View on Github external
pipeline.load(io.StringIO(pipeline_text))

    def callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.RunExceptionEvent)

    pipeline.add_listener(callback)
    m = [
        m
        for m in pipeline.modules()
        if isinstance(m, cellprofiler.modules.loadimages.LoadImages)
    ][0]
    m1 = cellprofiler.measurement.Measurements()
    w1 = cellprofiler.workspace.Workspace(pipeline, m, m1, None, m1, None)
    pipeline.prepare_run(w1)

    m2 = cellprofiler.measurement.Measurements()
    w2 = cellprofiler.workspace.Workspace(pipeline, m, m2, None, m2, None)
    urls = [
        cellprofiler.modules.loadimages.pathname2url(os.path.join(directory, filename))
        for filename in os.listdir(directory)
        if fn_filter(filename)
    ]
    w2.file_list.add_files_to_filelist(urls)
    pipeline.add_urls(urls, False)
    pipeline.convert_legacy_input_modules()
    pipeline.prepare_run(w2)

    ff1 = m1.get_feature_names(cellprofiler.measurement.IMAGE)
    ffexpected = [
        f.replace("IMAGE_FOR_", "")
        for f in ff1
        if not f.startswith(cellprofiler.measurement.C_METADATA)
github CellProfiler / CellProfiler / tests / modules / test_loadimages.py View on Github external
cellprofiler.modules.loadimages.FF_AVI_MOVIES
        not in cellprofiler.modules.loadimages.FF
    ):
        sys.stderr.write("WARNING: AVI movies not supported\n")
        return
    file_name = "DrosophilaEmbryo_GFPHistone.avi"
    avi_path = tests.modules.testimages_directory()
    tests.modules.maybe_download_tesst_image(file_name)
    module = cellprofiler.modules.loadimages.LoadImages()
    module.file_types.value = cellprofiler.modules.loadimages.FF_AVI_MOVIES
    module.images[0].common_text.value = file_name
    module.images[0].channels[0].image_name.value = "MyImage"
    module.location.dir_choice = cellprofiler.setting.ABSOLUTE_FOLDER_NAME
    module.location.custom_path = avi_path
    module.set_module_num(1)
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_module(module)
    pipeline.add_listener(error_callback)
    image_set_list = cellprofiler.image.ImageSetList()
    m = cellprofiler.measurement.Measurements()
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, None, None, m, image_set_list
    )
    module.prepare_run(workspace)
    assert m.image_set_count == 65
    module.prepare_group(workspace, (), [1, 2, 3])
    image_set = image_set_list.get_image_set(0)
    workspace = cellprofiler.workspace.Workspace(
        pipeline, module, image_set, cellprofiler.object.ObjectSet(), m, image_set_list
    )
    module.run(workspace)
    assert "MyImage" in image_set.names
github CellProfiler / CellProfiler / tests / modules / test_measureobjectsizeshape.py View on Github external
def test_measurements_zernike():
    module = cellprofiler.modules.measureobjectsizeshape.MeasureObjectAreaShape()
    settings = ["SomeObjects", "OtherObjects", "Yes"]
    module.set_settings_from_values(settings, 1, module.module_class())
    pipeline = cellprofiler.pipeline.Pipeline()
    for object_name in settings[:-1]:
        measurements = module.get_measurements(pipeline, object_name, "AreaShape")
        for measurement in (
            cellprofiler.modules.measureobjectsizeshape.F_STANDARD
            + cellprofiler.modules.measureobjectsizeshape.F_STD_2D
        ):
            assert measurement in measurements
        assert "Zernike_3_1" in measurements
github CellProfiler / CellProfiler / tests / modules / test_namesandtypes.py View on Github external
def test_get_categories():
    p = cellprofiler.pipeline.Pipeline()
    p.clear()
    nts = [
        m
        for m in p.modules()
        if isinstance(m, cellprofiler.modules.namesandtypes.NamesAndTypes)
    ]
    assert len(nts) == 1
    m = nts[0]
    m.assignment_method.value = cellprofiler.modules.namesandtypes.ASSIGN_RULES
    m.assignments[0].image_name.value = IMAGE_NAME
    categories = m.get_categories(p, cellprofiler.measurement.IMAGE)
    assert not (cellprofiler.measurement.C_OBJECTS_FILE_NAME in categories)
    assert not (cellprofiler.measurement.C_OBJECTS_PATH_NAME in categories)
    assert not (cellprofiler.measurement.C_OBJECTS_URL in categories)
    assert cellprofiler.measurement.C_FILE_NAME in categories
    assert cellprofiler.measurement.C_PATH_NAME in categories