-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMembraneAnalyze.ijm
85 lines (60 loc) · 2.26 KB
/
MembraneAnalyze.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
// Analyze membrane segmentation using MorphoLibJ
// Analyze the morphometry of segmented cells on image stack containing
// watershed lines, output stack with labeled cells and data tables.
// Get stack path and name
path = getDirectory("image");
stackname = getTitle();
// Set names for later usage
basename = File.getNameWithoutExtension(stackname);
mapname = replace(basename, "watershed", "labelmap.tif");
tablename = replace(basename, "watershed", "morphometry");
// Get stack dimensions
Stack.getDimensions(width, height, channels, slices, frames);
// Activate batch mode
setBatchMode(true);
// Loop over slices
for (i=1; i<=frames; i++) {
// Select window
selectWindow(stackname);
// Set current frame
Stack.setFrame(i);
// Duplicate current frame
run("Duplicate...", " ");
rename("frame");
// Remove labels from borders
run("Kill Borders");
rename("killborders");
// Identify connected components
run("Connected Components Labeling", "connectivity=4 type=[16 bits]");
rename("labelmap");
// Calculate area and other measurements of segmented cells
run("Analyze Regions", "pixel_count area perimeter circularity bounding_box centroid equivalent_ellipse ellipse_elong. convexity max._feret oriented_box oriented_box_elong. geodesic tortuosity max._inscribed_disc average_thickness geodesic_elong.");
// Name automatically given to measurements window
morphometry = tablename + "-frame" + i + ".txt";
Table.rename("labelmap-Morphometry", morphometry);
// Add shape index to table
Table.applyMacro("Shape=Perimeter/Math.sqrt(Area) Frame=" + i, morphometry);
// Save table to file
Table.save(path + morphometry);
// Copy label image and paste to label stack
selectWindow("labelmap");
run("Set Label Map", "colormap=[Golden angle] background=Black");
rename("labelmap" + i);
// Close temporary windows
close(morphometry);
close("killborders");
close("frame");
}
// Close main stack
close(stackname);
// Concatenate images to labelmap stack
run("Images to Stack", "name=" + mapname + " use");
// Set dimensions
Stack.setDimensions(channels, slices, frames);
// Save labelmap to file
save(path + mapname);
// Close files
close(mapname);
// Labelmap and morphometry are ready for downstream analyses and visualization
// Disable batch mode
setBatchMode(false);