Exemplo n.º 1
0
    def __init__(self):
        """ Setup the game
        """
        self.width = 300
        self.height = 200
        self.depth = 200
        self.playground = cle.create([self.depth, self.height, self.width])
        self.gradient = cle.create([self.depth, self.height, self.width])
        cle.set_ramp_z(self.gradient)
        self.view = cle.create([self.depth, self.height, self.width])

        self.player1_y = self.height / 2
        self.player1_z = self.depth / 2
        self.player2_y = self.height / 2
        self.player2_z = self.depth / 2

        self.player1_x = 10
        self.player2_x = self.width - 10

        self.player1_score = 0
        self.player2_score = 0

        self.bar_radius = self.height / 4

        self.puck_x = self.width / 2
        self.puck_y = self.height / 2
        self.puck_z = self.depth / 2
        self.puck_delta_x = 10
        self.puck_delta_y = 0
        self.puck_delta_z = 0

        self.result_label = QLabel()
def test_nonzero_minimum_box():
    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([
        [0, 0, 0, 0, 0],
        [0, 1, 1, 1, 0],
        [0, 1, 1, 1, 0],
        [0, 2, 2, 2, 0],
        [0, 0, 0, 0, 0]
    ]))

    result = cle.create(test)
    flag = cle.create((1, 1, 1))

    # as nonzero filters don't touch zero values, we need to initialize the result in advance
    cle.set(result, 0);

    cle.nonzero_minimum_box(test, flag, result)

    print(result)

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.allclose(a, b, atol=0.00001))
Exemplo n.º 3
0
    def __init__(self):
        """ Setup the game
        """

        # playground config
        self.width = 640
        self.height = 480

        self.pixel_size = 10
        self.food_calories = 5
        self.maximum_food_available = 10

        self.frame_delay = 0.2  # seconds

        # player 1
        self.player1_delta_x = 0
        self.player1_delta_y = self.pixel_size
        self.player1_score = 0
        self.player1_positions = [[240, 240]]

        # player 2
        self.player2_delta_x = 0
        self.player2_delta_y = -self.pixel_size
        self.player2_score = 0
        self.player2_positions = [[480, 240]]

        self.food_positions = []

        # others
        self.iteration = 0

        self.playground = cle.create([self.height, self.width])
        self.temp = cle.create([self.height, self.width])

        self.result_label = QLabel()
def block_enum(source, blocksize):
    flagged_indices = cle.push(source)
    max_label = source.shape[1] - 1

    block_sums = cle.create([1, int((int(max_label) + 1) / blocksize) + 1])
    cle.sum_reduction_x(flagged_indices, block_sums, blocksize)

    # distribute new numbers
    new_indices = cle.create([1, int(max_label) + 1])
    cle.block_enumerate(flagged_indices, block_sums, new_indices, blocksize)

    return cle.pull(new_indices)
def test_z_position_projection():

    temp = cle.create(reference)
    cle.z_position_of_maximum_z_projection(test1, temp)

    result = cle.create(reference)
    cle.z_position_projection(test1, temp, result)

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

    print(a)

    assert (np.array_equal(a, b))
Exemplo n.º 6
0
def test_minimum_x_projection():
    test1 = cle.push(
        np.asarray([[[1, 0, 0, 0, 1], [0, 2, 0, 8, 1], [3, 0, 1, 0, 1],
                     [0, 4, 0, 7, 1], [1, 1, 1, 1, 1]],
                    [[0, 2, 0, 8, 1], [1, 0, 0, 0, 1], [3, 0, 1, 0, 1],
                     [0, 4, 0, 7, 1], [1, 1, 1, 1, 1]],
                    [[0, 2, 0, 8, 1], [3, 0, 1, 0, 1], [0, 4, 0, 7, 1],
                     [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]],
                    [[0, 2, 0, 8, 1], [1, 0, 0, 0, 1], [0, 4, 0, 7, 1],
                     [3, 0, 1, 0, 1], [1, 1, 1, 1, 1]],
                    [[1, 0, 0, 0, 1], [0, 4, 0, 7, 1], [3, 0, 1, 0, 1],
                     [0, 2, 0, 8, 1], [1, 1, 1, 1, 1]]]).T)

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

    result = cle.create(reference)
    cle.minimum_x_projection(test1, result)

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

    print(a)

    assert (np.allclose(a, b, 0.001))
def test_smaller_2d():
    test1 = cle.push(np.asarray([
        [0, 0, 0, 0, 0],
        [0, 1, 2, 3, 0],
        [0, 3, 3, 4, 0],
        [0, 4, 4, 5, 0],
        [0, 0, 0, 0, 0]
    ]))
    test2 = cle.push(np.asarray([
        [0, 0, 0, 0, 0],
        [0, 3, 3, 3, 0],
        [0, 3, 3, 3, 0],
        [0, 3, 3, 3, 0],
        [0, 0, 0, 0, 0]
    ]))

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

    result = cle.create(test1)
    cle.smaller(test1, test2, result)

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

    assert (np.array_equal(a, b))

    print("ok smaller")
