Bonjour à tous,
Voilà mon problème, dans le cadre d'un projet à la fac j'ai du transformer une macro en plug-in ce que (débutant en java) j'ai plus ou moins réussis à faire :
code de la macro :
code de mon plug-in :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
158
159
160
161
162
163
164
165
166
167 ////////////////////////////////////////////////////////////////////////////////// // // // Macro for Marion // // // ////////////////////////////////////////////////////////////////////////////////// /// ////////////////////////////////////////////////////////////////////////////////// // Open image ////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// setBatchMode(true); // Controls whether images are visible or hidden during macro execution. arg is 'true', the interpreter enters batch mode and newly opened images are not displayed. open(); //open() fonction with no arg : opening of a windows in order to choose a image. dir = getInfo("image.directory"); //Returns the directory that the current image was loaded from, or an empty string if the directory is not available. //print(dir); //name=getInfo("image.filename"); //print(name); images = getFileList(dir); //returns the names of the images which are in the folder tailleTableau = lengthOf(images); //lengthOf : return the number of the image in tailleTableau for (i=0; i< images.length/*tailleTableau-1*/; i++) { //de i=0 à 1<tailleTableau-1 with i++. tailleTableau-1 because index 0 at the beginning of the array nom = getInfo("image.filename"); //return the file name in "nom" ////////////////////////////////////////////////////////////////////////////////// // Create Folders ////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// tmp = dir; //"dir" is put in tempory variable "tmp" if (tmp=="") //if tmp correspond to an empty string { exit("No temp directory available"); } newDir = tmp+"Analyse"+File.separator; //creation of a new folder path : tmp+Analyse+"\" File.makeDirectory(newDir); //creation of the folder Analyse if (!File.exists(newDir)) //if folder does'nt exist { exit("Unable to create directory"); //end of the macro } ////////////////////////////////////////////////////////////////////////////////// tmpO = dir+"Analyse"+File.separator; //"dir+Analyse+File.separator" is put in tempory variable "tmpO" if (tmpO=="") //if tmpO correspond to an empty string { exit("No temp directory available");//end of the macro } newDirE = tmpO+"Images"+File.separator; File.makeDirectory(newDirE);//creation of the folder Image in the folder Analyse if (!File.exists(newDirE))//if folder does'nt exist { exit("Unable to create directory");//end of the macro } ////////////////////////////////////////////////////////////////////////////////// tmpOr = dir+"Analyse"+File.separator;//"dir+Analyse+File.separator" is put in tempory variable "tmpOr" if (tmpOr=="")//if tmpOr correspond to an empty string { exit("No temp directory available");//end of the macro } newDirEc = tmpOr+"Results"+File.separator; File.makeDirectory(newDirEc);//creation of the folder Result in the folder Analyse if (!File.exists(newDirEc))//if folder does'nt exist { exit("Unable to create directory");//end of the macro } ////////////////////////////////////////////////////////////////////////////////// directoryI = dir+"Analyse"+File.separator+"Images"+File.separator; //in directoryI = path of Image folder directoryR = dir+"Analyse"+File.separator+"Results"+File.separator; //in directoryR = path of Result folder ////////////////////////////////////////////////////////////////////////////////// // Split and Close Channels ////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// run("Split Channels"); //spliting of the R G B channels colorRed =nom+" (red)"; selectWindow(colorRed); close(); //closing the red channel colorBlue =nom+" (blue)"; selectWindow(colorBlue); close(); //closing the blue channel run("Green"); //just green channel will be used indexGreen =" (green).tif"; saveAs("Tiff", ""+directoryI+""+nom+""+indexGreen+""); //saving green image in directoryI ////////////////////////////////////////////////////////////////////////////////// // Calibrate ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// run("Properties...", "channels=1 slices=1 frames=1 unit=¬µm pixel_width=0.4857143 pixel_height=0.4857143 voxel_depth=0 frame=[0 sec] origin=0,0"); ////////////////////////////////////////////////////////////////////////////////// // Tubeness ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// //tubeness treatment on green channel image run("Tubeness", "sigma=5 use"); indexT ="-01-Tubeness.tif"; saveAs("Tiff", ""+directoryI+""+nom+""+indexT+""); //creation of transitional image which was treated by tubeness. Saving in directoryI ////////////////////////////////////////////////////////////////////////////////// // Binary ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// //binary treatment on the image which was treated by tubeness run("Make Binary"); indexTB ="-02-TubenessBinarise.tif"; saveAs("Tiff", ""+directoryI+""+nom+""+indexTB+""); //Creation of transitional image wich was treated by binary. Saving in directoryI ////////////////////////////////////////////////////////////////////////////////// // Skeletonize ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// //Skeletonize treatment on the image which was treated by tubeness and binary previously run("Skeletonize (2D/3D)"); indexSkel ="-03-Skeleton.tif"; saveAs("Tiff", ""+directoryI+""+nom+""+indexSkel+"");//Creation of transitional image wich was treated by binary. Saving in directoryI ///At this stage 4 news images was normaly created ////////////////////////////////////////////////////////////////////////////////// // Analyze Skeleton ////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// //binary treatment on the image which was treated by tubeness, binary and skeletonized previously run("Analyze Skeleton (2D/3D)", "prune=none calculate show"); selectWindow("Longest shortest paths"); indexLSP ="-04-LSP.tif"; saveAs("Tiff", ""+directoryI+""+nom+""+indexLSP+""); //creation of transitional Longest Shortest paths image which was analized by Analyze Skeleton. Saving in directoryI close(); selectWindow("Tagged skeleton"); indexTS ="-05-TS.tif"; saveAs("Tiff", ""+directoryI+""+nom+""+indexTS+"");//creation of transitional Tagged skeleton image which was analized by Analyze Skeleton. Saving in directoryI close(); ResultLSP ="-01-ResultLSP.xls"; saveAs("Results", ""+directoryR+""+nom+""+ResultLSP+""); //creation of result Longest Shortest paths xls which was analized by Analyze Skeleton. Saving in directoryR run("Close"); ResultBI ="-02-ResultBI.xls"; saveAs("Results", ""+directoryR+""+nom+""+ResultBI+""); //creation of transitional BI xls which was analized by Analyze Skeleton. Saving in directoryR run("Clear Results"); run("Close"); ////////////////////////////////////////////////////////////////////////////////// // Analyze Particles ////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// Image =dir+nom; open(Image); run("Split Channels"); colorRed =nom+" (red)"; selectWindow(colorRed); close(); colorBlue =nom+" (blue)"; selectWindow(colorBlue); close(); run("Green"); run("Properties...", "channels=1 slices=1 frames=1 unit=¬µm pixel_width=0.4857143 pixel_height=0.4857143 voxel_depth=0 frame=[0 sec] origin=0,0"); run("Tubeness", "sigma=5 use"); run("Make Binary"); run("Set Measurements...", "area mean standard min display redirect=None decimal=3"); run("Analyze Particles...", "size=0,2359184 circularity=0.00-1.00 show=Outlines display clear record add"); indexAP ="-06-AP.tif"; saveAs("Tiff", ""+directoryI+""+nom+""+indexAP+""); ResultAP ="-03-ResultAP.xls"; saveAs("Results", ""+directoryR+""+nom+""+ResultAP+""); run("Close"); // fin boucle } ////////////////////////////////////////////////////////////////////////////////// // End of Macro ////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
Sauf que un problème reste et ça m'embête dans la macro il y a un setBatchMode=True, qui permet déjà un traitement de 10 sec/image en moyenne. Avec mon plug-in j'augmente la vitesse de traitement tout en affichant les images d'un facteur 2 ! alors j'imagine qu'en n'affichant pas toutes ces fenêtres ça irait encore plus vite !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295 import ij.*; /*import ij.process.*; import ij.gui.*;*/ import ij.plugin.*; /*import ij.plugin.filter.*; import ij.plugin.tool.*; import ij.plugin.frame.*; import ij.macro.*; import ij.ImagePlus.*; //import ij.ImageStack.*;*/ /*import java.*; import java.lang.*; import java.nio.file.Path; import java.awt.*;*/ import java.io.*; /*import java.util.*; import javax.imageio.spi.ImageReaderSpi;*/ import javax.swing.JOptionPane; /** * * @author */ public class CapillaryCaracterization_ implements PlugIn { public void run(String arg) { ////////////////////////////////////////////////////////////////////////////////// ///Starting up of the plug-in /// ////////////////////////////////////////////////////////////////////////////////// //Image opening and folder informations recovering //Open dialog box to choose an image and get the absolute path of the image in order to get the path of the folder String path = IJ.getFilePath("image"); System.out.println("path = "+path+"\n"); if ( path == null) { path = IJ.getFilePath("image"); } //Get in dir the path of the folder of the image String dir = IJ.getDirectory("current"); System.out.println("directory = "+dir+"\n"); //In the loop ! It's Go !! File path_img_list = new File(dir); File[] listOfFiles = path_img_list.listFiles(); String[] choices = { "red", "green", "blue" }; String channel = (String) JOptionPane.showInputDialog (null, "Color of your probe ?", "Choose channel", JOptionPane.QUESTION_MESSAGE, null,choices,choices[1]); String channelUpperCase=channel.substring(0, 1) .toUpperCase() + channel.substring(1); IJ.open(path); ImagePlus imp = IJ.getImage(); Double pixelW = imp.getCalibration().pixelWidth; Double pixelH= imp.getCalibration().pixelHeight; System.out.println("largeur métadata = "+pixelW); System.out.println("longueur métadata = "+pixelH); String pixel = JOptionPane.showInputDialog("If your image is already calibrated,\nplease enter this value : "+pixelW +"\n\nelse enter your own value to calibrate your images"); //String element = JOptionPane.showInputDialog("Size of structuring element?"); double pixel_width = Double.parseDouble(pixel); double pixel_height = Double.parseDouble(pixel); //double struc_element = Double.parseDouble(element); IJ.run("Close All"); ////////////////////////////////////////////////////////////////////////////////// ///Creation of folders /// ////////////////////////////////////////////////////////////////////////////////// //Folder Analyze, Images and Results String newDir_A_I = dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator; String newDir_A_R = dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Results"+File.separator; new File(newDir_A_I).mkdirs(); new File(newDir_A_R).mkdirs(); ///*********************************************************************************************************************************************************************/// /// Image Processing /// ///*********************************************************************************************************************************************************************/// for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { @SuppressWarnings("unused") int index = -1; String name = (listOfFiles[i].getName() != null) ? ((index = listOfFiles[i].getName().lastIndexOf(".")) == -1) ? listOfFiles[i].getName() : listOfFiles[i].getName().substring(0,listOfFiles[i].getName().lastIndexOf('.')) : ""; System.out.println("File n°"+ i +" = " + name); //Get the name of the image with ".extension" String name_ext = listOfFiles[i].getName(); System.out.println("name.tiff = "+name_ext+"\n"); //Construction of the path of the image which will be treated String tmp_path = dir+name_ext; System.out.println("tmp_path = "+tmp_path+"\n"); IJ.open(tmp_path); ////////////////////////////////////////////////////////////////////////////////// ///Splitting in RGB channel and closing color channels which we don't study /// ////////////////////////////////////////////////////////////////////////////////// IJ.run("Split Channels"); for (int j = 0; j < choices.length; j++) { if(channel!=choices[j]){ String Color = name_ext+" ("+choices[j]+")"; IJ.selectWindow(Color); IJ.run("Close"); } else { String Color = name_ext+" ("+channel+")"; IJ.selectWindow(Color); String index_C ="_("+channel+")"; System.out.println(dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_C); IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_C); } } //1st image created ////////////////////////////////////////////////////////////////////////////////// ///Calibration /// ////////////////////////////////////////////////////////////////////////////////// //Setting up of the properties of the images IJ.run("Properties...", "channels=1 slices=1 frames=1 unit=¬µm pixel_width="+pixel_width+" pixel_height="+pixel_height+" voxel_depth=0 frame=[0 sec] origin=0,0"); ////////////////////////////////////////////////////////////////////////////////// ///Tubeness /// ////////////////////////////////////////////////////////////////////////////////// IJ.run("Tubeness", "sigma=5"); String index_T="-01-Tubeness.tif"; IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_T); //2nd image created ////////////////////////////////////////////////////////////////////////////////// ///Binary /// ////////////////////////////////////////////////////////////////////////////////// IJ.run("Make Binary"); String index_TB="-02-TubenessBinaries.tif"; IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+""+name+""+index_TB); //3th image created ////////////////////////////////////////////////////////////////////////////////// ///Skeletonize /// ////////////////////////////////////////////////////////////////////////////////// IJ.run("Skeletonize (2D/3D)", ""); String index_skel="-03-skeleton.tif"; IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_skel); //4th image created ////////////////////////////////////////////////////////////////////////////////// ///Analyze Skeleton /// ////////////////////////////////////////////////////////////////////////////////// IJ.run("Analyze Skeleton (2D/3D)", "prune=none calculate show"); IJ.selectWindow("Longest shortest paths"); String index_LSP="-04-LSP.tif"; IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_LSP); //5th image created IJ.run("Close"); IJ.selectWindow("Tagged skeleton"); String index_TS="-05-TS.tif"; IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_TS); IJ.run("Close"); //6th images created String Result_LSP ="-01-ResultLSP.xls"; IJ.saveAs("Results",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Results"+File.separator+name+Result_LSP); IJ.run("Close"); //1st file of results created String Result_BI ="-02-ResultBI.xls"; //IJ.saveAs("Results", ""+Dir_A_R+""+name+""+Result_BI+""); IJ.saveAs("Results",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Results"+File.separator+name+Result_BI); IJ.run("Clear Results"); IJ.run("Close"); //2nd file of results created ////////////////////////////////////////////////////////////////////////////////// ///Analyze Particles /// ////////////////////////////////////////////////////////////////////////////////// /*Re-opening of the image in order to analyze the particles * the image need to be treated a second time with Tubeness, Make Binary. */ IJ.open(tmp_path); System.out.println("path 2nde partie = "+tmp_path); IJ.run("Split Channels"); for (int k = 0; k < choices.length; k++) { if(channel!=choices[k]) { String Color = name_ext+" ("+choices[k]+")"; IJ.selectWindow(Color); IJ.run("Close"); } else { String Color = name_ext+" ("+channel+")"; IJ.selectWindow(Color); String index_C="_("+channel+")"; System.out.println(dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_C); IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Images"+File.separator+name+index_C); } } IJ.run("Properties...", "channels=1 slices=1 frames=1 unit=¬µm pixel_width="+pixel_width+" pixel_height="+pixel_height+" voxel_depth=0 frame=[0 sec] origin=0,0"); System.out.println("taille pixel = "+pixel_width); IJ.run("Tubeness", "sigma=5 use"); IJ.run("Make Binary", ""); IJ.run("Set Measurements...", "area mean standard min display redirect=None decimal=3"); //////////size of structuring element modification ? IJ.run("Analyze Particles...", "size=0,2359184 circularity=0.00-1.00 show=Outlines display clear record add"); String index_AP ="-06-AP.tif"; IJ.saveAs("Tiff",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Results"+File.separator+name+index_AP); String Result_AP ="-03-ResultAP.xls"; IJ.saveAs("Results",dir+"Analyze"+File.separator+channelUpperCase+File.separator+"Results"+File.separator+name+Result_AP); //3rd file of results created IJ.run("Close"); IJ.run("Close All"); IJ.selectWindow("ROI Manager"); IJ.run("Close"); IJ.selectWindow("Results"); IJ.run("Close"); } } } }
Mais je ne trouve pas de solution (j'avais pensais à ImagePlus.hide() mais si c'est ça je ne trouve pas où le mettre)
Pour info il n'y a pas de tricherie quelconque j'ai soutenu aujourd'hui mon rapport de projet tuteuré mais j'ai le goût du travail bien fait =D
Merci d'avance à qui pourra m'aider
Loy0
Partager