Пример #1
0
def test_addend():
    """Test adding a value to image"""
    def fn(module):
        module.addend.value = 0.5
        module.operation.value = cellprofiler.modules.imagemath.O_NONE

    numpy.random.seed(0)
    image = numpy.random.uniform(size=(10, 10)) * 0.5
    image = image.astype(numpy.float32)
    expected = image + 0.5
    output = run_imagemath([{"pixel_data": image}], fn)
    check_expected(output, expected)
Пример #2
0
def test_bilateral():
    """test the smooth module with bilateral filtering"""
    sigma = 16.0
    sigma_range = 0.2
    numpy.random.seed(0)
    image = numpy.random.uniform(size=(100, 100)).astype(numpy.float32)
    mask = numpy.ones(image.shape, bool)
    mask[40:60, 45:65] = False
    expected = skimage.restoration.denoise_bilateral(
        image=image.astype(float),
        multichannel=False,
        sigma_color=sigma_range,
        sigma_spatial=sigma,
    )
    workspace, module = make_workspace(image, mask)
    module.smoothing_method.value = cellprofiler.modules.smooth.SMOOTH_KEEPING_EDGES
    module.sigma_range.value = sigma_range
    module.wants_automatic_object_size.value = False
    module.object_size.value = 16.0 * 2.35
    module.run(workspace)
    result = workspace.image_set.get_image(OUTPUT_IMAGE_NAME)
    assert not (result is None)
    numpy.testing.assert_almost_equal(result.pixel_data, expected)