Exemplo n.º 8
0
def test_maximum_y_projection():
    test1 = cle.push(
        np.asarray([[[1, 0, 0, 0, 9], [0, 2, 0, 8, 0], [3, 0, 1, 0, 10],
                     [0, 4, 0, 7, 0], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [1, 0, 0, 0, 9], [3, 0, 1, 0, 10],
                     [0, 4, 0, 7, 0], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [3, 0, 1, 0, 10], [0, 4, 0, 7, 0],
                     [1, 0, 0, 0, 9], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [1, 0, 0, 0, 9], [0, 4, 0, 7, 0],
                     [3, 0, 1, 0, 10], [5, 0, 6, 0, 10]],
                    [[1, 0, 0, 0, 9], [0, 4, 0, 7, 0], [3, 0, 1, 0, 10],
                     [0, 2, 0, 8, 0], [5, 0, 6, 0, 10]]]))

    reference = cle.push(
        np.asarray([[5, 4, 6, 8, 10], [5, 4, 6, 8, 10], [5, 4, 6, 8, 10],
                    [5, 4, 6, 8, 10], [5, 4, 6, 8, 10]]))

    result = cle.create(reference)
    cle.maximum_y_projection(test1, result)

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

    print(a)

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

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

    reference = cle.push(
        np.asarray([[0.4, 1.0, 1.8, 0.8, 5.], [1.2, 1.2, 1.6, 2.0, 0.],
                    [0., 0.2, 0.6, 0.2, 6.], [4.8, 3.0, 2.8, 4.4, 0.],
                    [3.6, 5.6, 6.0, 3.8, 10.]]).T)

    result = cle.create(reference)
    cle.mean_x_projection(test1, result)

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

    print(a)
    print(b)

    assert (np.allclose(a, b, 0.001))
Exemplo n.º 10
0
def test_maximum_images():
    test1 = cle.push(np.asarray([
        [0, 0, 0, 0, 0],
        [0, 1, 2, 3, 0],
        [0, 3, 3, 4, 0],
        [0, 4, 4, 5, 0],
        [0, 0, 0, 0, 0]
    ]))
    test2 = cle.push(np.asarray([
        [0, 0, 0, 0, 0],
        [0, 2, 1, 3, 0],
        [0, 2, 1, 3, 0],
        [0, 1, 1, 3, 0],
        [0, 0, 0, 0, 0]
    ]))

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

    result = cle.create(test1)
    cle.maximum_images(test1, test2, result)

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

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

    reference = cle.push(
        np.asarray([[3.94, 3.46, 4.21, 3.19, 4.27],
                    [3.46, 3.94, 4.21, 3.19, 4.27],
                    [3.46, 4.21, 3.19, 3.94, 4.27],
                    [3.46, 3.94, 3.19, 4.21, 4.27],
                    [3.94, 3.19, 4.21, 3.46, 4.27]]))

    result = cle.create(reference)
    cle.standard_deviation_z_projection(test1, result)

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

    print(a)

    assert (np.allclose(a, b, 0.01))
Exemplo n.º 12
0
def test_sum_z_projection():
    test1 = cle.push(
        np.asarray([[[1, 0, 0, 0, 9], [0, 2, 0, 8, 0], [3, 0, 1, 0, 10],
                     [0, 4, 0, 7, 0], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [1, 0, 0, 0, 9], [3, 0, 1, 0, 10],
                     [0, 4, 0, 7, 0], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [3, 0, 1, 0, 10], [0, 4, 0, 7, 0],
                     [1, 0, 0, 0, 9], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [1, 0, 0, 0, 9], [0, 4, 0, 7, 0],
                     [3, 0, 1, 0, 10], [5, 0, 6, 0, 10]],
                    [[1, 0, 0, 0, 9], [0, 4, 0, 7, 0], [3, 0, 1, 0, 10],
                     [0, 2, 0, 8, 0], [5, 0, 6, 0, 10]]]))

    reference = cle.push(
        np.asarray([[2., 6., 0., 24., 18.], [5., 6., 1., 15., 28.],
                    [9., 8., 3., 14., 30.], [4., 10., 1., 22., 19.],
                    [25., 0., 30., 0., 50.]]))

    result = cle.create(reference)
    cle.sum_z_projection(test1, result)

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

    print(b)
    print(a)

    assert (np.allclose(a, b, 0.01))
