예제 #1
0
def mink(A, B, t, col):
	L = []
	for a in A:
		x, y = base.setToLists([t*a+(1-t)*b for b in B])
		L.append(pl.fill(x, y, color=col)[0])
	for b in B:
		x, y = base.setToLists([t*a+(1-t)*b for a in A])
		L.append(pl.fill(x, y, color=col)[0])
	return L
예제 #2
0
	def aux(s):
		seen[s] = True
		for r, _ in E[s]:
			x, y = setToLists([s, r])
			pl.plot(x, y, color=ec, alpha=ealph, linewidth=ew)
			if not seen[r]:
				aux(r)
예제 #3
0
def plotGraph(V, E, ec='green', ealph=0.5, ew=0.8):
	x, y = setToLists(V)
	pl.scatter(x, y)
	seen = dict.fromkeys(V, False)
	def aux(s):
		seen[s] = True
		for r, _ in E[s]:
			x, y = setToLists([s, r])
			pl.plot(x, y, color=ec, alpha=ealph, linewidth=ew)
			if not seen[r]:
				aux(r)
	aux(V[0])
예제 #4
0
#!/usr/bin/env python3

from base import pointSet, setToLists
from convexe import convex_hull
import pylab as pl
import plot_opt
import matplotlib.animation as anim
from math import log, exp

T = 80
s = pointSet(0, 1, 0, 1, 6)
x0, y0 = setToLists(convex_hull(s))
l = len(x0) - 1
ims = []

fig = pl.figure()


def f(t):
    return (1 + (t / T)**0.45) / 2


di0 = ((x0[0] - x0[1])**2 + (y0[0] - y0[1])**2)**0.5
for t in range(T):
    im = [pl.plot(x0, y0, color=(t / T, 0, 1 - t / T))[0]]
    x, y = x0.copy(), y0.copy()
    di = di0 * (1 - f(t))
    d = di0
    while d >= 2 * di:
        a = di / d
        for j in range(l):
예제 #5
0
import pylab as pl
import plot_opt
import matplotlib.animation as anim

nim = 45
npoint = 500
temps = 3200
s = pointSet(0, 1, 0, 1, 5)
s.sort()
print(s)
bez = bezier(s, nim, int(npoint / nim))
colors = ['green', 'blue', 'purple', 'black']

fig = pl.figure()
piece_curve = []
x, y = setToLists(s)
init_points = pl.scatter(x, y, color='black')
init_curv = pl.plot(x, y, color='black')[0]
ims = [[init_curv, init_points]]

for cs, points in bez:
    im = [init_curv, init_points]
    x, y = setToLists(points)
    pc = pl.plot(x, y, color='red')[0]
    piece_curve.append(pc)
    for a in piece_curve:
        im.append(a)
    for i in range(len(cs)):
        x, y = setToLists(cs[i])
        im.append(pl.plot(x, y, color=colors[i])[0])
        im.append(pl.scatter(x, y, color=colors[i]))
fig = pl.figure(figsize=(6, 6))

n = 6000
centers = base.pointSet(0, 1, 0, 1, n - 4) + [
    Vec2D(0.01, 0.01),
    Vec2D(0.99, 0.01),
    Vec2D(0.01, 0.99),
    Vec2D(0.99, 0.99)
]
square = [Vec2D(0, 0), Vec2D(1, 0), Vec2D(1, 1), Vec2D(0, 1), Vec2D(0, 0)]
im = Image.open("base_images/panda.jpg").convert("RGB")
w, h = im.width, im.height


def get_col(c):
    col = im.getpixel((int(c.x * w), int(h - c.y * h)))
    return tuple(col[i] / 255 for i in range(3))


cells = delaunay.voronoi(centers)

x0, y0 = base.setToLists(centers)
for i in range(n):
    c = centers[i]
    cells[c] = base.interConv(cells[c], square)
    x, y = base.setToLists(cells[c])
    pl.fill(x, y, color=get_col(c), linewidth=0)

