How to use the cellprofiler.image function in CellProfiler

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_measureimageoverlap.py View on Github external
module.test_img.value = TEST_IMAGE_NAME
    module.wants_emd.value = True

    pipeline = cellprofiler.pipeline.Pipeline()

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

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

    image_set_list = cellprofiler.image.ImageSetList()
    image_set = image_set_list.get_image_set(0)

    for name, d in ((GROUND_TRUTH_IMAGE_NAME, ground_truth), (TEST_IMAGE_NAME, test)):
        image = cellprofiler.image.Image(
            d["image"],
            mask=d.get("mask"),
            crop_mask=d.get("crop_mask"),
            dimensions=dimensions,
        )
        image_set.add(name, image)

    workspace = cellprofiler.workspace.Workspace(
        pipeline,
        module,
        image_set,
        cellprofiler.object.ObjectSet(),
        cellprofiler.measurement.Measurements(),
        image_set_list,
    )
    return workspace, module
github CellProfiler / CellProfiler / tests / modules / test_identifydeadworms.py View on Github external
def make_workspace(pixel_data, mask=None):
    image = cellprofiler.image.Image(pixel_data, mask)
    image_set_list = cellprofiler.image.ImageSetList()

    image_set = image_set_list.get_image_set(0)
    image_set.add(IMAGE_NAME, image)

    module = cellprofiler.modules.identifydeadworms.IdentifyDeadWorms()
    module.set_module_num(1)
    module.image_name.value = IMAGE_NAME
    module.object_name.value = OBJECTS_NAME

    pipeline = cellprofiler.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)
        assert not isinstance(event, cellprofiler.pipeline.RunExceptionEvent)
github CellProfiler / CellProfiler / tests / modules / test_identifydeadworms.py View on Github external
def make_workspace(pixel_data, mask=None):
    image = cellprofiler.image.Image(pixel_data, mask)
    image_set_list = cellprofiler.image.ImageSetList()

    image_set = image_set_list.get_image_set(0)
    image_set.add(IMAGE_NAME, image)

    module = cellprofiler.modules.identifydeadworms.IdentifyDeadWorms()
    module.set_module_num(1)
    module.image_name.value = IMAGE_NAME
    module.object_name.value = OBJECTS_NAME

    pipeline = cellprofiler.pipeline.Pipeline()

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

    pipeline.add_listener(callback)
github CellProfiler / CellProfiler / tests / modules / test_correctilluminationcalculate.py View on Github external
module.illumination_image_name.value = "OutputImage"
    module.intensity_choice.value = (
        cellprofiler.modules.correctilluminationcalculate.IC_REGULAR
    )
    module.each_or_all.value == cellprofiler.modules.correctilluminationcalculate.EA_EACH
    module.smoothing_method.value = (
        cellprofiler.modules.correctilluminationcalculate.SM_MEDIAN_FILTER
    )
    module.automatic_object_width.value = (
        cellprofiler.modules.correctilluminationcalculate.FI_MANUALLY
    )
    module.size_of_smoothing_filter.value = 10
    module.rescale_option.value = cellprofiler.setting.NO
    module.dilate_objects.value = False
    measurements = cellprofiler.measurement.Measurements()
    image_set_list = cellprofiler.image.ImageSetList()
    workspace = cellprofiler.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.object.ObjectSet()
    workspace = cellprofiler.workspace.Workspace(
        pipeline, inj_module, image_set, object_set, measurements, image_set_list
    )
    inj_module.run(workspace)
    module.run(workspace)
    image = image_set.get_image("OutputImage")
    assert numpy.all(image.pixel_data == expected_image)
github CellProfiler / CellProfiler / tests / modules / test_unmixcolors.py View on Github external
module = cellprofiler.modules.unmixcolors.UnmixColors()
    module.input_image_name.value = INPUT_IMAGE
    module.outputs[0].image_name.value = output_image_name(0)
    module.outputs[0].stain_choice.value = choices[0]
    for i, choice in enumerate(choices[1:]):
        module.add_image()
        module.outputs[i + 1].image_name.value = output_image_name(i + 1)
        module.outputs[i + 1].stain_choice.value = choice

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

    image_set_list = cellprofiler.image.ImageSetList()
    image_set = image_set_list.get_image_set(0)
    image = cellprofiler.image.Image(pixels)
    image_set.add(INPUT_IMAGE, image)

    workspace = cellprofiler.workspace.Workspace(
        pipeline,
        module,
        image_set,
        cellprofiler.object.ObjectSet(),
        cellprofiler.measurement.Measurements(),
        image_set_list,
    )
    return workspace, module
