-
Notifications
You must be signed in to change notification settings - Fork 0
/
bfArea.ijm
95 lines (83 loc) · 2.15 KB
/
bfArea.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
90
91
92
93
94
95
// vim: set filetype=javascript:
macro "bfArea" {
//setBatchMode(true);
bfArea();
}
function bfArea() {
roiManager("reset");
run("Select None");
orig = getImageID();
slices = nSlices();
project_dir = File.getParent(getDirectory("image"));
Dialog.create("Enter time info");
Dialog.addNumber("Start time (hours)",0);
Dialog.addNumber("Time step (hours)",1.5);
Dialog.show();
start = Dialog.getNumber();
dt = Dialog.getNumber();
//print(project_dir);
f = File.open(project_dir+"/bfArea_results.txt");
print(f,"position\tslice\ttime\tarea");
for (slice=1; slice<nSlices; slice++) {
setSlice(slice);
title = getTitle();
flat = flatten();
mask = makeMask(flat);
run("Create Selection");
List.setMeasurements;
area = List.getValue("Area");
time = start+(slice-1)*dt;
print(f,title+"\t"+slice+"\t"+time+"\t"+area);
roiManager("reset");
run("Select None");
close();
close();
}
}
function flatten() {
run("Duplicate...", "title=flat");
id = getImageID();
title = getTitle();
image_name = replace(title,'.tif',"");
rad=50;
selectImage(id);
run("Duplicate...", "title=bg");
bg_id = getImageID();
run("Select None");
run("Gaussian Blur...", "sigma=10");
run("Subtract Background...", "rolling="+rad+" light parabaloid create");
imageCalculator("Subtract create 32-bit", id, bg_id);
rename(image_name+"_flat.tif");
f_id = getImageID();
selectImage(bg_id);
close();
selectImage(id);
close();
return f_id;
}
function makeMask(id) {
run("Select None");
selectImage(id);
run("Duplicate...", "title=mask");
mask = getImageID();
run("16-bit");
run("Gaussian Blur...", "sigma=1");
run("8-bit");
run("Variance...", "radius=2");
setAutoThreshold("MaxEntropy dark");
run("Convert to Mask","");
run("Fill Holes");
return mask;
}
function measureSelections(id) {
selectImage(id);
title = getTitle();
nStarts = roiManager("count");
for (sel=0;sel<nStarts;sel++) {
roiManager("Select",sel);
List.setMeasurements;
area = List.getValue("Area");
sd = List.getValue("StdDev");
print(f,title+"\t"+slice+"\t"+(sel+1)+"\t"+area+"\t"+sd);
}
}