-
Notifications
You must be signed in to change notification settings - Fork 0
/
MembraneSegmentation.ijm
91 lines (65 loc) · 2.24 KB
/
MembraneSegmentation.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
86
87
88
89
// Membrane segmentation using MorphoLibJ
// Performs membrane segmentation on image stack (frame by frame), and exports
// the watershed lines as a new image stack.
// Get stack path, name and basename
path = getDirectory("image");
stackname = getTitle();
basename = File.getNameWithoutExtension(stackname);
// Set name for output watershed stack
watername = basename + "-watershed";
// Define tolerance value for segmentation
tolerance = 20;
// Waiting time needed for MorphoLibJ macro to work
waitime = 5000;
// Get stack dimensions
Stack.getDimensions(width, height, channels, slices, frames);
// Swap slices by frames if needed
// TODO: Handle this better
if (frames == 1 && slices > 1) {
run("Properties...", "slices=" + frames + " frames=" + slices);
frames = slices;
slices = 1;
}
// Loop over slices
for (i=1; i<=frames; i++) {
// Select window
selectWindow(stackname);
// Set current frame
Stack.setFrame(i);
// Duplicate current slice
run("Duplicate...", " ");
// Begin MorphoLibJ default segmentation
run("Morphological Segmentation");
wait(waitime);
// Activate batch mode
setBatchMode(true);
// Run membrane segmentation using default parameters
selectWindow("Morphological Segmentation");
call("inra.ijpb.plugins.MorphologicalSegmentation.segment", "tolerance=" + tolerance, "calculateDams=true", "connectivity=4");
wait(waitime);
// Select catchment basins image type
selectWindow("Morphological Segmentation");
call("inra.ijpb.plugins.MorphologicalSegmentation.setDisplayFormat", "Watershed lines");
wait(waitime);
// Generate segmentation results
selectWindow("Morphological Segmentation");
call("inra.ijpb.plugins.MorphologicalSegmentation.createResultImage");
rename("watershed" + i);
// Generate segmentation results
close("Morphological Segmentation");
// Close mysterious hidden stack
close(basename + "-1.tif");
// Disable batch mode
setBatchMode(false);
}
// Close main stack
close(stackname);
// Concatenate images to watershed stack
run("Images to Stack", "name=" + watername + " use");
// Set dimensions
Stack.setDimensions(channels, slices, frames);
// Save watershed to file
save(path + watername);
// Close watershed
close(watername);
// Watershed is ready for editing or for downstream analyses