-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParticleArea.ijm
74 lines (68 loc) · 2.83 KB
/
ParticleArea.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
//Macro by Félix de Carpentier, 2020, CNRS / Sorbonne University / Paris-Saclay University, France
//Inspired by Will Armour, 2018 (https://willarmour.science/how-to-automate-image-particle-analysis-by-creating-a-macro-in-imagej/)
//Allows the user to choose the folder containing the images and the folder for the results
inputFolder=getDirectory("Choose input folder");
outputFolder=getDirectory("Choose output folder for the results");
Dialog.create("Options");
Dialog.addNumber("Distance in pixels", 2.85);
Dialog.addNumber("Known distance", 1);
Dialog.addCheckbox("Activate Watershed", false);
Dialog.show();
disPix = Dialog.getNumber();
disKnown = Dialog.getNumber();
watershed = Dialog.getCheckbox();
watershedLabel = "";
if(watershed!=false) watershedLabel="_ws";
//Puts the name of the files in a list
list=getFileList(inputFolder);
//In batch mode the windows are not shown so it is faster.
setBatchMode(true);
run("Set Measurements...", "area mean perimeter shape limit redirect=None decimal=4");
run("Clear Results");
for(i=0; i<list.length; i++) {
//Open the images
loc=inputFolder+list[i];
//if(endsWith(loc, ".jpg"))
open(loc);
print(loc); //I don't know why but it doesn't work without printing the value of loc
run("Set Scale...", "distance="+disPix+" known="+disKnown+" unit=µm");
//Processes of the image to measure the area of each particle and add an overlay
if(nImages>=1) {
outputPath=outputFolder+list[i];
//The following two lines removes the file extension
fileExtension=lastIndexOf(outputPath,".");
if(fileExtension!=-1) outputPath=substring(outputPath,0,fileExtension);
currentNResults = nResults;
run("Duplicate...", " ");
//run("8-bit"); //Convert to black and white
run("RGB Stack");
//run("Delete Slice");
//run("Delete Slice");
run("Slice Remover", "first=1 last=2 increment=1"); //Select de desired channel, for R: 2;3;1 / G: 1;3;2 /B: 1;2;1
run("Gaussian Blur...", "sigma=2"); //Blur the particles to be sure to select the objects and not the sub-objects
setAutoThreshold("Default");
run("Convert to Mask");
run("Close");
if(watershed!=false) run("Watershed");
run("Fill Holes");
run("Analyze Particles...","size=0-Infinity add display");
for (row = currentNResults; row < nResults; row++) //This add the file name in a row
{
setResult("Label", row, list[i]);
}
selectWindow(list[i]);
roiManager("Show All without labels"); //transfer the label from the bw image to color image
roiManager("Set Color", "red");
roiManager("Set Line Width", 2);
run("Flatten");
roiManager("Delete");
saveAs("Jpeg", outputPath+ watershedLabel+ ".jpg");
close("*");
}
showProgress(i, list.length); //Shows a progress bar
}
setOption("ShowRowNumbers", false);
saveAs("results", outputFolder+ "results"+ watershedLabel+ ".csv");
selectWindow("Results");
run("Close");
setBatchMode(false);