-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path180619_mask_generator_for_keras.ijm
106 lines (93 loc) · 2.62 KB
/
180619_mask_generator_for_keras.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
96
97
98
99
100
101
102
103
104
105
106
/*
* Elyra batch scaling and color merging
* Artur Yakimovich (c) copyright 2016. UCL
*/
function getDirAndFileList(ReadPath, filePattern, listType){
//listType = "dir" or "file", file default
list = getFileList(ReadPath);
//clean up the file list
dirList = newArray();
fileList = newArray();
for(i=0; i<=list.length-1; i++){
if (endsWith(list[i], "/"))
dirList = Array.concat(dirList, list[i]);
else if (matches(list[i], filePattern))
fileList = Array.concat(fileList, list[i]);
}
if (listType == "dir"){
return dirList;
}
else if (listType == "file"){
return fileList;
}
else {
return fileList;
}
}
function addPlateOutline(title,maskDir){
//add selctions
makePolygon(244,84,3512,100,3544,2312,172,2304);
//here user outlines the mask for splitting
waitForUser("Adjust selection for the plate outline");
run("Create Mask");
run("Invert LUT");
roiManager("Deselect");
selectWindow("Mask");
saveAs("Png", maskDir+File.separator+title);
close();
selectWindow(title);
}
function addWellsOutline(title,maskDir){
//add selctions
size = 164;
startX=550;
startY=310;
stepX =230;
stepY=230;
for(i=0;i<12;i++){
for(j=0;j<8;j++){
makeOval(startX+i*stepX, startY+j*stepY, size, size);
roiManager("Add");
run("Select None");
}
}
count = roiManager("count");
print(count);
selections = newArray();
for(i=0;i<count;i++){
Array.concat(selections,i);
}
Array.print(selections);
roiManager("Show All with labels");
//here user outlines the mask for splitting
waitForUser("Adjust selection for the wells outline. Use ROI manager + Update to update wells position");
roiManager("Select", selections);
roiManager("Show All");
roiManager("Combine");
run("Create Mask");
run("Invert LUT");
selectWindow(title);
roiManager("Select", newArray(roiManager("count")));
roiManager("Delete");
roiManager("Deselect");
selectWindow("Mask");
saveAs("Png", maskDir+File.separator+title);
close();
selectWindow(title);
}
inDir = getDirectory("Select the input folder...");
setBatchMode(false);
files = getDirAndFileList(inDir, ".*.jpg", "file");
outDir = inDir + File.separator + "masks";
File.makeDirectory(outDir);
mask1Dir = outDir + File.separator + "wellsMask";
File.makeDirectory(mask1Dir);
mask2Dir = outDir + File.separator + "plateMask";
File.makeDirectory(mask2Dir);
for (iFiles=0; iFiles < files.length; iFiles++){
run("Bio-Formats Importer", "open="+inDir+File.separator+files[iFiles]+" color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT use_virtual_stack");
title = getTitle();
addPlateOutline(title,mask1Dir);
addWellsOutline(title,mask2Dir);
close();
}