예제 #1
0
def test_push_tuple():
    reference = ([1, 2], [-3, 4])

    image = cle.push(reference)

    result = cle.pull(image)

    assert np.allclose(result, reference)
예제 #2
0
def test_push_np():
    reference = np.asarray([[1, 2], [-3, 4]])

    image = cle.push(reference)

    result = cle.pull(image)

    assert np.allclose(result, reference)
예제 #3
0
def test_push_list():
    reference = [[1, 2], [-3, 4]]

    image = cle.push(reference)

    result = cle.pull(image)

    assert np.allclose(result, reference)
def test_labelled_spots_to_pointlist():

    gpu_input = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0],
                    [0, 0, 1, 0, 0], [0, 0, 0, 0, 1]]))

    gpu_reference = cle.push(np.asarray([[1, 3, 2, 4], [1, 1, 3, 4]]))

    gpu_output = cle.spots_to_pointlist(gpu_input)

    a = cle.pull(gpu_output)
    b = cle.pull(gpu_reference)

    print(a)
    print(b)

    assert (np.array_equal(a, b))
def test_connected_components_labeling_diamond():

    gpu_input = cle.push(
        np.asarray([[[0, 1, 0, 1], [0, 1, 0, 0], [1, 0, 0, 1]]]))

    gpu_reference = cle.push(
        np.asarray([[[0, 2, 0, 3], [0, 2, 0, 0], [1, 0, 0, 4]]]))

    gpu_output = cle.connected_components_labeling_diamond(gpu_input)

    a = cle.pull(gpu_output)
    b = cle.pull(gpu_reference)

    print(b)
    print(a)

    assert (np.array_equal(a, b))
예제 #6
0
def test_erode_sphere():
    test = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0],
                    [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))

    result = cle.create(test)
    cle.erode_sphere(test, result)

    print(result)

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.array_equal(a, b))
예제 #7
0
def test_dilate_labels_3d():
    gpu_input = cle.push(
        np.asarray([[
            [0, 0, 0, 0, 0, 2],
            [0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0],
            [0, 0, 0, 4, 0, 0],
            [0, 0, 0, 0, 0, 0],
            [5, 0, 0, 0, 0, 3],
        ],
                    [
                        [1, 0, 0, 0, 0, 2],
                        [0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0],
                        [5, 0, 0, 0, 0, 0],
                    ]]))

    gpu_reference = cle.push(
        np.asarray([[
            [1, 1, 0, 0, 2, 2],
            [1, 1, 0, 0, 2, 2],
            [0, 0, 4, 4, 4, 0],
            [0, 0, 4, 4, 4, 0],
            [5, 5, 4, 4, 4, 3],
            [5, 5, 0, 0, 3, 3],
        ],
                    [
                        [1, 1, 0, 0, 2, 2],
                        [1, 1, 0, 0, 2, 2],
                        [0, 0, 4, 4, 4, 0],
                        [0, 0, 4, 4, 4, 0],
                        [5, 5, 4, 4, 4, 3],
                        [5, 5, 0, 0, 3, 3],
                    ]]))

    gpu_output = cle.extend_labels_with_maximum_radius(gpu_input, radius=1)

    a = cle.pull(gpu_output)
    b = cle.pull(gpu_reference)

    print(a)
    print(b)

    assert (np.array_equal(a, b))
예제 #8
0
def test_smaller_constant():
    test1 = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 2, 3, 0], [0, 2, 3, 4, 0],
                    [0, 4, 5, 5, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 0, 1],
                    [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]))

    result = cle.create(test1)
    cle.smaller_constant(test1, result, 4)

    print(result)

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.array_equal(a, b))
def test_label_maximum_intensity_map_2d():

    intensity = cle.push(np.asarray([[1, 1, 2], [4, 0, 0], [5, 3, 0]]))

    labels = cle.push(np.asarray([[1, 1, 2], [1, 0, 0], [3, 3, 0]]))

    reference = cle.push(np.asarray([[4, 4, 2], [4, 0, 0], [5, 5, 0]]))

    result = cle.label_maximum_intensity_map(intensity, labels)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)

    assert (np.array_equal(a, b))
def test_set_ramp_z():
    result = cle.push(
        np.asarray([[[0, 0, 0], [3, 4, 3], [3, 4, 3]],
                    [[3, 4, 3], [3, 4, 3], [3, 4, 3]]]))

    reference = cle.push(
        np.asarray([[[0, 1, 2], [0, 1, 2], [0, 1, 2]],
                    [[0, 1, 2], [0, 1, 2], [0, 1, 2]]]))

    cle.set_ramp_z(result)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)

    assert (np.allclose(a, b, 0.001))
