Mercurial > hg > segmentation
comparison cnmf.py @ 7:294f66d285af
some previous changes
author | mitian |
---|---|
date | Tue, 05 May 2015 08:54:09 +0100 |
parents | 56a2ca9359d0 |
children | 915c849b17ea |
comparison
equal
deleted
inserted
replaced
6:719b4ff8e9c9 | 7:294f66d285af |
---|---|
16 import pymf | 16 import pymf |
17 | 17 |
18 # Local stuff | 18 # Local stuff |
19 from utils import SegUtil | 19 from utils import SegUtil |
20 | 20 |
21 # Algorithm params | |
22 h = 8 # Size of median filter for features in C-NMF | |
23 R = 15 # Size of the median filter for the activation matrix C-NMF | |
24 rank = 4 # Rank of decomposition for the boundaries | |
25 rank_labels = 6 # Rank of decomposition for the labels | |
26 R_labels = 6 # Size of the median filter for the labels | |
21 | 27 |
22 def cnmf(S, rank, niter=500): | 28 def cnmf(S, rank, niter=500): |
23 """(Convex) Non-Negative Matrix Factorization. | 29 """(Convex) Non-Negative Matrix Factorization. |
24 | 30 |
25 Parameters | 31 Parameters |
86 G = np.sum(G, axis=1) | 92 G = np.sum(G, axis=1) |
87 G = SegUtil.median_filter(G[:, np.newaxis], R) | 93 G = SegUtil.median_filter(G[:, np.newaxis], R) |
88 return G.flatten() | 94 return G.flatten() |
89 | 95 |
90 | 96 |
91 def segmentation(X, rank, R, h, niter=300): | 97 def segmentation(X, rank=4, R=15, h=8, niter=300): |
92 """ | 98 """ |
93 Gets the segmentation (boundaries and labels) from the factorization | 99 Gets the segmentation (boundaries and labels) from the factorization |
94 matrices. | 100 matrices. |
95 | 101 |
96 Parameters | 102 Parameters |
136 rank += 1 | 142 rank += 1 |
137 bound_idxs = None | 143 bound_idxs = None |
138 else: | 144 else: |
139 break | 145 break |
140 | 146 |
141 return bound_idxs | 147 return G, bound_idxs |