Esempio n. 1
0
def test_circle(nbpoints, expected):
    """
    test with parametrize to run several tests
    """

    theta, path = spl.circle([0, 0], 1, npoints=nbpoints)
    assert path == approx(expected)
def circle(img):
    def xs_func():
        nsamples = 500
        return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi)

    theta, path = spl.circle([.5, .5], .3, npoints=40)
    spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005)
Esempio n. 3
0
def test_circle_10():
    """
    test with 10 points
    """
    theta, path = spl.circle([0, 0], 1, npoints=10)

    assert theta == approx(np.linspace(0, 2 * np.pi, 10))
Esempio n. 4
0
def test_circle_1():
    theta, path = spl.circle(
        [0, 0], 1, npoints=2
    )  # create a splinned circle with center [0,0] radius 1 and 2 points
    print(theta)
    assert theta == approx(
        [0, 2 * np.pi])  # the resulting vector of theta angles for each point
    #assert path == approx(np.array([[1, 0], [1, 0]]))
    print(path)
    assert path == approx(np.array([[1, 0], [1, 0]
                                    ]))  # and the resulting path must be this
Esempio n. 5
0
def test_case(tmpdir, load_json):

    datadir, js = load_json
    np.random.seed(js["seed"])

    img_size, channels = 1000, 4
    img = np.ones((img_size, img_size, channels), dtype=np.float32)

    theta, path = spl.circle(js["center"], js["radius"])

    def xs_func():
        nsamples = 500
        return (np.random.random() + 2 * np.pi * np.linspace(0, 1, nsamples))%(2*np.pi)

    spl.update_img(img, path, xs_func, nrep=js["nrep"], x=theta)

    spl.save_img(img, tmpdir.dirname, 'output.png')

    assert filecmp.cmp(tmpdir.dirname + '/output.png', datadir + "/" + js["output"]) 
Esempio n. 6
0
def test_circle_case():

    np.random.seed(42)

    img_size, channels = 1000, 4
    img = np.ones((img_size, img_size, channels), dtype=np.float32)

    theta, path = spl.circle([0.5, 0.5], 0.3)

    def xs_func():
        nsamples = 500
        return (np.random.random() +
                2 * np.pi * np.linspace(0, 1, nsamples)) % (2 * np.pi)

    spl.update_img(img, path, xs_func, nrep=4000, x=theta)

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.imshow(img)
    return fig
Esempio n. 7
0
def test_spline_circle(center, radius, nbpoints):
    theta, path = spl.circle(center, radius, npoints=nbpoints)
    y2s = spl.spline.spline(theta, path)
    y_new = np.zeros_like(path)
    spl.spline.splint(theta, path, y2s, theta, y_new)
    assert path == pytest.approx(y_new)
Esempio n. 8
0
import numpy as np
import splinart as spl
import json

SEED = 42
CENTER = [.5, .5]
RADIUS = .3
NREP = 4000

np.random.seed(SEED)
img_size, channels = 1000, 4
img = np.ones((img_size, img_size, channels), dtype=np.float32)

theta, path = spl.circle(CENTER, RADIUS)


def xs_func():
    nsamples = 500
    return (np.random.random() +
            2 * np.pi * np.linspace(0, 1, nsamples)) % (2 * np.pi)


spl.update_img(img, path, xs_func, nrep=NREP, x=theta)

spl.save_img(img, '.', 'circle.png')

js = json.dumps(
    {
        "circle": {
            "seed": SEED,
            "center": CENTER,
Esempio n. 9
0
from __future__ import print_function, division, absolute_import
import numpy as np
from six.moves import range
import splinart as spl

img_size, channels = 1000, 4
img = np.ones((img_size, img_size, channels), dtype=np.float32)

nb_circles = 10
theta_circles = []
path_circles = []
color_circles = []
for i in range(nb_circles):
    radius = .1 + np.random.random() * .1
    center = .2 + np.random.random(2) * .6
    theta, path = spl.circle(center, radius, npoints=75)
    theta_circles.append(theta)
    path_circles.append(path)
    color = np.random.random(4) * .3
    color[-1] = 1.
    color_circles.append(color)


def xs_func():
    nsamples = 500
    return (np.random.random() +
            2 * np.pi * np.linspace(0, 1, nsamples)) % (2 * np.pi)


for i in range(nb_circles):
    img1 = np.ones_like(img)
Esempio n. 10
0
from __future__ import print_function, division, absolute_import
import numpy as np
import splinart as spl

img_size, channels = 1000, 4
img = np.ones((img_size, img_size, channels), dtype=np.float32)

theta, path = spl.circle([.5, .5], .3, npoints=40)


def xs_func():
    nsamples = 500
    return (np.random.random() +
            2 * np.pi * np.linspace(0, 1, nsamples)) % (2 * np.pi)


spl.update_img(img, path, xs_func, nrep=4000, x=theta, scale_value=.00005)

spl.save_img(img, './output', 'circle.png')
Esempio n. 11
0
def test_circle_2():
    theta, path = spl.circle([0, 0], 1, npoints=5)

    assert theta == approx(np.linspace(0, 2 * np.pi, 5))
    assert path == approx(np.array([[1, 0], [0, 1], [-1, 0], [0, -1], [1, 0]]))
Esempio n. 12
0
def test_circle_1():
    theta, path = spl.circle([0, 0], 1, npoints=2)

    assert theta == approx([0, 2 * np.pi])
    assert path == approx(np.array([[1, 0], [1, 0]]))
Esempio n. 13
0
def test_circle(nbpoints, expected):
    theta, path = spl.circle([0, 0], 1, npoints=nbpoints)
    assert path == approx(expected)