Exemplo n.º 13
0
def test_replace_intensity():
    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, 0, 0, 0, 0],
        [0, 1, 8, 3, 0],
        [0, 8, 3, 4, 0],
        [0, 4, 4, 5, 0],
        [0, 0, 0, 0, 0]
    ]))

    result = cle.create(test1)
    cle.replace_intensity(test1, result, 2, 8)

    print(result)

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.allclose(a, b, 0.001))
def workflow(input: Image, sigma=3, threshold: float = 30) -> Labels:
    if input:
        # push image to GPU memory and show it
        gpu_input = cle.push(input.data)

        # Spot detection
        # After some noise removal/smoothing, we perform a local maximum detection

        # gaussian blur
        gpu_blurred = cle.gaussian_blur(gpu_input,
                                        sigma_x=sigma,
                                        sigma_y=sigma,
                                        sigma_z=0)

        # detect maxima
        gpu_detected_maxima = cle.detect_maxima_box(gpu_blurred)

        # Spot curation
        # Now, we remove spots with values below a certain intensity and label the remaining spots

        # threshold
        gpu_thresholded = cle.greater_constant(gpu_blurred,
                                               constant=threshold * 10)

        # mask
        gpu_masked_spots = cle.mask(gpu_detected_maxima, gpu_thresholded)

        # label spots
        gpu_labelled_spots = cle.connected_components_labeling_box(
            gpu_masked_spots)

        number_of_spots = cle.maximum_of_all_pixels(gpu_labelled_spots)
        print("Number of detected spots: " + str(number_of_spots))

        # Expanding labelled spots
        # Next, we spatially extend the labelled spots by applying a maximum filter.

        # label map closing
        number_of_dilations = 10
        number_of_erosions = 4

        flip = cle.create_like(gpu_labelled_spots)
        flop = cle.create_like(gpu_labelled_spots)
        flag = cle.create([1, 1, 1])
        cle.copy(gpu_labelled_spots, flip)

        for i in range(0, number_of_dilations):
            cle.onlyzero_overwrite_maximum_box(flip, flag, flop)
            cle.onlyzero_overwrite_maximum_diamond(flop, flag, flip)

        flap = cle.greater_constant(flip, constant=1)

        for i in range(0, number_of_erosions):
            cle.erode_box(flap, flop)
            cle.erode_sphere(flop, flap)

        gpu_labels = cle.mask(flip, flap)

        output = cle.pull(gpu_labels)
        return output
def test_equal_constant():
    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, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 1, 0],
        [0, 1, 1, 0, 0],
        [0, 0, 0, 0, 0]
    ]))

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

    print(result)

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

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

    reference = cle.push(
        np.asarray([[0.4, 1.2, 0, 4.8, 3.6], [1, 1.2, 0.2, 3, 5.6],
                    [1.8, 1.6, 0.6, 2.8, 6], [0.8, 2, 0.2, 4.4, 3.8],
                    [5, 0, 6, 0, 10]]))

    result = cle.create(reference)
    cle.mean_z_projection(test1, result)

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

    print(a)

    assert (np.allclose(a, b, 0.001))
def test_sum_x_projection():
    test1 = cle.push(
        np.asarray([[[1, 0, 0, 0, 9], [0, 2, 0, 8, 0], [3, 0, 1, 0, 10],
                     [0, 4, 0, 7, 0], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [1, 0, 0, 0, 9], [3, 0, 1, 0, 10],
                     [0, 4, 0, 7, 0], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [3, 0, 1, 0, 10], [0, 4, 0, 7, 0],
                     [1, 0, 0, 0, 9], [5, 0, 6, 0, 10]],
                    [[0, 2, 0, 8, 0], [1, 0, 0, 0, 9], [0, 4, 0, 7, 0],
                     [3, 0, 1, 0, 10], [5, 0, 6, 0, 10]],
                    [[1, 0, 0, 0, 9], [0, 4, 0, 7, 0], [3, 0, 1, 0, 10],
                     [0, 2, 0, 8, 0], [5, 0, 6, 0, 10]]]).T)

    reference = cle.push(
        np.asarray([[2, 5, 9, 4, 25], [6, 6, 8, 10, 0], [0, 1, 3, 1, 30],
                    [24, 15, 14, 22, 0], [18, 28, 30, 19, 50]]).T)

    result = cle.create(reference)
    cle.sum_x_projection(test1, result)

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

    print(a)

    assert (np.allclose(a, b, 0.01))
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, 0, 0, 0, 0],
        [1, 2, -1, -2, 0],
        [1, 2, -1, -2, 0],
        [1, 3, -1, -3, 0],
        [0, 0, 0, 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_mean_sphere():
    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, 0, 1.8, 0, 0],
        [0, 1.8, 1.8, 1.8, 0],
        [0, 0, 1.8, 0, 0],
        [0, 0, 0, 0, 0]
    ]))

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

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

    print(a)
    print(b)

    assert (np.allclose(a, b, 0.0001))
