-
Notifications
You must be signed in to change notification settings - Fork 0
/
HCmasking-chPrj.ijm
148 lines (132 loc) · 4.05 KB
/
HCmasking-chPrj.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Functions:
// interactive process to generate hair cell masks
// batch processing all czi 3D image stacks in the folder
// save Z-projection for each channel
// save the binary mask of the roi
//
// Depends on plugin Masks From ROIs : https://sites.imagej.net/MasksfromRois/
// 20230517 Leiz
// **************************************************************
// Channel arrrangment:
chArr = newArray("_hc", "TH", "_Vamp2");
chColor = newArray("Grays","Magenta", "Green");
suffix_for_HCmsk = "_hc_msk";
//***************************************************************
inDir = getDirectory("--> INPUT: Choose Directory <--");
outDir = getDirectory("--> OUTPUT: Choose Directory for TIFF Output <--");
inList = getFileList(inDir);
list = getFromFileList("czi", inList); // select dirs only
Array.sort(list);
nl = list.length;
// Checkpoint: get list of dirs
print("Below is a list of files to be processeded:");
printArray(list); // Implemented below
print("Result save to:");
print(outDir);
outChPrj = outDir + File.separator + "chPrj" + File.separator;
if (!File.exists(outChPrj)) {
File.makeDirectory(outChPrj);
}
setBatchMode(false);
roiManager("show none");
roiManager("reset");
for (i=0; i<nl; i++)
{
inFullname = inDir + list[i];
sampleID = substring(list[i],0, lengthOf(list[i])-4);
outFullname = outDir + sampleID + suffix_for_HCmsk + ".tif";
print("Saving(",(i+1),"/",list.length,")...",list[i]);
open(inFullname);
rename("Current");
getDimensions(width, height, channels, slices, frames);
run("Duplicate...", "title=Current1 duplicate");
run("Subtract Background...", "rolling=50 stack");
run("Split Channels");
for (j=1;j<channels+1;j++){
curPrj = outChPrj + sampleID + chArr[j-1] + "Prj.tif";
if(!File.exists(curPrj)){
selectWindow("C" + j + "-Current1");
run("Z Project...", "projection=[Max Intensity]");
saveAs("Tiff", curPrj );
selectWindow("C" + j + "-Current1"); close();
}
}
selectWindow("Current");
run("Z Project...", "projection=[Max Intensity]");
rename("zpj");
selectWindow("zpj");
Stack.setDisplayMode("composite");
Stack.setActiveChannels("111");
Stack.setChannel(1)
run("Enhance Contrast", "saturated=0.02");
run(chColor[0]);
Stack.setChannel(2)
run(chColor[1]);
run("Enhance Contrast", "saturated=0.02");
Stack.setChannel(3)
run(chColor[2]);
run("Enhance Contrast", "saturated=0.35");
run("Flatten");
// Prompt the user to draw an ROI
run("ROI Manager...");
roiManager("reset");
run("Show All");
selectWindow("zpj-1");
waitForUser("Draw ROI, then hit OK");
roiManager("Add");
run("Binary (0-255) mask(s) from Roi(s)", "show_mask(s) save_in=[] suffix=[] save_mask_as=tif rm=[RoiManager[size=1, visible=true]]");
saveAs("Tiff", outFullname);
roiManager("reset");
run("Close All");
print("...done."); //Checkpoint: Done one.
}
setBatchMode("exit and display");
print("--- All Done ---");
// --- Main procedure end ---
function getFromFileList(ext, fileList)
{
// Select from fileList array the filenames with specified extension
// and return a new array containing only the selected ones.
selectedFileList = newArray(fileList.length);
selectedDirList = newArray(fileList.length);
ext = toLowerCase(ext);
j = 0;
iDir = 0;
for (i=0; i<fileList.length; i++)
{
extHere = toLowerCase(getExtension(fileList[i]));
if (endsWith(fileList[i], "/"))
{
selectedDirList[iDir] = fileList[i];
iDir++;
}
else if (extHere == ext)
{
selectedFileList[j] = fileList[i];
j++;
}
}
selectedFileList = Array.trim(selectedFileList, j);
selectedDirList = Array.trim(selectedDirList, iDir);
if (ext == "")
{
return selectedDirList;
}
else
{
return selectedFileList;
}
}
/////
function printArray(array)
{
// Print array elements recursively
for (i=0; i<array.length; i++)
print(array[i]);
}
////
function getExtension(filename)
{
ext = substring( filename, lastIndexOf(filename, ".") + 1 );
return ext;
}