-
Notifications
You must be signed in to change notification settings - Fork 1
/
BATCH_Select_area_calculate_fraction
107 lines (75 loc) · 2.51 KB
/
BATCH_Select_area_calculate_fraction
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
96
97
98
99
100
101
102
103
104
105
106
107
//Tested using ImageJ 1.53c
//Opens images and ask user to select ROIs, save area of ROIs and calculate area fraction for each. saves image and results
#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix
run("Set Measurements...", "area area_fraction redirect=None decimal=6");
processFolder(input);
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}
function processFile(input, output, file) {
open(input+File.separator+list[i]);
//******User varialbes
rolling_ball = 50;
gaussian = 2;
lower_threshold = 60;
//Get image properties
run("Z Project...", "projection=[Max Intensity]");
title = getTitle();
noEXT = File.nameWithoutExtension;
run("Split Channels");
run("Merge Channels...", "c2=[C2-"+title+"] c3=[C1-"+title+"] create ignore");
rename(title);
//*****Filters
//Add two slacshes before a filter if you dont want to use it
run("Gaussian Blur...", "sigma="+gaussian);
run("Subtract Background...", "rolling="+rolling_ball);
//Save Filtered Image
selectImage(title);
saveAs("tiff", output+File.separator+noEXT+"_FLT.tiff");
//loop over the ROI selection
calculate=false;
while (calculate==false) {
ROISelector(lower_threshold);
Dialog.createNonBlocking("Controls");
Options = newArray("Make another ROI", "Next Image");
Dialog.addRadioButtonGroup("Options", Options, 2, 1, "Make another ROI");
Dialog.show();
next = Dialog.getRadioButton;
row = nResults-1;
setResult("Cell", row, noEXT);
if (next=="Make another ROI") {
}
if (next=="Next Image") {
calculate = true;
close("*");
updateResults();
}
}
saveAs("Results", output+File.separator+"Results.csv");
//ROI Selection function
function ROISelector(lower_threshold) {
run("Select None");
waitForUser("Select ROI. Press OK after selection");
isSelection=is("area");
if (isSelection==false) {
run("Select All");
}
setOption("BlackBackground", true);
Stack.setChannel(1);
run("Duplicate...", "title=ROI_area");
getStatistics(area, mean, min, max, std, histogram);
setThreshold(lower_threshold, max);
run("Measure");
close();
selectImage(noEXT+"_FLT.tiff");
}
}