def test_multiply_images():
    test1 = cle.push(np.asarray([
        [0, 0, 0, 0, 0],
        [0, 1, 2, 3, 0],
        [0, 4, 5, 6, 0],
        [0, 7, 8, 9, 0],
        [0, 0, 0, 0, 0]
    ]))
    test2 = cle.push(np.asarray([
        [0, 0, 0, 0, 0],
        [0, 2, 2, 2, 0],
        [0, 1, 1, 1, 0],
        [0, 3, 3, 3, 0],
        [0, 0, 0, 0, 0]
    ]))

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

    result = cle.create(test1)
    cle.multiply_images(test1, test2, result)

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

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

    reference = cle.push(
        np.asarray([[10, 10, 14, 11, 21], [10, 10, 14, 11, 21],
                    [10, 14, 11, 10, 21], [10, 10, 11, 14, 21],
                    [10, 11, 14, 10, 21]]))

    result = cle.create(reference)
    cle.sum_z_projection(test1, result)

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

    print(a)

    assert (np.allclose(a, b, 0.01))
def test_maximum_box():
    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, 1, 1, 1, 0],
        [0, 1, 1, 1, 0],
        [0, 1, 1, 1, 0],
        [0, 0, 0, 0, 0]
    ]))

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

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

    print(a)

    assert (np.array_equal(a, b))
Exemplo n.º 23
0
def test_power():
    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, 0, 0, 0, 0],
        [0, 1, 4, 9, 0],
        [0, 4, 9, 16, 0],
        [0, 16, 16, 25, 0],
        [0, 0, 0, 0, 0]
    ]))

    result = cle.create(test1)
    cle.power(test1, result, 2)

    print(result)

    a = cle.pull(result)
    b = cle.pull(reference)
    assert (np.allclose(a, b, 0.001))
Exemplo n.º 24
0
def test_paste():
    test1 = cle.push_zyx(np.asarray([
        [0, 0, 0, 1],
        [0, 0, 3, 1],
        [0, 0, 3, 1],
        [1, 1, 1, 1]
    ]))
    test2 = cle.push_zyx(np.asarray([
        [1, 2],
    ]))

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

    result = cle.create(test1)
    cle.copy(test1, result)
    cle.paste(test2, result, 1, 2, 0)

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

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

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

    result = cle.create(test1)
    cle.greater_or_equal(test1, test2, result)

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

    assert (np.array_equal(a, b))
def test_dilate_box_slice_by_slice():
    test = cle.push_zyx(
        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]],
                    [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 1, 0, 0, 0],
                     [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
                    [[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_zyx(
        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]],
                    [[0, 0, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 0],
                     [1, 1, 1, 0, 0], [0, 0, 0, 0, 0]],
                    [[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(test)
    cle.dilate_box_slice_by_slice(test, result)

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

    print(a)

    assert (np.array_equal(a, b))
Exemplo n.º 27
0
def test_erode_sphere_slice_by_slice():
    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]],
                    [[0, 0, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 0],
                     [1, 1, 1, 0, 0], [0, 0, 0, 0, 0]],
                    [[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]],
                    [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, 0, 0, 0],
                     [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
                    [[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_slice_by_slice(test, result)

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

    print(a)

    assert (np.array_equal(a, b))
Exemplo n.º 28
0
def test_transpose_yz():
    test1 = cle.push(np.asarray([
        [
            [0, 1],
            [2, 3]
        ], [
            [4, 5],
            [6, 7]
        ]
    ]))

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

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

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

    print(a)
    print(b)

    assert (np.array_equal(a, b))
Exemplo n.º 29
0
def test_flip():
    test = cle.push_zyx(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_zyx(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(result)

    a = cle.pull_zyx(result)
    b = cle.pull_zyx(reference)
    assert (np.array_equal(a, b))
Exemplo n.º 30
0
def test_gradient_z():
    test = cle.push_zyx(
        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]],
                    [[0, 0, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 0],
                     [1, 1, 1, 0, 0], [0, 0, 0, 0, 0]],
                    [[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_zyx(
        np.asarray([[[0, 0, 0, 0, 0], [1, 0, 0, -1, 0], [1, 0, 0, -1, 0],
                     [1, 0, 0, -1, 0], [0, 0, 0, 0, 0]],
                    [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
                    [[0, 0, 0, 0, 0], [-1, 0, 0, 1, 0], [-1, 0, 0, 1, 0],
                     [-1, 0, 0, 1, 0], [0, 0, 0, 0, 0]]]))

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

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

    print(a)

    assert (np.array_equal(a, b))