-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLABELS_Binarize_Exclude labels option_Batch.3.2.ijm
57 lines (50 loc) · 1.83 KB
/
LABELS_Binarize_Exclude labels option_Batch.3.2.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
#@ File (label="Select mask directory", style = "directory") input
#@ File (label="Select output directory", style = "directory") output
#@ String (label="filter by string (separated by _ in the original name)", value="Object Predictions.tiff") filter
#@ Boolean (label= "remove filter strning from the output file name?") remove
#@ String (label="Prefix to add", value="mk") tag
#@ String (label="Labels to Exclude, separated by commas", value="3,4") labels
/*
* This Macro gets a list of label images in which one or more gray levels identify specific objects types,
* as those exported by Ilastik as Object predictions. All labels but those indicated by the user will be assigned the value of 255.
*/
labels=split(labels,",");
setBatchMode(true);
InputList = getFileList(input);
print("files in stack directory: "+InputList.length);
for (l = 0; l < InputList.length; l++) {
Name_split=split(InputList[l], "_");
if(contains(Name_split,filter)){
open(input+File.separator+InputList[l]);
Img=getTitle();
getDimensions(width, height, channels, slices, frames);
//Erase the unwanted labels
for (i = 0; i <labels.length; i++) {
setThreshold(labels[i], labels[i], "raw"); //must be a string
for (s = 0; s < slices; s++) {
setSlice(s+1);
run("Create Selection");
setForegroundColor(0, 0, 0);
if(selectionType()!=-1){
run("Fill", "slice");
}
run("Select None");
}
}
//Binarize the image
getStatistics(area, mean, min, max, std, histogram);
setThreshold(1, max);
run("Convert to Mask", "method=Default background=Dark black");
// Save the result
if(remove){
Img=replace(Img,"_"+filter,"");
}
saveAs("tiff", output+File.separator+tag+Img);
}
}
print("Done!");
function contains(array, value ) {
for (i=0; i<array.length; i++)
if ( array[i] == value ) return true;
return false;
}