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)
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 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_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"])
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
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, color=color_lines[i]) mask = img1 < 1. img[mask] += img1[mask] spl.save_img(img, "./output", "lines.png")
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, "radius": RADIUS, "nrep": NREP, "output": "./circle.png" } }, indent=4)
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) spl.update_img(img1, path_circles[i], xs_func, nrep=1000, scale_value=.00005, x=theta_circles[i], color=color_circles[i]) mask = img1 < 1. img[mask] += img1[mask] spl.save_img(img, './output', 'circles.png')
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')
# 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")