pl.show()
예제 #7
0
n = 180
V = [Vec2D(0.5, 0.5)] + pointSetSpace(0, 1, 0, 1, n - 1, 0.8 / n**0.5)
E = toGraph(V)
ds, pred = dijkstra(V, E, V[0])

fig = pl.figure()
pl.xlim(0, 1)
pl.ylim(0, 1)
plotGraph(V, E)

es = []
for v in V[1:]:
    es.append((ds[v], v))
es.sort()
es = [setToLists([e[1], pred[e[1]]]) for e in es]
ls = [pl.plot([], [], color='red', linewidth=1.6)[0] for _ in range(n - 1)]

nc = 7
dd = 1 / (nc - 1)
x, y = np.mgrid[slice(0, 1 + dd / 2, dd), slice(0, 1 + dd / 2, dd)]
z = [[[0, 0] for _ in range(nc)] for _ in range(nc)]
for v in V:
    a = round(nc * (v.x - 1 / nc / 2))
    b = round(nc * (v.y - 1 / nc / 2))
    c = z[a][b]
    c[0] += ds[v]
    c[1] += 1
for l in z:
    for i in range(nc):
        su, na = l[i]
예제 #8
0
N = 36
md = 0.02 ** 2
sig2 = 0.02
inter = 0.15
lenp = len(ps)
ds = [10] * lenp
centers = []
clusters = []
k_mean_ims = []

vertl, = pl.plot([1, 1], [0, 1], color='black')
t1, t2 = pl.text(0.05, 0.98, "Mean-Shift"), pl.text(1.05, 0.98, "K-Mean")
for ni in range(N):
	im = [vertl, t1, t2]
	x, y = setToLists(ps)
	for i in range(lenp):
		l = lines[i]
		x, y = setToLists(l)
		im.append(pl.plot(x, y, color='red')[0])
		lp = l[-1]
		c = (lp.x, abs(lp.x - lp.y), lp.y)
		im.append(pl.scatter([ps[i].x], [ps[i].y], color=c))
	if ni != N-1:
		np = []
		for l in lines:
			lp = l[-1]
			s = 0
			p = Vec2D(0, 0)
			for l2 in lines:
				if l == l2:
#!/usr/bin/env python3
from base import pointSetCircle, pointSet, setToLists
from convexe import convex_hull
import pylab as pl
import matplotlib.animation as anim

s = pointSetCircle(0, 0, 1, 80) + pointSet(-1.4, -0.65, -1.4, -0.65, 16)
chs = convex_hull(s, True)

fig = pl.figure()
xs, ys = setToLists(s)
pl.scatter(xs, ys, linewidths=0.0001)
chs = [setToLists(ch) for ch in chs]
cl, = pl.plot([], [], color='red', linewidth=2)


def animate(i):
    j = i % len(chs)
    cl.set_data(chs[j][0], chs[j][1])
    return cl,


ani = anim.FuncAnimation(fig, animate, repeat=True, interval=80)
pl.show()
import pylab as pl
import matplotlib.animation as anim
from delaunay import delaunay
import plot_opt
from random import random

n = 32
s = pointSetSpace(0, 1, 0, 1, n, 0.8 / n**0.5)
s.sort(key=lambda p: -abs(p.x - 0.5) - abs(p.y - 0.5) + random())

fig = pl.figure()
tss = delaunay(s, True)

ims = []
pts = {}
x, y = setToLists(s)
ps = [pl.scatter(x, y, color='green', s=10)]
toc = lambda t: (0, 0.5 - 0.5 * min(1, max(0, t.center.x)), 0.5 + 0.5 * min(
    1, max(0, t.center.y)))
for i in range(n):
    p = pl.scatter([s[i].x], [s[i].y], color='black', s=64)
    ps.append(p)
    im = ps.copy()
    for t in tss[i]:
        if t in pts:
            im.append(pts[t])
        else:
            x, y = t.toPylab()
            im.append(pl.plot(x, y, color='red')[0])
            if t in tss[i + 1]:
                pts[t] = pl.plot(x, y, color=toc(t))[0]