예제 #11
0
def test_add_images_weighted_named_params():
    output = cle.add_images_weighted(input1,
                                     input2,
                                     None,
                                     factor1=1,
                                     factor2=2)
    result = cle.pull(output)
    assert np.array_equal(result, reference)
def test_label_label_maximum_extension_map_2d():

    labels = cle.push(np.asarray([[1, 1, 2], [1, 0, 0], [3, 3, 0]]))

    reference = cle.push(
        np.asarray([[0.74535596, 0.74535596, 0], [0.74535596, 0, 0],
                    [0.5, 0.5, 0]]))

    result = cle.label_maximum_extension_map(labels)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)

    assert (np.allclose(a, b, 0.001))
def test_read_intensities_from_map():

    intensities = cle.push(np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))

    labels = cle.push(np.asarray([[8, 0, 7], [6, 5, 4], [3, 2, 1]]))

    reference = cle.push(np.asarray([[2, 9, 8, 7, 6, 5, 4, 3, 1]]))

    result = cle.read_intensities_from_map(labels, intensities)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)

    assert (np.array_equal(a, b))
예제 #14
0
def test_gradient_x():
    test = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 2, 0, 0], [0, 1, 2, 0, 0],
                    [0, 1, 3, 0, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 1, 2, 0, 0], [0, 1, 2, 0, 0], [0, 0, 1, 0, 0],
                    [0, -1, -2, 0, 0], [0, -1, -3, 0, 0]]))

    result = cle.create(test)
    cle.gradient_x(test, result)

    a = cle.pull(result)
    b = cle.pull(reference)
    print(a)

    assert (np.array_equal(a, b))
def test_resample_upsample_3d():
    test1 = cle.push(np.asarray([[[0, 2], [1, 4]], [[5, 5], [5, 5]]]))

    reference = cle.push(
        np.asarray([[[0, 0, 2, 2], [0, 0, 2, 2], [1, 1, 4, 4], [1, 1, 4, 4]],
                    [[0, 0, 2, 2], [0, 0, 2, 2], [1, 1, 4, 4], [1, 1, 4, 4]],
                    [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]],
                    [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]]))

    result = cle.resample(test1, factor_x=2, factor_y=2, factor_z=2)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)
    assert (np.array_equal(a, b))
예제 #16
0
def test_label_mean_intensity_map_2d():

    intensity = cle.push(np.asarray([[1, 1, 2], [4, 0, 0], [5, 3, 0]]))

    labels = cle.push(np.asarray([[1, 1, 2], [1, 0, 0], [3, 3, 0]]))

    reference = cle.push(np.asarray([[2, 2, 2], [2, 0, 0], [4, 4, 0]]))

    result = cle.label_mean_intensity_map(intensity, labels)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)

    assert (np.allclose(a, b, 0.001))
def test_pointlist_to_labelled_spots_2d():
    positions_and_values = cle.push(
        np.asarray([[0, 0, 2, 3, 5], [0, 1, 3, 2, 6]]))

    reference = cle.push(
        np.asarray([[1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0],
                    [0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 5]]))

    result = cle.pointlist_to_labelled_spots(positions_and_values)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)

    assert (np.array_equal(a, b))
예제 #18
0
def test_minimum_box():
    test1 = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0],
                    [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))

    result = cle.create(test1)
    cle.minimum_box(test1, result, 1, 1, 0)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)

    assert (np.array_equal(a, b))
예제 #19
0
def test_exponential():
    test = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 1, 2, 0], [0, 2, 2, 3, 0],
                    [0, 3, 3, 4, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[1, 1, 1, 1, 1], [1, 2.7182817, 2.7182817, 7.389056, 1],
                    [1, 7.389056, 7.389056, 20.085537, 1],
                    [1, 20.085537, 20.085537, 54.59815, 1], [1, 1, 1, 1, 1]]))

    result = cle.create(test)
    cle.exponential(test, result)

    print(result)

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.allclose(a, b, atol=0.00001))
예제 #20
0
def test_resample_3d_interpolation_x():
    test1 = cle.push(np.asarray([[[0, 2]]]))
    reference = cle.push(np.asarray([[
        [0, 0.5, 1.5, 1.5],
    ]]))

    result = cle.resample(test1,
                          factor_x=2,
                          factor_y=1,
                          factor_z=1,
                          linear_interpolation=True)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)
    assert (np.array_equal(a, b))
