10
10
11
11
import net .imagej .Dataset ;
12
12
import net .imagej .ImageJ ;
13
+ import net .imagej .ops .image .cooccurrenceMatrix .MatrixOrientation ;
14
+ import net .imagej .ops .image .cooccurrenceMatrix .MatrixOrientation2D ;
13
15
import net .imglib2 .IterableInterval ;
16
+ import net .imglib2 .RandomAccessibleInterval ;
14
17
import net .imglib2 .type .numeric .real .DoubleType ;
15
18
import net .imagej .plugins .commands .typechange .TypeChanger ;
16
19
@@ -19,36 +22,170 @@ public class Main {
19
22
public static void main (String [] args ) throws IOException {
20
23
ImageJ ij = new ImageJ ();
21
24
ModuleInfo module = ij .command ().getCommand (TypeChanger .class );
22
-
23
- File file = ij .ui ().chooseFile (null , "Open" );
24
- String fileName = file .getName ();
25
-
25
+ Dataset dataset ;
26
+ Map <String , Object > input ;
27
+
28
+ //File file = ij.ui().chooseFile(null, "Open");
29
+ File imgsPath = new File ("nodulo" );
30
+ String fileName = "" ;
31
+
26
32
PrintWriter pw = new PrintWriter (new File ("test.csv" ));
27
- StringBuilder sb = new StringBuilder ();
28
- sb .append ("magnitude" );
29
- sb .append ("," );
30
- sb .append ("label" );
31
- sb .append ("\n " );
32
-
33
- Dataset dataset = ij .scifio ().datasetIO ().open (file .getPath ());
34
- ij .ui ().show (dataset );
35
- Map <String , Object > input = new HashMap <String , Object >();
36
- input .put ("data" , dataset );
37
- input .put ("typeName" , "8-bit unsigned integer" );
38
- input .put ("combineChannels" , true );
39
- ij .module ().waitFor (ij .module ().run (module , true , input ));
40
-
41
- // ij.op().haralick, ij.op().zernike, ij.op().tamura, ij.op().stats estes são os descritores que possuem
42
- // os atributos
43
- DoubleType value = ij .op ().zernike ().magnitude ((IterableInterval <DoubleType >)dataset .getImgPlus (), 0 ,0 );
44
- sb .append (value );
45
- sb .append ("," );
46
- // maligno ou benigno
47
- sb .append (fileName .substring (fileName .lastIndexOf ("." ) - 1 , fileName .lastIndexOf ("." )));
48
- sb .append ("\n " );
49
-
50
- pw .write (sb .toString ());
51
- pw .close ();
52
- System .out .println (value );
33
+ pw .write ("kurtosis,maximum,minimum,mean,geometricMean,standardDeviation,skewness,variance,sum,sumOfSq,haralickContrastV,haralickEntropyV,haralickDiffEntropyV,haralickSumEntropyV,haralickVarianceV,haralickDiffVarianceV,haralickIcm2V,haralickContrastH,haralickEntropyH,haralickDiffEntropyH,haralickSumEntropyH,haralickVarianceH,haralickDiffVarianceH,haralickIcm2H,tamuraCoarseness,zernikeMagnitude,label\n " );
34
+
35
+ for (File file : imgsPath .listFiles ()) {
36
+ StringBuilder sb = new StringBuilder ();
37
+ fileName = file .getName ();
38
+
39
+ dataset = ij .scifio ().datasetIO ().open (file .getPath ());
40
+ //ij.ui().show(dataset);
41
+ input = new HashMap <String , Object >();
42
+ input .put ("data" , dataset );
43
+ input .put ("typeName" , "8-bit unsigned integer" );
44
+ input .put ("combineChannels" , true );
45
+ ij .module ().waitFor (ij .module ().run (module , true , input ));
46
+
47
+ // ij.op().haralick, ij.op().zernike, ij.op().tamura, ij.op().stats estes são os descritores que possuem
48
+ // os atributos
49
+
50
+ // Kurtosis
51
+ DoubleType value = ij .op ().stats ().kurtosis ((IterableInterval <DoubleType >)dataset .getImgPlus ());
52
+ sb .append (value );
53
+ sb .append ("," );
54
+
55
+ // Maximum
56
+ value = ij .op ().stats ().max ((IterableInterval <DoubleType >)dataset .getImgPlus ());
57
+ sb .append (value );
58
+ sb .append ("," );
59
+
60
+ // Minimum
61
+ value = ij .op ().stats ().min ((IterableInterval <DoubleType >)dataset .getImgPlus ());
62
+ sb .append (value );
63
+ sb .append ("," );
64
+
65
+ // Mean
66
+ value = ij .op ().stats ().mean ((IterableInterval <DoubleType >)dataset .getImgPlus ());
67
+ sb .append (value );
68
+ sb .append ("," );
69
+
70
+ // Geometric mean
71
+ value = ij .op ().stats ().geometricMean ((IterableInterval <DoubleType >)dataset .getImgPlus ());
72
+ sb .append (value );
73
+ sb .append ("," );
74
+
75
+ // Standard deviation
76
+ value = ij .op ().stats ().stdDev ((IterableInterval <DoubleType >)dataset .getImgPlus ());
77
+ sb .append (value );
78
+ sb .append ("," );
79
+
80
+ // Skewness
81
+ value = ij .op ().stats ().skewness ((IterableInterval <DoubleType >)dataset .getImgPlus ());
82
+ sb .append (value );
83
+ sb .append ("," );
84
+
85
+ // Variance
86
+ value = ij .op ().stats ().variance ((IterableInterval <DoubleType >)dataset .getImgPlus ());
87
+ sb .append (value );
88
+ sb .append ("," );
89
+
90
+ // Sum
91
+ value = ij .op ().stats ().sum ((IterableInterval <DoubleType >)dataset .getImgPlus ());
92
+ sb .append (value );
93
+ sb .append ("," );
94
+
95
+ // Sum of squares
96
+ value = ij .op ().stats ().sumOfSquares ((IterableInterval <DoubleType >)dataset .getImgPlus ());
97
+ sb .append (value );
98
+ sb .append ("," );
99
+
100
+ // Vertical contrast:
101
+ value = ij .op ().haralick ().contrast ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .VERTICAL );
102
+ sb .append (value );
103
+ sb .append ("," );
104
+
105
+ // Vertical entropy:
106
+ value = ij .op ().haralick ().entropy ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .VERTICAL );
107
+ sb .append (value );
108
+ sb .append ("," );
109
+
110
+ // Vertical difference Entropy:
111
+ value = ij .op ().haralick ().differenceEntropy ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .VERTICAL );
112
+ sb .append (value );
113
+ sb .append ("," );
114
+
115
+ // Vertical sum entropy:
116
+ value = ij .op ().haralick ().sumEntropy ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .VERTICAL );
117
+ sb .append (value );
118
+ sb .append ("," );
119
+
120
+ // Vertical variance:
121
+ value = ij .op ().haralick ().variance ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .VERTICAL );
122
+ sb .append (value );
123
+ sb .append ("," );
124
+
125
+ // Vertical difference variance:
126
+ value = ij .op ().haralick ().differenceVariance ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .VERTICAL );
127
+ sb .append (value );
128
+ sb .append ("," );
129
+
130
+ // Vertical icm2:
131
+ value = ij .op ().haralick ().icm2 ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .VERTICAL );
132
+ sb .append (value );
133
+ sb .append ("," );
134
+
135
+ // Horizontal contrast:
136
+ value = ij .op ().haralick ().contrast ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .HORIZONTAL );
137
+ sb .append (value );
138
+ sb .append ("," );
139
+
140
+ // Horizontal entropy:
141
+ value = ij .op ().haralick ().entropy ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .HORIZONTAL );
142
+ sb .append (value );
143
+ sb .append ("," );
144
+
145
+ // Horizontal difference Entropy:
146
+ value = ij .op ().haralick ().differenceEntropy ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .HORIZONTAL );
147
+ sb .append (value );
148
+ sb .append ("," );
149
+
150
+ // Horizontal sum entropy:
151
+ value = ij .op ().haralick ().sumEntropy ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .HORIZONTAL );
152
+ sb .append (value );
153
+ sb .append ("," );
154
+
155
+ // Horizontal variance:
156
+ value = ij .op ().haralick ().variance ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .HORIZONTAL );
157
+ sb .append (value );
158
+ sb .append ("," );
159
+
160
+ // Horizontal difference variance:
161
+ value = ij .op ().haralick ().differenceVariance ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .HORIZONTAL );
162
+ sb .append (value );
163
+ sb .append ("," );
164
+
165
+ // Horizontal icm2:
166
+ value = ij .op ().haralick ().icm2 ((IterableInterval <DoubleType >)dataset .getImgPlus (), 256 , 1 , MatrixOrientation2D .HORIZONTAL );
167
+ sb .append (value );
168
+ sb .append ("," );
169
+
170
+ // Coarseness:
171
+ value = ij .op ().tamura ().coarseness ((RandomAccessibleInterval <DoubleType >)dataset .getImgPlus ());
172
+ sb .append (value );
173
+ sb .append ("," );
174
+
175
+ // Magnitude:
176
+ value = ij .op ().zernike ().magnitude ((IterableInterval <DoubleType >)dataset .getImgPlus (), 0 , 0 );
177
+ sb .append (value );
178
+ sb .append ("," );
179
+
180
+ // Maligno ou benigno:
181
+ sb .append (fileName .substring (fileName .lastIndexOf ("." ) - 1 , fileName .lastIndexOf ("." )));
182
+ sb .append ("\n " );
183
+
184
+ pw .write (sb .toString ());
185
+
186
+ System .out .println (fileName );
187
+ }
188
+
189
+ pw .close ();
53
190
}
54
191
}
0 commit comments