Exemplo n.º 1
0
def test_compute_focus_error():
    image = np.random.normal(loc=0.0, scale=1.0, size=10000)
    image = np.reshape(image, (100, 100))
    # error: sequence 'neighborhood_size' too short
    with pytest.raises(ValueError):
        _ = stack.compute_focus(image, neighborhood_size=[11])
    # error: sequence 'neighborhood_size' too long
    with pytest.raises(ValueError):
        _ = stack.compute_focus(image, neighborhood_size=(5, 11, 31))
Exemplo n.º 2
0
def test_in_focus_selection(dtype):
    x = x_3d_out_focus.astype(dtype)
    expected_y = x_3d.astype(dtype)
    focus = stack.compute_focus(x_3d_out_focus, neighborhood_size=31)
    y = stack.in_focus_selection(x, focus, proportion=3)
    assert_array_equal(y, expected_y)
    assert y.dtype == dtype
Exemplo n.º 3
0
def test_compute_focus_format(dtype, neighborhood_size):
    # 2D input
    image = np.random.normal(loc=0.0, scale=1.0, size=10000)
    image = np.reshape(image, (100, 100)).astype(dtype)
    focus = stack.compute_focus(image, neighborhood_size=neighborhood_size)
    assert focus.dtype == np.float64
    assert focus.shape == image.shape
    assert focus.min() >= 1

    # 3D input
    image = np.random.normal(loc=0.0, scale=1.0, size=100000)
    image = np.reshape(image, (10, 100, 100)).astype(dtype)
    focus = stack.compute_focus(image, neighborhood_size=neighborhood_size)
    assert focus.dtype == np.float64
    assert focus.shape == image.shape
    assert focus.min() >= 1
Exemplo n.º 4
0
def test_get_in_focus_indices():
    focus = stack.compute_focus(x_3d_out_focus, neighborhood_size=31)

    # number of slices to keep
    indices_to_keep = stack.get_in_focus_indices(focus, proportion=3)
    assert isinstance(indices_to_keep, list)
    assert len(indices_to_keep) == 3
    assert indices_to_keep[0] == 1
    assert indices_to_keep[1] == 3
    assert indices_to_keep[2] == 4

    # proportion of slices to keep
    indices_to_keep = stack.get_in_focus_indices(focus, proportion=0.5)
    assert isinstance(indices_to_keep, list)
    assert len(indices_to_keep) == 3
    assert indices_to_keep[0] == 1
    assert indices_to_keep[1] == 3
    assert indices_to_keep[2] == 4

    # 0 slice
    indices_to_keep = stack.get_in_focus_indices(focus, proportion=0)
    assert isinstance(indices_to_keep, list)
    assert len(indices_to_keep) == 0

    # error: float > 1
    with pytest.raises(ValueError):
        _ = stack.get_in_focus_indices(focus, proportion=3.)

    # error: 'proportion' < 0
    with pytest.raises(ValueError):
        _ = stack.get_in_focus_indices(focus, proportion=-3)
Exemplo n.º 5
0
def test_compute_focus():
    focus = stack.compute_focus(x_out_focus, neighborhood_size=31)
    average_focus = focus.mean(axis=(1, 2))
    assert round(average_focus[0], 5) == 1.
    assert round(average_focus[1], 5) > 1.
    assert round(average_focus[2], 5) == 1.
    assert round(average_focus[3], 5) > 1.
    assert round(average_focus[4], 5) > 1.
    assert round(average_focus[5], 5) == 1.