diff --git a/ecut/base_types.py b/ecut/base_types.py index 1f37b91..783d893 100644 --- a/ecut/base_types.py +++ b/ecut/base_types.py @@ -192,6 +192,8 @@ def _linear_programming(self): frag.source = dict.fromkeys(frag.traversed, 1) for variable in self._problem.variables(): + if 'dummy' in variable.name: + continue frag_id, src = variable.name.split('_')[1:] frag_id, src = int(frag_id), int(src) frag = self._fragment[frag_id] diff --git a/example/app2_processing.py b/example/app2_processing.py index 0896df4..b2e72ec 100644 --- a/example/app2_processing.py +++ b/example/app2_processing.py @@ -9,13 +9,14 @@ if __name__ == '__main__': # tree = swc_handler.parse_swc('../test/data/gcut_input.swc_sorted.swc') - tree = swc_handler.parse_swc(r'D:\rectify\my_app2\17302_14358_42117_2799.swc') + # tree = swc_handler.parse_swc(r'D:\rectify\my_app2\17302_14358_42117_2799.swc') + tree = swc_handler.parse_swc(r"C:\Users\zzh\Downloads\2965_9868_7229.swc") tree = [t for t in tree if not (t[1] == t[2] == t[3] == 0)] # tree = swc_handler.parse_swc(r'D:\rectify\my_app2\15257_16445_16836_4489.swc') - - maxr = max([t[5] for t in tree]) * .3 - rad = max(maxr * .5, 5.) - centers = DetectTracingMask(rad, 20.).predict(tree, [.3, .3, 1]) + res = .23 + maxr = max([t[5] for t in tree]) * res + rad = max(maxr * .5, 3.) + centers = DetectTracingMask(rad, 20.).predict(tree, [res, res, 1]) # anneal a = MorphAnneal(tree) tree = a.run() @@ -26,15 +27,14 @@ kd = KDTree([t[2:5] for t in tree]) inds = kd.query(centers, return_distance=False) inds = [tree[i[0]][0] for i in inds] - print(inds) + print(inds, centers) e = ECut(tree, inds) e.run() trees = e.export_swc() - # pruning for k, v in trees.items(): v = swc_handler.sort_swc(v) - p = ErrorPruning([.3,.3,1], anchor_dist=20., soma_radius=10.) + p = ErrorPruning([res,res,1], anchor_dist=20., soma_radius=10.) morph = Morphology(v) a = p.branch_prune(morph, 60, 1.5) b = p.crossover_prune(morph, 2, 60, 90, short_tips_thr=10., no_multi=False) diff --git a/example/batch_1891.py b/example/batch_1891.py deleted file mode 100644 index 31d0eef..0000000 --- a/example/batch_1891.py +++ /dev/null @@ -1,63 +0,0 @@ -from ecut import swc_handler -from ecut.annealing import MorphAnneal -from ecut.graph_cut import ECut -from ecut.soma_detection import DetectTracingMask -from sklearn.neighbors import KDTree -from ecut.error_prune import ErrorPruning -from ecut.morphology import Morphology -from traceback import print_exc - - -def main(args): - in_path, out_path = args - try: - tree = [t for t in swc_handler.parse_swc(in_path) if not (t[1] == t[2] == t[3] == 0)] - - # detect soma - d = DetectTracingMask(3) - soma = d.predict(tree, [.3, .3, 1]) - - # anneal - a = MorphAnneal(tree) - tree = a.run() - - # map soma - kd = KDTree([t[2:5] for t in tree]) - inds = kd.query(soma, return_distance=False) - inds = [tree[i[0]][0] for i in inds] - - # graph cut - if len(inds) > 1: - e = ECut(tree, inds) - e.run() - trees = e.export_swc() - else: - trees = {0: tree} - - # pruning - for k, v in trees.items(): - p = ErrorPruning([.3, .3, 1], anchor_reach=(5., 20.)) - morph = Morphology(v) - a = p.branch_prune(morph, 45, 2) - b = p.crossover_prune(morph, 5, 90) - # c = p.crossover_prune(morph, check_bif=True) - t = swc_handler.prune(v, a | b) - swc_handler.write_swc(t, str(out_path) + f'_{k}.swc') - except: - print_exc() - print(in_path) - - -if __name__ == '__main__': - from pathlib import Path - from tqdm import tqdm - from multiprocessing import Pool - indir = Path('D:/rectify/my_app2') - outdir = Path('D:/rectify/pruned') - outdir.mkdir(exist_ok=True) - files = sorted(indir.glob('*.swc')) - outfiles = [outdir / f.name for f in files] - arglist = [*zip(files, outfiles)] - with Pool(12) as p: - for i in tqdm(p.imap(main, arglist), total=len(arglist)): - pass \ No newline at end of file