예제 #21
0
def test_flip():
    test = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 2, 0, 0], [0, 1, 2, 0, 0],
                    [0, 1, 3, 0, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, 2, 1, 0], [0, 0, 2, 1, 0],
                    [0, 0, 3, 1, 0], [0, 0, 0, 0, 0]]))

    result = cle.create(test)
    cle.flip(test, result, True, False, False)

    print(reference.get())
    print(result.get())

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.array_equal(a, b))
예제 #22
0
def test_affine_shear_x_in_z_plane():
    source = np.zeros((5, 5, 5))
    source[1, 1, 1] = 1

    reference = np.zeros((5, 5, 5))
    reference[1, 1, 2] = 1

    transform = cle.AffineTransform3D()
    transform.shear_in_z_plane(angle_x_in_degrees=45)
    result = cle.affine_transform(source, transform=transform)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)

    assert (np.array_equal(a, b))
def test_resample_downsample_3d():
    test1 = cle.push(
        np.asarray([[[-3, 0, 1, 2], [0, 5, 2, 7], [0, 1, 3, 4], [1, 6, 4, 8]],
                    [[-3, 0, 1, 2], [0, 5, 2, 7], [0, 1, 3, 4], [1, 6, 4, 8]],
                    [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]],
                    [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]]))

    reference = cle.push(
        np.asarray([[[0, 2], [1, 4]], [[0, 2], [1, 4]], [[5, 5], [5, 5]],
                    [[5, 5], [5, 5]]]))

    result = cle.downsample_slice_by_slice_half_median(test1)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    assert (np.array_equal(a, b))
def onlyzero_overwrite_maximum_diamond():
    test1 = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 2, 3, 0], [0, 2, 3, 4, 0],
                    [0, 4, 4, 5, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 1, 2, 3, 0], [1, 1, 2, 3, 3], [2, 2, 3, 4, 4],
                    [4, 4, 4, 5, 5], [0, 4, 4, 5, 0]]))

    result = cle.create(test1)
    flag = cle.create((1, 1, 1))
    cle.onlyzero_overwrite_maximum_diamond(test1, flag, result)

    print(result)

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.array_equal(a, b))
예제 #25
0
def test_laplace_diamond():
    test1 = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, -1, 0, 0], [0, -1, 4, -1, 0],
                    [0, 0, -1, 0, 0], [0, 0, 0, 0, 0]]))

    result = cle.create(test1)
    cle.laplace_diamond(test1, result)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)

    assert (np.array_equal(a, b))
def test_exclude_large_labels_2d():
    gpu_input = cle.push(
        np.asarray([[1, 1, 2, 0, 3, 3], [1, 1, 2, 0, 3, 3], [0, 0, 0, 0, 0, 0],
                    [4, 4, 5, 6, 6, 6], [4, 4, 5, 6, 6, 6]]))

    gpu_reference = cle.push(
        np.asarray([[0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0],
                    [0, 0, 2, 0, 0, 0], [0, 0, 2, 0, 0, 0]]))

    gpu_output = cle.exclude_large_labels(gpu_input, gpu_input, minimum_size=3)

    a = cle.pull(gpu_output)
    b = cle.pull(gpu_reference)

    print(a)
    print(b)

    assert (np.array_equal(a, b))
def test_mean_box():
    test1 = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 9, 0, 0],
                    [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0],
                    [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]))

    result = cle.create(test1)
    cle.mean_box(test1, result, 1, 1, 0)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)

    assert (np.allclose(a, b))
def test_standard_deviation_sphere():
    test1 = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]))

    reference = cle.push(
        np.asarray([[0, 0, 0, 0, 0], [0, 0, 0.4, 0, 0], [0, 0.4, 0.4, 0.4, 0],
                    [0, 0, 0.4, 0, 0], [0, 0, 0, 0, 0]]))

    result = cle.create(test1)
    cle.standard_deviation_sphere(test1, result, 1, 1, 0)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)

    assert (np.allclose(a, b, 0.01))
def test_maximum_y_projection2():
    test1 = cle.push(
        np.asarray([
            [1, 0, 0, 0, 9],
            [0, 2, 0, 8, 0],
            [3, 0, 1, 0, 10],
        ]))

    reference = cle.push(np.asarray([[3, 2, 1, 8, 10]]))

    result = cle.maximum_y_projection(test1)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)

    assert (np.array_equal(a, b))
def test_deskew_y():
    source = np.zeros((5, 5, 5))
    source[1, 1, 1] = 1

    reference = np.zeros((2, 7, 5))
    reference[0, 5, 1] = 1

    result = cle.deskew_y(source, angle_in_degrees=30)

    a = cle.pull(result)
    b = cle.pull(reference)

    print(a)
    print(b)

    print(a.shape)
    print(b.shape)

    assert (np.array_equal(a, b))