Newer
Older
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//This macro for ImageJ find the geen leaves of grapevine on a blue Background;
//Éric Duchêne, 2012, eric.duchene@inrae.fr;
//Reference: Duchêne E, Dumas V, Jaegli N, Merdinoglu D. 2012. Deciphering the ability of different grapevine genotypes to accumulate sugar in berries. Australian Journal of Grape and Wine Research 18(3): 319-328;
//Update (English version) August 2023;
//The output in an Excel files with the mean grey of each image;
//How to use this macro in ImageJ?
//Select "Plugins/Macros/Install" in the ImageJ menu and choose this macro;
//Select the directory with the images to process in "Plugins/Macros/Directory and Parameters" (or "alt-d" on MacOS);
//Start to analyze the images with "Plugins/Macros/Foliage coverage" (or "alt-c" on MacOS);
//General variables
var imagesDir="";
var resultsDir;
var tempDir;
var Rfile;
var list;
var Titre;
var TimeString;
setKeyDown("esc");
//This function records the results and delete intermediate files;
function CleanFiles(tempDir,resultsDir,Rfile) {
saveAs("measurements",resultsDir+Rfile+".xls");
if(nImages>0) run("Close All");
ListTemp=getFileList(tempDir);
for(i=0;i<lengthOf(ListTemp);i++) File.delete(tempDir+ListTemp[i]);
File.delete(substring(tempDir,0,lengthOf(tempDir)-1));
roiManager("Reset");
run("Clear Results");
}
macro "directory and parameters [d]"
{
print("\\Clear");
imagesDir=getDirectory("");
print("Working directory: "+imagesDir);
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
TimeString ="Date: "+dayOfMonth+"/"+month+1+"/"+year;
print(TimeString);
list=getFileList(imagesDir);
//Create a subdirectory for the results;
resultsDir=imagesDir+"resultsS/";
File.makeDirectory(resultsDir);
print("Results in "+resultsDir);
//Create a subdirectory for temporary files;
tempDir=imagesDir+"temp/";
File.makeDirectory(tempDir);
print("Tampon: "+tempDir);
run("Clear Results");
roiManager("Reset");
Dialog.create("File with the results");
Dialog.addMessage("Provide a name for the file with the results");
Dialog.addString("Nom", "Results");
Dialog.show();
Method= Dialog.getChoice();
//PhotoType=Dialog.getChoice();
Rfile=Dialog.getString();
run("Set Measurements...", "area mean center of mass redirect=None decimal=1");
if(nImages>0) run("Close All");
run("Colors...", "foreground=black background=white selection=yellow");
run("Options...", "iterations=1 count=1 edm=Overwrite");
print ("Fichier de résultat: "+Rfile);
print ("# Settings OK #");
}
macro "Foliage coverage [c]" {
if (imagesDir=="") {
showMessage("Choose a working directory then open an image");
print("\\Clear");
imagesDir=getDirectory("");
print("Working directory "+imagesDir);
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
TimeString ="Date: "+dayOfMonth+"/"+month+1+"/"+year;
print(TimeString);
list=getFileList(imagesDir);
//Create a subdirectory for the results;
resultsDir=imagesDir+"resultsS/";
File.makeDirectory(resultsDir);
print("Results in "+resultsDir);
//Create a subdirectory for temporary files;
tempDir=imagesDir+"temp/";
File.makeDirectory(tempDir);
print("Tampon: "+tempDir);
run("Clear Results");
roiManager("Reset");
Dialog.create("Question");
Dialog.addMessage("Name of the results file")
Dialog.addString("Nom", "Results");
Dialog.show();
Method= Dialog.getChoice();
//PhotoType=Dialog.getChoice();
Rfile=Dialog.getString();
run("Set Measurements...", "area mean center of mass redirect=None decimal=1");
if(nImages>0) run("Close All");
run("Colors...", "foreground=black background=white selection=yellow");
run("Options...", "iterations=1 count=1 edm=Overwrite");
print ("# Settings OK #");
}
do
{
if(nImages==0) {
//showMessage("Open an image");
open();
}
if(selectionType==-1) {
makeRectangle(280, 0, 954, getHeight());
ROI_Ok=getBoolean("Modify the region of interest?");
if (ROI_Ok==1) exit();
}
roiManager("reset");
if(selectionType!=-1) run("Crop");
Titre=getTitle()+"_";
saveAs("Tiff", tempDir+"IMGWo.tif");
run("Brightness/Contrast...");
run("Enhance Contrast", "saturated=0.8");
run("Split Channels");
imageCalculator("Subtract", "IMGWo.tif (green)","IMGWo.tif (blue)");
//run("Image Calculator...", "image1=[IMGWo.tif (green)] operation=Subtract image2=[IMGWo.tif (blue)] create");
run("Set Measurements...", "area mean area_fraction display redirect=None decimal=3");
selectWindow("IMGWo.tif (red)");
close();
selectWindow("IMGWo.tif (blue)");
close();
saveAs("Tiff", tempDir+Titre);
setAutoThreshold();
setThreshold(20, 255);
run("Measure");
//run("Convert to Mask");
run("Create Selection");
roiManager("Add");
roiManager("Deselect");
run("Select None");
close();
File.delete(tempDir+Titre);
open(tempDir+"IMGWo.tif");
selectWindow("IMGWo.tif");
setOption("Show All",true);
Continuer=getBoolean("Continue with another image?");
close();
File.delete(tempDir+"IMGWo.tif");
} while (Continuer==1);
showMessage("Results are in the directory "+ resultsDir);
CleanFiles(tempDir,resultsDir,Rfile);
imagesDir="";
}