mediml 0.9.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. MEDiml/MEDscan.py +1696 -0
  2. MEDiml/__init__.py +21 -0
  3. MEDiml/biomarkers/BatchExtractor.py +806 -0
  4. MEDiml/biomarkers/BatchExtractorTexturalFilters.py +840 -0
  5. MEDiml/biomarkers/__init__.py +16 -0
  6. MEDiml/biomarkers/diagnostics.py +125 -0
  7. MEDiml/biomarkers/get_oriented_bound_box.py +158 -0
  8. MEDiml/biomarkers/glcm.py +1602 -0
  9. MEDiml/biomarkers/gldzm.py +523 -0
  10. MEDiml/biomarkers/glrlm.py +1315 -0
  11. MEDiml/biomarkers/glszm.py +555 -0
  12. MEDiml/biomarkers/int_vol_hist.py +527 -0
  13. MEDiml/biomarkers/intensity_histogram.py +615 -0
  14. MEDiml/biomarkers/local_intensity.py +89 -0
  15. MEDiml/biomarkers/morph.py +1756 -0
  16. MEDiml/biomarkers/ngldm.py +780 -0
  17. MEDiml/biomarkers/ngtdm.py +414 -0
  18. MEDiml/biomarkers/stats.py +373 -0
  19. MEDiml/biomarkers/utils.py +389 -0
  20. MEDiml/filters/TexturalFilter.py +299 -0
  21. MEDiml/filters/__init__.py +9 -0
  22. MEDiml/filters/apply_filter.py +134 -0
  23. MEDiml/filters/gabor.py +215 -0
  24. MEDiml/filters/laws.py +283 -0
  25. MEDiml/filters/log.py +147 -0
  26. MEDiml/filters/mean.py +121 -0
  27. MEDiml/filters/textural_filters_kernels.py +1738 -0
  28. MEDiml/filters/utils.py +107 -0
  29. MEDiml/filters/wavelet.py +237 -0
  30. MEDiml/learning/DataCleaner.py +198 -0
  31. MEDiml/learning/DesignExperiment.py +480 -0
  32. MEDiml/learning/FSR.py +667 -0
  33. MEDiml/learning/Normalization.py +112 -0
  34. MEDiml/learning/RadiomicsLearner.py +714 -0
  35. MEDiml/learning/Results.py +2237 -0
  36. MEDiml/learning/Stats.py +694 -0
  37. MEDiml/learning/__init__.py +10 -0
  38. MEDiml/learning/cleaning_utils.py +107 -0
  39. MEDiml/learning/ml_utils.py +1015 -0
  40. MEDiml/processing/__init__.py +6 -0
  41. MEDiml/processing/compute_suv_map.py +121 -0
  42. MEDiml/processing/discretisation.py +149 -0
  43. MEDiml/processing/interpolation.py +275 -0
  44. MEDiml/processing/resegmentation.py +66 -0
  45. MEDiml/processing/segmentation.py +912 -0
  46. MEDiml/utils/__init__.py +25 -0
  47. MEDiml/utils/batch_patients.py +45 -0
  48. MEDiml/utils/create_radiomics_table.py +131 -0
  49. MEDiml/utils/data_frame_export.py +42 -0
  50. MEDiml/utils/find_process_names.py +16 -0
  51. MEDiml/utils/get_file_paths.py +34 -0
  52. MEDiml/utils/get_full_rad_names.py +21 -0
  53. MEDiml/utils/get_institutions_from_ids.py +16 -0
  54. MEDiml/utils/get_patient_id_from_scan_name.py +22 -0
  55. MEDiml/utils/get_patient_names.py +26 -0
  56. MEDiml/utils/get_radiomic_names.py +27 -0
  57. MEDiml/utils/get_scan_name_from_rad_name.py +22 -0
  58. MEDiml/utils/image_reader_SITK.py +37 -0
  59. MEDiml/utils/image_volume_obj.py +22 -0
  60. MEDiml/utils/imref.py +340 -0
  61. MEDiml/utils/initialize_features_names.py +62 -0
  62. MEDiml/utils/inpolygon.py +159 -0
  63. MEDiml/utils/interp3.py +43 -0
  64. MEDiml/utils/json_utils.py +78 -0
  65. MEDiml/utils/mode.py +31 -0
  66. MEDiml/utils/parse_contour_string.py +58 -0
  67. MEDiml/utils/save_MEDscan.py +30 -0
  68. MEDiml/utils/strfind.py +32 -0
  69. MEDiml/utils/textureTools.py +188 -0
  70. MEDiml/utils/texture_features_names.py +115 -0
  71. MEDiml/utils/write_radiomics_csv.py +47 -0
  72. MEDiml/wrangling/DataManager.py +1724 -0
  73. MEDiml/wrangling/ProcessDICOM.py +512 -0
  74. MEDiml/wrangling/__init__.py +3 -0
  75. mediml-0.9.9.dist-info/LICENSE.md +674 -0
  76. mediml-0.9.9.dist-info/METADATA +232 -0
  77. mediml-0.9.9.dist-info/RECORD +78 -0
  78. mediml-0.9.9.dist-info/WHEEL +4 -0
