forked from hoogenboom-lab/image-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Branching.ijm.ijm
87 lines (75 loc) · 2.33 KB
/
Branching.ijm.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
title = getTitle();
dir = "";
dotIndex = indexOf(title, "tif") - 1;
name = substring(title, 0, dotIndex);
skeletonname = name + "_skeleton";
skelsave = dir + "output/" + skeletonname + ".tif";
longestpaths = dir + "output/" + name + "labelled_skel.tif";
branchinfo = dir + "output/" + name + "Branch_information.txt";
marked = dir + "output/" + name + "marked.tif";
//Get marked MACs as filled circles
selectWindow(title);
run("Set Scale...", "distance=1 known=1 pixel=1 unit=nm");
run("8-bit");
setThreshold(88, 109);
run("Convert to Mask");
run("Fill Holes");
run("Despeckle");
//Skeletonise and remove very small paths due to single MACs
run("Duplicate...", " ");
rename(skeletonname);
run("Skeletonize");
run("Dilate");
run("Analyze Particles...", "size=25-Infinity pixel show=Masks display");
//Save skeleton
selectWindow("Mask of " + skeletonname);
save(skelsave);
close("Results");
//Analyse skeleton
run("Invert");
run("Skeletonize");
run("Invert");
run("Analyze Skeleton (2D/3D)", "prune=none calculate show display");
selectWindow("Branch information");
close();
close("Results");
//Get longest branches only
selectWindow("Longest shortest paths");
setThreshold(96, 96);
run("Convert to Mask");
run("Make Binary");
run("Invert");
selectWindow("Tagged skeleton");
setThreshold(30, 70);
run("Convert to Mask");
run("Make Binary");
run("Invert");
imageCalculator("AND create", "Longest shortest paths","Tagged skeleton");
selectWindow("Result of Longest shortest paths");
run("Invert");
run("Analyze Particles...", "size=4-Infinity pixel show=Masks display");
close("Results");
//Get lengths of longest branches and save results
run("Analyze Skeleton (2D/3D)", "prune=none calculate show display");
selectWindow("Branch information");
save(branchinfo);
selectWindow("Mask-labeled-skeletons");
run("RGB Color");
save(longestpaths);
close("Results");
//Save MACs marked with branches
selectWindow("Mask of Result of Longest shortest paths");
run("Maximum...", "radius=3");
run("Fire");
run("Max...", "value=211");
selectWindow(title);
run("Fire");
run("Max...", "value=85");
imageCalculator("Transparent-zero create", title, "Mask of Result of Longest shortest paths");
selectWindow("Result of "+title);
run("Duplicate...", " ");
rename("white");
run("Min...", "value=255");
imageCalculator("Transparent-zero create", "white","Result of "+title);
save(marked);
close("*")