def line(img): def xs_func(): nsamples = 500 return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) lo, up = .2, .8 path = spl.line(lo, up, .5) spl.update_img(img, path, xs_func, nrep=1000, periodic=False)
def test_spline(beg, end, nbpoints): """ test that spline return a null vector for a line """ path = spl.line(beg, end, npoints=nbpoints) # create a path from a line y2s = spl.spline.spline( path[:, 0], path[:, 1] ) # create the spline from the path, nb: path[:,0] is the first column assert y2s == pytest.approx(np.zeros( nbpoints)) # check that the second derivative is a null vector
def line(img): """ line """ def xs_func(): """ xs function """ nsamples = 500 return .001 * np.random.random() + np.linspace(beg + .1, end - .1, nsamples) beg, end = .2, .8 path = spl.line(beg, end, .5) spl.update_img(img, path, xs_func, nrep=1000, periodic=False)
def test_spline(beg, end, nbpoints): path = spl.line(beg, end, npoints=nbpoints) y2s = spl.spline.spline(path[:, 0], path[:, 1]) assert y2s == pytest.approx(np.zeros(nbpoints))
import numpy as np import splinart as spl img_size, channels = 1000, 4 img = np.ones((img_size, img_size, channels)) #, dtype=np.float32) lo, up = .2, .8 path = [] color_lines = [] npoints = 20 for iy, y in enumerate(np.linspace(lo, up, 10)): npoints += 5 path.append(spl.line(lo, up, y, npoints)) color = np.random.random(4) * .3 color[-1] = 1. color_lines.append(color) def xs_func(): nsamples = 500 return .001 * np.random.random() + np.linspace(lo + .02, up - .02, nsamples) for i in range(len(path)): img1 = np.ones_like(img) spl.update_img(img1, path[i], xs_func, nrep=1000, periodic=False,
# Author: # Loic Gouarin <*****@*****.**> # # License: BSD 3 clause 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) def xs_func(): nsamples = 500 return .001*np.random.random() + np.linspace(lo+.1,up-.1, nsamples) lo, up = .2, .8 path = spl.line(lo, up, .5) spl.update_img(img, path, xs_func, nrep=1000, periodic=False) spl.save_img(img, "./output", "line.png")
def test_line(nbpoints, expected): path = spl.line(0, 1, npoints=nbpoints) assert path == approx(expected)
def test_line_2(): path = spl.line(0, 1, npoints=3) assert path == approx(np.array([[0, 0.5], [0.5, 0.5], [1, 0.5]]))