-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubtract-two-images-and-analyse-difference.ijm
65 lines (48 loc) · 2.14 KB
/
subtract-two-images-and-analyse-difference.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
/*
Author: Alessandro Felder, RVC, London
basic frame work that allows to (re-)analyse all tiff images in one directory with the same input suffix.
if offers the possibility to import a previous ROI
inputs: directory to analyse
output directory
input suffix
input roi suffix
output roi suffix
idea is to be easily repeatable and modular with respect to various area measurements and counts of interest.
*/
run("Close All");
roiManager("reset");
setOption("Show All", true);
run("Set Measurements...", "area mean standard median area_fraction limit redirect=None decimal=5");
minuend_image_dir = getDirectory("Choose an input minuend image directory");
subtrahend_image_dir = getDirectory("Choose an input subtrahend image directory");
difference_image_dir = getDirectory("Choose an output difference image directory");
minuend_suffix = getString("Choose an input minuend suffix", "");
subtrahend_suffix = getString("Choose an input subtrahend suffix","");
difference_suffix = getString("Choose an output difference suffix", "");
minuend_files = getFileList(minuend_image_dir);
subtrahend_files = getFileList(subtrahend_image_dir);
//check all files are present
if(!(minuend_files.length==subtrahend_files.length)){
print("length of file lists do not match: "+minuend_files.length+" v "+subtrahend_files.length+". Aborting.");
return;
}
for(i=0; i<minuend_files.length; i++) {
if(!endsWith(minuend_files[i], minuend_suffix+"-binary.tif")) {
continue;
}
if(!endsWith(subtrahend_files[i], subtrahend_suffix+"-binary.tif")) {
continue;
}
open(minuend_image_dir+minuend_files[i]);
open(subtrahend_image_dir+subtrahend_files[i]);
imageCalculator("Subtract create", minuend_files[i],subtrahend_files[i]);
selectWindow("Result of "+minuend_files[i]);
difference_name = replace(minuend_files[i],minuend_suffix,difference_suffix);
saveAs(difference_image_dir+difference_name);
//analyse and save
run("Analyze Particles...", "size=0.0001-Infinity show=Nothing display exclude clear summarize");
close();
if(isOpen("Results")) selectWindow("Results");
saveAs("Results", difference_image_dir+replace(difference_name,".tif","")+".csv");
run("Close All");
}