-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBV_Deconvolverv1.2..ijm
86 lines (83 loc) · 3.26 KB
/
DBV_Deconvolverv1.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
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
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////// MACRO INSTRUCTIONS ///////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////// This macro reads '.nd2; .czi; .tiff' files from an input directory and outputs ///////////////
//////////////// them as deconvolved ///////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////// David Kleinhans, 22.06.2016 ///////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
psfdir = "//141.2.47.191/grp_ak-lecaudey$/lab common/Analyse and process Images/PSFs (for deconvolution)/"
// Call CLEANUP
cleanup();
// Create Dialog
Dialog.create("Deconvolver v1.0");
Algoarr = newArray("RL", "else");
Dialog.addMessage("Z / .tif stacks only!");
Dialog.addChoice("Algorithm:", Algoarr);
Dialog.addNumber("Iterations", 20)
Dialog.show();
algo = Dialog.getChoice();
iter = Dialog.getNumber();
// CHOOSE PSF
files = newArray(0);
list = getFileList(psfdir);
for (i = 0; i < list.length; i++){
if(endsWith(list[i],".tif")){
files=Array.concat(files,list[i]);
}
}
Dialog.create("Choose PSF");
//psflist = getFileList(psfdir);
Dialog.addChoice("PSF", files);
Dialog.show();
PSF = Dialog.getChoice();
PSFp = psfdir + PSF;
// CHOOSE DIRECTORIES
input = getDirectory("Choose an input directory");
channel = File.getName(input);
// CREATE Subdirs
par = File.getParent(input); // get org parent directory
decondir = par + File.separator + channel + "_" + algo + iter + File.separator; // create directory to save metadata
File.makeDirectory(decondir);
// PRINT to LOG window
print("PARAMETERS");
print(" Algorithm: "+algo);
print(" Iterations: "+iter);
print("POINT SPREAD FUNCTION");
print(" PSF: "+PSF);
print("DIRECTORIES");
print(" INPUT directory: "+input);
print(" OUTPUT directory: "+decondir);
print("----------------- PROCESSING -----------------");
// GET FILE LIST & SET BATCH MODE
setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++) {
if (endsWith(list[i], ".tif")) { //list element + dataformat from formats array
print("Processing file "+list[i]);
decon(input, decondir, list[i]);
}
}
setBatchMode(false);
print(" ");
print("DONE!");
//--------------------------------FUNCTIONS-------------------------------------
function cleanup(){
run("Close All");
run("Clear Results");
call("java.lang.System.gc");
}
function decon(input, decondir, filename){
filepath = input + list[i];
filepath = replace(filepath,"\\","/");
PSFstr = " -psf file "+ PSFp;
image = " -image file " + filepath;
algorithm = " -algorithm "+ algo + " " + iter;
parameters = "";
run("DeconvolutionLab2 Run", image + PSFstr + algorithm + parameters);
run("16-bit");
deconimg = replace(list[i], ".tif", "");
saveAs("Tiff", decondir + deconimg + "DC" + algo + iter);
close();
cleanup();
}