@@ -0,0 +1,373 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import numpy as np
5
+ from scipy.stats import iqr, kurtosis, skew, scoreatpercentile, variation
6
+
7
+
8
+ def extract_all(vol: np.ndarray, intensity_type: str) -> dict:
9
+ """Computes Intensity-based statistical features.
10
+ These features refer to "Intensity-based statistical features" (ID = UHIW) in
11
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
12
+
13
+ Args:
14
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
15
+ (continuous imaging intensity distribution).
16
+ intensity_type (str): Type of intensity to compute. Can be "arbitrary", "definite" or "filtered".
17
+ Will compute features only for "definite" intensity type.
18
+
19
+ Return:
20
+ dict: Dictionnary containing all stats features.
21
+
22
+ Raises:
23
+ ValueError: If `intensity_type` is not "arbitrary", "definite" or "filtered".
24
+ """
25
+ assert intensity_type in ["arbitrary", "definite", "filtered"], \
26
+ "intensity_type must be 'arbitrary', 'definite' or 'filtered'"
27
+
28
+ x = vol[~np.isnan(vol[:])] # Initialization
29
+
30
+ # Initialization of final structure (Dictionary) containing all features.
31
+ stats = {'Fstat_mean': [],
32
+ 'Fstat_var': [],
33
+ 'Fstat_skew': [],
34
+ 'Fstat_kurt': [],
35
+ 'Fstat_median': [],
36
+ 'Fstat_min': [],
37
+ 'Fstat_P10': [],
38
+ 'Fstat_P90': [],
39
+ 'Fstat_max': [],
40
+ 'Fstat_iqr': [],
41
+ 'Fstat_range': [],
42
+ 'Fstat_mad': [],
43
+ 'Fstat_rmad': [],
44
+ 'Fstat_medad': [],
45
+ 'Fstat_cov': [],
46
+ 'Fstat_qcod': [],
47
+ 'Fstat_energy': [],
48
+ 'Fstat_rms': []
49
+ }
50
+
51
+ # STARTING COMPUTATION
52
+ if intensity_type == "definite":
53
+ stats['Fstat_mean'] = np.mean(x) # Mean
54
+ stats['Fstat_var'] = np.var(x) # Variance
55
+ stats['Fstat_skew'] = skew(x) # Skewness
56
+ stats['Fstat_kurt'] = kurtosis(x) # Kurtosis
57
+ stats['Fstat_median'] = np.median(x) # Median
58
+ stats['Fstat_min'] = np.min(x) # Minimum grey level
59
+ stats['Fstat_P10'] = scoreatpercentile(x, 10) # 10th percentile
60
+ stats['Fstat_P90'] = scoreatpercentile(x, 90) # 90th percentile
61
+ stats['Fstat_max'] = np.max(x) # Maximum grey level
62
+ stats['Fstat_iqr'] = iqr(x) # Interquantile range
63
+ stats['Fstat_range'] = np.ptp(x) # Range max(x) - min(x)
64
+ stats['Fstat_mad'] = np.mean(np.absolute(x - np.mean(x))) # Mean absolute deviation
65
+ x_10_90 = x[np.where((x >= stats['Fstat_P10']) &
66
+ (x <= stats['Fstat_P90']), True, False)]
67
+ stats['Fstat_rmad'] = np.mean(np.abs(x_10_90 - np.mean(x_10_90))) # Robust mean absolute deviation
68
+ stats['Fstat_medad'] = np.mean(np.absolute(x - np.median(x))) # Median absolute deviation
69
+ stats['Fstat_cov'] = variation(x) # Coefficient of variation
70
+ x_75_25 = scoreatpercentile(x, 75) + scoreatpercentile(x, 25)
71
+ stats['Fstat_qcod'] = iqr(x)/x_75_25 # Quartile coefficient of dispersion
72
+ stats['Fstat_energy'] = np.sum(np.power(x, 2)) # Energy
73
+ stats['Fstat_rms'] = np.sqrt(np.mean(np.power(x, 2))) # Root mean square
74
+
75
+ return stats
76
+
77
+ def mean(vol: np.ndarray) -> float:
78
+ """Computes statistical mean feature of the input dataset (3D Array).
79
+ This feature refers to "Fstat_mean" (ID = Q4LE) in
80
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
81
+
82
+ Args:
83
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
84
+ (continuous imaging intensity distribution)
85
+
86
+ Returns:
87
+ float: Statistical mean feature
88
+ """
89
+ x = vol[~np.isnan(vol[:])] # Initialization
90
+
91
+ return np.mean(x) # Mean
92
+
93
+ def var(vol: np.ndarray) -> float:
94
+ """Computes statistical variance feature of the input dataset (3D Array).
95
+ This feature refers to "Fstat_var" (ID = ECT3) in
96
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
97
+
98
+ Args:
99
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
100
+ (continuous imaging intensity distribution)
101
+
102
+ Returns:
103
+ float: Statistical variance feature
104
+ """
105
+ x = vol[~np.isnan(vol[:])] # Initialization
106
+
107
+ return np.var(x) # Variance
108
+
109
+ def skewness(vol: np.ndarray) -> float:
110
+ """Computes the sample skewness feature of the input dataset (3D Array).
111
+ This feature refers to "Fstat_skew" (ID = KE2A) in
112
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
113
+
114
+ Args:
115
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
116
+ (continuous imaging intensity distribution)
117
+
118
+ Returns:
119
+ float: The skewness feature of values along an axis. Returning 0 where all values are
120
+ equal.
121
+ """
122
+ x = vol[~np.isnan(vol[:])] # Initialization
123
+
124
+ return skew(x) # Skewness
125
+
126
+ def kurt(vol: np.ndarray) -> float:
127
+ """Computes the kurtosis (Fisher or Pearson) feature of the input dataset (3D Array).
128
+ This feature refers to "Fstat_kurt" (ID = IPH6) in
129
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
130
+
131
+ Args:
132
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
133
+ (continuous imaging intensity distribution)
134
+
135
+ Returns:
136
+ float: The kurtosis feature of values along an axis. If all values are equal,
137
+ return -3 for Fisher's definition and 0 for Pearson's definition.
138
+ """
139
+ x = vol[~np.isnan(vol[:])] # Initialization
140
+
141
+ return kurtosis(x) # Kurtosis
142
+
143
+ def median(vol: np.ndarray) -> float:
144
+ """Computes the median feature along the specified axis of the input dataset (3D Array).
145
+ This feature refers to "Fstat_median" (ID = Y12H) in
146
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
147
+
148
+ Args:
149
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
150
+ (continuous imaging intensity distribution)
151
+
152
+ Returns:
153
+ float: The median feature of the array elements.
154
+ """
155
+ x = vol[~np.isnan(vol[:])] # Initialization
156
+
157
+ return np.median(x) # Median
158
+
159
+ def min(vol: np.ndarray) -> float:
160
+ """Computes the minimum grey level feature of the input dataset (3D Array).
161
+ This feature refers to "Fstat_min" (ID = 1GSF) in
162
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
163
+
164
+ Args:
165
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
166
+ (continuous imaging intensity distribution)
167
+
168
+ Returns:
169
+ float: The minimum grey level feature of the array elements.
170
+ """
171
+ x = vol[~np.isnan(vol[:])] # Initialization
172
+
173
+ return np.min(x) # Minimum grey level
174
+
175
+ def p10(vol: np.ndarray) -> float:
176
+ """Computes the score at the 10th percentile feature of the input dataset (3D Array).
177
+ This feature refers to "Fstat_P10" (ID = QG58) in
178
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
179
+
180
+ Args:
181
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
182
+ (continuous imaging intensity distribution)
183
+
184
+ Returns:
185
+ float: Score at 10th percentil.
186
+ """
187
+ x = vol[~np.isnan(vol[:])] # Initialization
188
+
189
+ return scoreatpercentile(x, 10) # 10th percentile
190
+
191
+ def p90(vol: np.ndarray) -> float:
192
+ """Computes the score at the 90th percentile feature of the input dataset (3D Array).
193
+ This feature refers to "Fstat_P90" (ID = 8DWT) in
194
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
195
+
196
+ Args:
197
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
198
+ (continuous imaging intensity distribution)
199
+
200
+ Returns:
201
+ float: Score at 90th percentil.
202
+ """
203
+ x = vol[~np.isnan(vol[:])] # Initialization
204
+
205
+ return scoreatpercentile(x, 90) # 90th percentile
206
+
207
+ def max(vol: np.ndarray) -> float:
208
+ """Computes the maximum grey level feature of the input dataset (3D Array).
209
+ This feature refers to "Fstat_max" (ID = 84IY) in
210
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
211
+
212
+ Args:
213
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
214
+ (continuous imaging intensity distribution)
215
+
216
+ Returns:
217
+ float: The maximum grey level feature of the array elements.
218
+ """
219
+ x = vol[~np.isnan(vol[:])] # Initialization
220
+
221
+ return np.max(x) # Maximum grey level
222
+
223
+ def iqrange(vol: np.ndarray) -> float:
224
+ """Computes the interquartile range feature of the input dataset (3D Array).
225
+ This feature refers to "Fstat_iqr" (ID = SALO) in
226
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
227
+
228
+ Args:
229
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
230
+ (continuous imaging intensity distribution)
231
+
232
+ Returns:
233
+ float: Interquartile range. If axis != None, the output data-type is the same as that of the input.
234
+ """
235
+ x = vol[~np.isnan(vol[:])] # Initialization
236
+
237
+ return iqr(x) # Interquartile range
238
+
239
+ def range(vol: np.ndarray) -> float:
240
+ """Range of values (maximum - minimum) feature along an axis of the input dataset (3D Array).
241
+ This feature refers to "Fstat_range" (ID = 2OJQ) in
242
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
243
+
244
+ Args:
245
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
246
+ (continuous imaging intensity distribution)
247
+
248
+ Returns:
249
+ float: A new array holding the range of values, unless out was specified,
250
+ in which case a reference to out is returned.
251
+ """
252
+ x = vol[~np.isnan(vol[:])] # Initialization
253
+
254
+ return np.ptp(x) # Range max(x) - min(x)
255
+
256
+ def mad(vol: np.ndarray) -> float:
257
+ """Mean absolute deviation feature of the input dataset (3D Array).
258
+ This feature refers to "Fstat_mad" (ID = 4FUA) in
259
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
260
+
261
+ Args:
262
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
263
+ (continuous imaging intensity distribution)
264
+
265
+ Returns:
266
+ float : A new array holding mean absolute deviation feature.
267
+ """
268
+ x = vol[~np.isnan(vol[:])] # Initialization
269
+
270
+ return np.mean(np.absolute(x - np.mean(x))) # Mean absolute deviation
271
+
272
+ def rmad(vol: np.ndarray) -> float:
273
+ """Robust mean absolute deviation feature of the input dataset (3D Array).
274
+ This feature refers to "Fstat_rmad" (ID = 1128) in
275
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
276
+
277
+ Args:
278
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
279
+ (continuous imaging intensity distribution)
280
+ P10(ndarray): Score at 10th percentil.
281
+ P90(ndarray): Score at 90th percentil.
282
+
283
+ Returns:
284
+ float: A new array holding the robust mean absolute deviation.
285
+ """
286
+ x = vol[~np.isnan(vol[:])] # Initialization
287
+ P10 = scoreatpercentile(x, 10) # 10th percentile
288
+ P90 = scoreatpercentile(x, 90) # 90th percentile
289
+ x_10_90 = x[np.where((x >= P10) &
290
+ (x <= P90), True, False)] # Holding x for (x >= P10) and (x<= P90)
291
+
292
+ return np.mean(np.abs(x_10_90 - np.mean(x_10_90))) # Robust mean absolute deviation
293
+
294
+ def medad(vol: np.ndarray) -> float:
295
+ """Median absolute deviation feature of the input dataset (3D Array).
296
+ This feature refers to "Fstat_medad" (ID = N72L) in
297
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
298
+
299
+ Args:
300
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
301
+ (continuous imaging intensity distribution)
302
+
303
+ Returns:
304
+ float: A new array holding the median absolute deviation feature.
305
+ """
306
+ x = vol[~np.isnan(vol[:])] # Initialization
307
+
308
+ return np.mean(np.absolute(x - np.median(x))) # Median absolute deviation
309
+
310
+ def cov(vol: np.ndarray) -> float:
311
+ """Computes the coefficient of variation feature of the input dataset (3D Array).
312
+ This feature refers to "Fstat_cov" (ID = 7TET) in
313
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
314
+
315
+ Args:
316
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
317
+ (continuous imaging intensity distribution)
318
+
319
+ Returns:
320
+ float: A new array holding the coefficient of variation feature.
321
+ """
322
+ x = vol[~np.isnan(vol[:])] # Initialization
323
+
324
+ return variation(x) # Coefficient of variation
325
+
326
+ def qcod(vol: np.ndarray) -> float:
327
+ """Computes the quartile coefficient of dispersion feature of the input dataset (3D Array).
328
+ This feature refers to "Fstat_qcod" (ID = 9S40) in
329
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
330
+
331
+ Args:
332
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
333
+ (continuous imaging intensity distribution)
334
+
335
+ Returns:
336
+ float: A new array holding the quartile coefficient of dispersion feature.
337
+ """
338
+ x = vol[~np.isnan(vol[:])] # Initialization
339
+ x_75_25 = scoreatpercentile(x, 75) + scoreatpercentile(x, 25)
340
+
341
+ return iqr(x) / x_75_25 # Quartile coefficient of dispersion
342
+
343
+ def energy(vol: np.ndarray) -> float:
344
+ """Computes the energy feature of the input dataset (3D Array).
345
+ This feature refers to "Fstat_energy" (ID = N8CA) in
346
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
347
+
348
+ Args:
349
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
350
+ (continuous imaging intensity distribution)
351
+
352
+ Returns:
353
+ float: A new array holding the energy feature.
354
+ """
355
+ x = vol[~np.isnan(vol[:])] # Initialization
356
+
357
+ return np.sum(np.power(x, 2)) # Energy
358
+
359
+ def rms(vol: np.ndarray) -> float:
360
+ """Computes the root mean square feature of the input dataset (3D Array).
361
+ This feature refers to "Fstat_rms" (ID = 5ZWQ) in
362
+ the `IBSI1 reference manual <https://arxiv.org/pdf/1612.07003.pdf>`_.
363
+
364
+ Args:
365
+ vol(ndarray): 3D volume, NON-QUANTIZED, with NaNs outside the region of interest
366
+ (continuous imaging intensity distribution)
367
+
368
+ Returns:
369
+ float: A new array holding the root mean square feature.
370
+ """
371
+ x = vol[~np.isnan(vol[:])] # Initialization
372
+
373
+ return np.sqrt(np.mean(np.power(x, 2))) # Root mean square