-
Notifications
You must be signed in to change notification settings - Fork 0
/
subtract_background_cmndln.ijm
83 lines (67 loc) · 2.23 KB
/
subtract_background_cmndln.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
/* Remove background and isolate single channel for downstream FQ analysis
* 18 January 2019
*
* Uses 'rolling ball' background subtraction algorithm
*
* ---Modifications to allow the code to run -headless---
*
* -Replaced Bioformats with open by enabling SCIFIO, Edit>Options>IM2>Check SCIFIO
* -Duplicate hyperstack instead of arrange channels
* -Pass directory from command line argument instead of calling finder window
*
* ---Macro commands---
*
* Setup directories
* Select the appropriate channel
* Subtract background
* Save single channel image
*
* ----Call from the command line with the following script:
* fiji --headless --console -macro ~/src/FIJI_macros/subtract_background_cmndln.ijm /path/to/directory
*
* ---requires absolute path---
*/
macro "Subtract_background" {
setBatchMode(true);
// Setup directories
indir = getArgument();
list = getFileList(indir);
GFP_channel = ('2');
smFISH_channel = ('3');
File.makeDirectory(indir+'GFP_channel');
File.makeDirectory(indir+'smFISH_channel');
GFP_dir = indir+'GFP_channel/';
smFISH_dir = indir+'smFISH_channel/';
// Setup loop
for (j=0; j<list.length; j++) {
showProgress(j+1, list.length);
filename = indir + list[j];
if (endsWith(filename, ".tiff"))
print("processing ... "+j+1+"/"+list.length+"\n "+list[j]);
// Open file
if (endsWith(filename, ".tiff"))
open(filename);
// Start macro
// Duplicate stack and select specific channel
original = getTitle();
run("Duplicate...", "duplicate channels=GFP_channel");
GFP = getTitle();
selectWindow(original);
run("Duplicate...", "duplicate channels=smFISH_channel");
smFISH = getTitle();
selectWindow(original);
close();
// Subtract background
selectWindow(GFP);
run("Subtract Background...", "rolling=8 stack");
GFP_file = replace(GFP, "-1.tiff", "_GFP.tiff");
saveAs("Tiff", GFP_dir+GFP_file);
close();
selectWindow(smFISH);
run("Subtract Background...", "rolling=8 stack");
smFISH_file = replace(smFISH, "-1.tiff", "_smFISH.tiff");
saveAs("Tiff", smFISH_dir+smFISH_file);
close();
}
setBatchMode(false);
}