github CellProfiler / CellProfiler / tests / modules / test_histogramequalization.py View on Github external
module.y_name.value = "HistogramEqualization"

    module.nbins.value = 256

    module.local.value = False

    module.mask.value = "Mask"

    module.run(workspace)

    actual = image_set.get_image("HistogramEqualization")

    expected_data = skimage.exposure.equalize_hist(data, mask=mask_data)

    expected = cellprofiler.image.Image(
        image=expected_data,
        parent_image=image,
        dimensions=image.dimensions
    )

    numpy.testing.assert_array_equal(expected.pixel_data, actual.pixel_data)
github CellProfiler / CellProfiler / tests / modules / test_correctilluminationcalculate.py View on Github external
def make_workspaces(images_and_masks):
    """Make a workspace for each image set provided

    images_and_masks - a collection of two-tuples: image+mask

    returns a list of workspaces + the module
    """
    image_set_list = cellprofiler.image.ImageSetList()
    workspaces = []
    module = (
        cellprofiler.modules.correctilluminationcalculate.CorrectIlluminationCalculate()
    )
    module.set_module_num(1)
    module.image_name.value = INPUT_IMAGE_NAME
    module.illumination_image_name.value = OUTPUT_IMAGE_NAME
    module.average_image_name.value = AVERAGE_IMAGE_NAME
    module.dilated_image_name.value = DILATED_IMAGE_NAME
    pipeline = cellprofiler.pipeline.Pipeline()
    pipeline.add_listener(error_callback)
    measurements = cellprofiler.measurement.Measurements()

    for i, (image, mask) in enumerate(images_and_masks):
        image_set = image_set_list.get_image_set(i)
        if mask is None:
github CellProfiler / CellProfiler / tests / modules / test_removeholes.py View on Github external
def test_run_label_image(module):
    data = numpy.zeros((10, 10), dtype=numpy.uint8)
    data[3:8, 3:8] = 1
    data[5, 5] = 0

    image = cellprofiler.image.Image(image=data, convert=False)

    image_set_list = cellprofiler.image.ImageSetList()

    image_set = image_set_list.get_image_set(0)
    image_set.add("example", image)

    workspace = cellprofiler.workspace.Workspace(
        pipeline=None,
        module=module,
        image_set=image_set,
        object_set=None,
        measurements=None,
        image_set_list=image_set_list,
    )

    module.x_name.value = "example"
    module.y_name.value = "output"
    module.run(workspace)
github CellProfiler / CellProfiler / cellprofiler / modules / histogramequalization.py View on Github external
if self.local.value:

            kernel_size = self.kernel_size.value

            if x.volumetric:
                y_data = numpy.zeros_like(x_data, dtype=numpy.float)

                for index, plane in enumerate(x_data):
                    y_data[index] = skimage.exposure.equalize_adapthist(plane, kernel_size=kernel_size, nbins=nbins)
            else:
                y_data = skimage.exposure.equalize_adapthist(x_data, kernel_size=kernel_size, nbins=nbins)
        else:
            y_data = skimage.exposure.equalize_hist(x_data, nbins=nbins, mask=mask_data)

        y = cellprofiler.image.Image(
            dimensions=dimensions,
            image=y_data,
            parent_image=x
        )

        images.add(y_name, y)

        if self.show_window:
            workspace.display_data.x_data = x_data

            workspace.display_data.y_data = y_data

            workspace.display_data.dimensions = dimensions
github CellProfiler / CellProfiler / cellprofiler / modules / smooth.py View on Github external
output_pixels = fit_polynomial(pixel_data, image.mask, self.clip.value)
        elif self.smoothing_method.value == CIRCULAR_AVERAGE_FILTER:
            output_pixels = circular_average_filter(
                pixel_data, object_size / 2 + 1, image.mask
            )
        elif self.smoothing_method.value == SM_TO_AVERAGE:
            if image.has_mask:
                mean = np.mean(pixel_data[image.mask])
            else:
                mean = np.mean(pixel_data)
            output_pixels = np.ones(pixel_data.shape, pixel_data.dtype) * mean
        else:
            raise ValueError(
                "Unsupported smoothing method: %s" % self.smoothing_method.value
            )
        output_image = cellprofiler.image.Image(output_pixels, parent_image=image)
        workspace.image_set.add(self.filtered_image_name.value, output_image)
        workspace.display_data.pixel_data = pixel_data
        workspace.display_data.output_pixels = output_pixels