예제 #11
0
from convexe import convex_hull
import plot_opt
from PIL import Image
import sys

sys.setrecursionlimit(10**4)

n = 1000
rat = 12 / 8
s = pointSetSpace(0, rat, 0, 1, n, 0.8 / n**0.5)
s += [Vec2D(-10, -10), Vec2D(10, -10), Vec2D(-10, 10), Vec2D(10, -10)]

fig = pl.figure()
pl.xlim(0, rat)
pl.ylim(0, 1)
xs, ys = setToLists(s)
# pl.scatter(xs, ys, linewidths=1, color='blue')
ts = delaunay(s)
cs = []
es = {}
vs = {}
for t in ts:
    #x, y = t.toPylab()
    #pl.plot(x, y, linewidth=0.8, color='green')
    c = t.center
    cs.append(c)
    for e in t.edges():
        a, b = e
        # 	if e in es:
        # 		x, y = setToLists([es[e], c])
        # 		pl.plot(x, y, linewidth=0.4, color='red')
예제 #12
0
import math
import matplotlib.animation as anim

monk0 = [(93, 455), (46, 447), (19, 441), (12, 433), (10, 416), (19, 396), (34, 375), (52, 353), (80, 321), (72, 279), (68, 223), (64, 210), (79, 161), (93, 145), (172, 102), (191, 92), (232, 77), (266, 73), (332, 72), (360, 75), (411, 43), (440, 39), (464, 46), (484, 64), (491, 78), (500, 86), (492, 125), (499, 148), (500, 168), (496, 178), (484, 193), (464, 198),(405, 176), (389, 171), (377, 182), (389, 205), (408, 263), (421, 306), (437, 358), (456, 403), (460, 432), (466, 449), (456, 457), (431, 456), (422, 451), (426, 447), (431, 444),(430, 438), (427, 428), (422, 396), (377, 430), (350, 414), (346, 406), (360, 388), (364, 392), (364, 403), (369, 408), (376, 410), (392, 390), (386, 372), (383, 357), (372, 341),(308, 270), (297, 255), (293, 236), (250, 248), (196, 251), (211, 274), (227, 303), (234, 331), (245, 358), (259, 396), (269, 418), (289, 420), (322, 419), (340, 430), (340, 441),(334, 442), (329, 449), (289, 467), (259, 473), (238, 459), (203, 418), (179, 361), (178, 353), (142, 329), (132, 354), (103, 383), (66, 409), (77, 415), (110, 426), (117, 439), (113, 443), (101, 445), (100, 452), (93, 455)]
monk0 = [base.Vec2D(u, -v) for u, v in monk0]
monk = base.densify(monk0, 2)
cirs = []

# Initialisation du dessein
x0, x1, y0, y1 = base.setToRectangle(monk)
w, h = x1-x0, y1-y0
fig = pl.figure()
ax = fig.gca()
pl.xlim(x0-0.1*w, x1+0.1*w)
pl.ylim(y0-0.1*h, y1+0.1*h)
x, y = base.setToLists(monk0)
pl.plot(x, y)
cirs_im = []


sp = [base.Vec2D(2*x0-x1, 2*y0-y1), base.Vec2D(2*x1-x0, 2*y0-y1), base.Vec2D(2*x0-x1, 2*y1-y0), base.Vec2D(2*x1-x0, 2*y1-y0)]
ts = delaunay.delaunay(monk[:-1] + sp)
def valid(c, p):
	for a, r in cirs:
		if (p - a).norm22() < r:
			return False
	count = 0
	for i in range(len(monk0)-1):
		a, b = monk0[i], monk0[i+1]
		if (p.y > a.y) != (p.y > b.y):
			x = a.x + (p.y - a.y) / (b.y - a.y) * (b.x - a.x)