Skip to content

Commit 7b3025a

Browse files
author
Emmanuelle Gouillart
committed
example file that shows how to separate a shape in different objects,
using spectral clustering
1 parent c1c9a66 commit 7b3025a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test_white_spectral_clustering.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import numpy as np
2+
from diffusions import _build_laplacian
3+
import pyamg
4+
5+
l = 100
6+
X, Y = np.indices((l, l))
7+
8+
c1 = (28, 24)
9+
c2 = (40, 50)
10+
c3 = (67, 58)
11+
c4 = (24, 80)
12+
c5 = (83, 34)
13+
14+
r1, r2, r3, r4, r5 = 16, 14, 15, 24, 14
15+
16+
m1 = (X - c1[0])**2 + (Y - c1[1])**2 < r1**2
17+
m2 = (X - c2[0])**2 + (Y - c2[1])**2 < r2**2
18+
m3 = (X - c3[0])**2 + (Y - c3[1])**2 < r3**2
19+
m4 = (X - c4[0])**2 + (Y - c4[1])**2 < r4**2
20+
m5 = (X - c5[0])**2 + (Y - c5[1])**2 < r5**2
21+
22+
23+
#m1[::4, ::4] = False
24+
m = (m1 + m2 + m3 + m4).astype(bool)
25+
mask = np.copy(m)
26+
m = m.astype(float)
27+
28+
m /= 2
29+
m += 0.5
30+
31+
m += 0.1 * np.random.randn(*m.shape)
32+
33+
res, scores = separate_in_regions(m, mask, mode='amg', take_first=True)

0 commit comments

Comments
 (0)