-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.preprocessing_batch.ijm
63 lines (51 loc) · 2.55 KB
/
2.preprocessing_batch.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
// Michael Savage 11/01/2015
//This macro runs batch preanaylsis for tracing pictures
// Includes Gaussian blur and split&separation of colour channels and saving
macro "Preprocessing FITC... " {
// These options need personalised for individual data sets
fileIdentifier = ").TIF";
fileIdentifier_2 = ").tif"; // ImageJ treats capitalised and non-capitalised letters differently
dir = getDirectory("Choose a Directory for Preprocessing");
//dir_2 = getDirectory("Choose a Directory for Saving Files");
setBatchMode(true);
list = getFileList(dir); // Gets a file list from directory
for (i = 0; i < list.length; i++)
{
batchPreproccessing(dir, dir, list[i]); // Runs through the file list
//batchPreproccessing(dir, dir_2, list[i]); // Uncomment this and comment out the above statement if input and output directories are different
}
setBatchMode(false);
function batchPreproccessing(input, output, filename)
{
if (endsWith(filename, fileIdentifier)==1 || endsWith(filename, fileIdentifier_2)==1 ) // Filtering options, in this case only processes images with the 'fileIdentifier' string at the end of the filename
{
open(input + filename);
if (bitDepth() != 8) // does not process grayscaled images
{
run("Set Scale...", "distance=617 known=200 pixel=1 unit=um"); // You may or may not want to properly set the scales for the images (distance in pixels, known distance in real life, pixel aspect ratio (1), unit of length (see macro website for ImageJ)
run("Gaussian Blur...", "sigma=1.5"); // may need to change sigma size to get the right level of filtering of artefacts
run("Split Channels"); // Splits channels into red, green, blue and grayscales them
selectImage("C1-"+filename);
close(); // deletes red channel
selectImage("C3-"+filename);
close(); // deletes blue channel, may need to personalise for dataset
run("8-bit");
run("8-bit");
if (endsWith(filename, "TIF")==1 || endsWith(filename, "tif") == 1 ) // if filename ends in 'TIF' or 'tif' savers files as .tif. otherwise saves as .jpeg
{
saveAs("tiff", output +filename +"_gray");
}
else
{
saveAs("jpeg", output +filename +"_gray");
}
print(filename +" has been processed and saved"); // outputs current image name and that is has been processed succesfully
call("java.lang.System.gc"); // cleans up memory used, this script may fail if ImageJ uses all the RAM in computer. ImageJ is not very efficient at releasing unused RAM
}
else
{
print(filename +" has NOT been processed as has already been grayscaled");
close();
}
}
}