コード例 #1
0
def test_threshold_li_image_log():
    numpy.random.seed(73)

    data = numpy.random.rand(10, 10)

    mask = numpy.zeros_like(data, dtype=bool)

    mask[1:-1, 1:-1] = True

    workspace, module = make_workspace(data, mask=mask)

    image = workspace.image_set.get_image(INPUT_IMAGE_NAME)

    module.threshold_scope.value = cellprofiler.modules.threshold.TS_GLOBAL

    module.global_operation.value = cellprofiler.modules.threshold.TM_LI

    module.log_transform.value = True

    t_local, t_global, t_guide = module.get_threshold(image, workspace)

    transformed_data, d = centrosome.threshold.log_transform(data)

    t_expected = skimage.filters.threshold_li(transformed_data[mask])

    t_expected = centrosome.threshold.inverse_log_transform(t_expected, d)

    t_expected = module._correct_global_threshold(
        t_expected
    )

    numpy.testing.assert_almost_equal(t_global, t_expected, decimal=5)
コード例 #2
0
def test_threshold_robust_background_adaptive():
    numpy.random.seed(73)

    data = numpy.random.rand(10, 10)

    workspace, module = make_workspace(data, dimensions=2)

    image = workspace.image_set.get_image(INPUT_IMAGE_NAME)

    module.threshold_scope.value = cellprofiler.modules.threshold.TS_ADAPTIVE

    module.adaptive_window_size.value = 3

    module.local_operation.value = cellprofiler.modules.threshold.TM_ROBUST_BACKGROUND

    module.averaging_method.value = cellprofiler.modules.threshold.RB_MEAN

    module.variance_method.value = cellprofiler.modules.threshold.RB_SD

    t_local, t_uncorrected, t_guide = module.get_threshold(image, workspace)

    t_guide_expected = module.get_threshold_robust_background(data)

    t_guide_expected = module._correct_global_threshold(t_guide_expected)

    t_local_expected = module._get_adaptive_threshold(data,
                                                      module.get_threshold_robust_background)

    t_local_expected = module._correct_local_threshold(t_local_expected, t_guide_expected)

    numpy.testing.assert_almost_equal(t_guide, t_guide_expected)

    numpy.testing.assert_almost_equal(t_local, t_local_expected)
コード例 #3
0
def test_threshold_otsu3_image_log():
    numpy.random.seed(73)

    data = numpy.random.rand(10, 10)

    mask = numpy.zeros_like(data, dtype=bool)

    mask[1:-1, 1:-1] = True

    workspace, module = make_workspace(data, mask=mask)

    image = workspace.image_set.get_image(INPUT_IMAGE_NAME)

    module.threshold_scope.value = cellprofiler.modules.threshold.TS_GLOBAL

    module.global_operation.value = centrosome.threshold.TM_OTSU

    module.two_class_otsu.value = cellprofiler.modules.threshold.O_THREE_CLASS

    module.assign_middle_to_foreground.value = (
        cellprofiler.modules.threshold.O_FOREGROUND
    )

    module.log_transform.value = True

    t_local, t_global, t_guide = module.get_threshold(image, workspace)

    transformed_data, d = centrosome.threshold.log_transform(data)

    t_expected = skimage.filters.threshold_multiotsu(transformed_data[mask], nbins=128)[0]

    t_expected = centrosome.threshold.inverse_log_transform(t_expected, d)

    t_expected = module._correct_global_threshold(
        t_expected
    )

    numpy.testing.assert_almost_equal(t_global, t_expected, decimal=5)