mirp 2.2.0__tar.gz → 2.2.1__tar.gz

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 (118) hide show
  1. {mirp-2.2.0 → mirp-2.2.1}/CONTRIBUTING.md +7 -5
  2. {mirp-2.2.0 → mirp-2.2.1}/NEWS.md +28 -0
  3. {mirp-2.2.0 → mirp-2.2.1}/PKG-INFO +62 -42
  4. {mirp-2.2.0 → mirp-2.2.1}/README.md +59 -38
  5. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/dicom_file.py +167 -28
  6. mirp-2.2.1/mirp/_data_import/dicom_file_pet.py +825 -0
  7. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/dicom_file_rtdose.py +15 -9
  8. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/dicom_file_rtstruct.py +9 -7
  9. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/dicom_file_stack.py +3 -3
  10. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/directory.py +6 -2
  11. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/generic_file.py +47 -9
  12. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/generic_file_stack.py +11 -11
  13. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/itk_file.py +9 -1
  14. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/mask_contour.py +2 -2
  15. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/numpy_file.py +5 -1
  16. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/read_data.py +11 -9
  17. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/suv.py +1 -1
  18. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/dzm.py +0 -59
  19. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/szm.py +0 -55
  20. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/gaussian.py +1 -1
  21. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/base_image.py +1 -1
  22. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/generic_image.py +15 -12
  23. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/mask_image.py +2 -2
  24. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/mr_image.py +1 -0
  25. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/utilities.py +19 -4
  26. {mirp-2.2.0 → mirp-2.2.1}/mirp/_masks/base_mask.py +16 -18
  27. {mirp-2.2.0 → mirp-2.2.1}/mirp/_workflows/standardWorkflow.py +5 -1
  28. {mirp-2.2.0 → mirp-2.2.1}/mirp/config_settings.xml +4 -0
  29. {mirp-2.2.0 → mirp-2.2.1}/mirp/data_import/import_image_and_mask.py +93 -68
  30. {mirp-2.2.0 → mirp-2.2.1}/mirp/data_import/import_mask.py +1 -1
  31. {mirp-2.2.0 → mirp-2.2.1}/mirp/deep_learning_preprocessing.py +11 -11
  32. {mirp-2.2.0 → mirp-2.2.1}/mirp/deprecated.py +6 -6
  33. {mirp-2.2.0 → mirp-2.2.1}/mirp/extract_features_and_images.py +10 -11
  34. {mirp-2.2.0 → mirp-2.2.1}/mirp/extract_image_parameters.py +8 -16
  35. {mirp-2.2.0 → mirp-2.2.1}/mirp/extract_mask_labels.py +6 -15
  36. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/feature_parameters.py +1 -1
  37. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/generic.py +11 -2
  38. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/image_processing_parameters.py +46 -3
  39. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/interpolation_parameters.py +7 -3
  40. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/transformation_parameters.py +27 -25
  41. {mirp-2.2.0 → mirp-2.2.1}/mirp/utilities/config_utilities.py +5 -4
  42. mirp-2.2.1/mirp/utilities/parallel.py +100 -0
  43. {mirp-2.2.0 → mirp-2.2.1}/mirp.egg-info/PKG-INFO +62 -42
  44. {mirp-2.2.0 → mirp-2.2.1}/mirp.egg-info/SOURCES.txt +0 -4
  45. {mirp-2.2.0 → mirp-2.2.1}/mirp.egg-info/requires.txt +4 -1
  46. {mirp-2.2.0 → mirp-2.2.1}/pyproject.toml +10 -6
  47. mirp-2.2.0/mirp/_data_import/dicom_file_pet.py +0 -388
  48. mirp-2.2.0/mirp/_image_processing/add_noise.py +0 -32
  49. mirp-2.2.0/mirp/_image_processing/normalise_image.py +0 -31
  50. mirp-2.2.0/mirp/_image_processing/resegmentise_mask.py +0 -33
  51. mirp-2.2.0/mirp/_image_processing/saturate_image.py +0 -18
  52. mirp-2.2.0/mirp/utilities/parallel.py +0 -44
  53. {mirp-2.2.0 → mirp-2.2.1}/LICENSE.txt +0 -0
  54. {mirp-2.2.0 → mirp-2.2.1}/MANIFEST.in +0 -0
  55. {mirp-2.2.0 → mirp-2.2.1}/mirp/__init__.py +0 -0
  56. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/__init__.py +0 -0
  57. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/dicom_file_ct.py +0 -0
  58. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/dicom_file_mr.py +0 -0
  59. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/dicom_file_seg.py +0 -0
  60. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/itk_file_stack.py +0 -0
  61. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/numpy_file_stack.py +0 -0
  62. {mirp-2.2.0 → mirp-2.2.1}/mirp/_data_import/utilities.py +0 -0
  63. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/__init__.py +0 -0
  64. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/cm.py +0 -0
  65. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/intensity_histogram.py +0 -0
  66. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/intensity_volume_histogram.py +0 -0
  67. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/local_intensity.py +0 -0
  68. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/morphology_3d.py +0 -0
  69. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/ngldm.py +0 -0
  70. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/ngtdm.py +0 -0
  71. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/rlm.py +0 -0
  72. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/statistics.py +0 -0
  73. {mirp-2.2.0 → mirp-2.2.1}/mirp/_featuresets/utilities.py +0 -0
  74. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/__init__.py +0 -0
  75. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/alter_mask.py +0 -0
  76. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/anti_aliasing.py +0 -0
  77. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/cropping.py +0 -0
  78. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/discretise_image.py +0 -0
  79. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/randomise_mask.py +0 -0
  80. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/split_mask.py +0 -0
  81. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/tissue_mask.py +0 -0
  82. {mirp-2.2.0 → mirp-2.2.1}/mirp/_image_processing/utilities.py +0 -0
  83. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/__init__.py +0 -0
  84. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/exponential_transform.py +0 -0
  85. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/gabor.py +0 -0
  86. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/generic.py +0 -0
  87. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/laplacian_of_gaussian.py +0 -0
  88. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/laws.py +0 -0
  89. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/log_transform.py +0 -0
  90. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/mean.py +0 -0
  91. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/nonseparable_wavelet.py +0 -0
  92. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/separable_wavelet.py +0 -0
  93. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/square_root_transform.py +0 -0
  94. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/square_transform.py +0 -0
  95. {mirp-2.2.0 → mirp-2.2.1}/mirp/_imagefilters/utilities.py +0 -0
  96. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/__init__.py +0 -0
  97. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/ct_image.py +0 -0
  98. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/pet_image.py +0 -0
  99. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/rtdose_image.py +0 -0
  100. {mirp-2.2.0 → mirp-2.2.1}/mirp/_images/transformed_image.py +0 -0
  101. {mirp-2.2.0 → mirp-2.2.1}/mirp/_masks/__init__.py +0 -0
  102. {mirp-2.2.0 → mirp-2.2.1}/mirp/_workflows/__init__.py +0 -0
  103. {mirp-2.2.0 → mirp-2.2.1}/mirp/_workflows/baseWorkflow.py +0 -0
  104. {mirp-2.2.0 → mirp-2.2.1}/mirp/config_data.xml +0 -0
  105. {mirp-2.2.0 → mirp-2.2.1}/mirp/data_import/__init__.py +0 -0
  106. {mirp-2.2.0 → mirp-2.2.1}/mirp/data_import/import_image.py +0 -0
  107. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/__init__.py +0 -0
  108. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/general_parameters.py +0 -0
  109. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/import_config_parameters.py +0 -0
  110. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/import_data_parameters.py +0 -0
  111. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/perturbation_parameters.py +0 -0
  112. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/resegmentation_parameters.py +0 -0
  113. {mirp-2.2.0 → mirp-2.2.1}/mirp/settings/utilities.py +0 -0
  114. {mirp-2.2.0 → mirp-2.2.1}/mirp/utilities/__init__.py +0 -0
  115. {mirp-2.2.0 → mirp-2.2.1}/mirp/utilities/utilities.py +0 -0
  116. {mirp-2.2.0 → mirp-2.2.1}/mirp.egg-info/dependency_links.txt +0 -0
  117. {mirp-2.2.0 → mirp-2.2.1}/mirp.egg-info/top_level.txt +0 -0
  118. {mirp-2.2.0 → mirp-2.2.1}/setup.cfg +0 -0
@@ -1,16 +1,18 @@
1
- # How to contribute
1
+ # Contributing
2
2
 
3
- If you have ideas or code to contribute, please first open an [issue](https://github.com/oncoray/mirp/issues). We will then discuss your ideas and create an implementation roadmap.
3
+ IRP is open-source software, hosted on [GitHub](https://github.com/oncoray/mirp). Contributions that enable
4
+ new DICOM modalities are especially welcome! If you have ideas or code to contribute, please first open an
5
+ `issue <https://github.com/oncoray/mirp/issues>`_ and describe your ideas.
4
6
 
5
- Please keep the following in mind when contributing:
7
+ Technical documentation is forthcoming. For now, please keep the following in mind when contributing:
6
8
 
7
9
  - The main branch of `mirp` is protected. You can therefore make a pull request for your contribution to a
8
10
  development branch of the intended future version.
9
- - If you introduce new functionality, this functionality should be tested as part of the tests in the `test`directory.
11
+ - If you introduce new functionality, this functionality should be tested as part of the tests in the `test` directory.
10
12
  After implementation, please ensure that all tests complete without errors by running `pytest` from your IDE or
11
13
  console using `python -m pytest test` from the mirp main directory.
12
14
  - Code is styled according to [PEP8](https://peps.python.org/pep-0008/). Using a linter or IDE with automated linter
13
15
  is recommended.
14
16
  - Function, class and method documentation is done using Numpy-flavoured [docstrings](https://numpydoc.readthedocs.io/en/latest/format.html).
15
17
  [Long-form documentation](https://oncoray.github.io/mirp/) is partially created from function, class and method
16
- documentation, embedded in restructured text files in `docs_source`.
18
+ documentation, embedded in restructured text files in the `docs_source` directory.
@@ -1,3 +1,31 @@
1
+ # Version 2.2.1
2
+
3
+ ## Minor changes
4
+
5
+ - If mask-related parameters are not provided for computing features or processing of images for deep learning, a
6
+ mask is generated that covers the entire image.
7
+
8
+ - Add fall-back methods for missing installation of the `ray` package for parallel processing. This can happen when
9
+ a python version is not supported by the `ray` package. `ray` is now a conditional dependency, until that package
10
+ is released for python `3.12`.
11
+
12
+ - The default export format for `deep_learning_processing` and `deep_learning_processing_generator` is now `dict`,
13
+ because the sample name is important for matching against observed outcomes.
14
+
15
+ - `write_file` arguments of `extract_mask_labels` and `extract_image_parameters` were deprecated as these were
16
+ redundant.
17
+
18
+ ## Fixes
19
+
20
+ - Streamlined importing and reading DICOM files results in faster processing of DICOM-based imaging.
21
+
22
+ - Fixed an indexing issue when attempting to split masks into bulk and rim sections in a slice-wise fashion.
23
+
24
+ - Fixed an indexing issue in Rank's method for noise estimation.
25
+
26
+ - Fixed incorrectly named image parameters file export. Instead of `mask_labels.csv`, image parameters are now
27
+ correctly exported to `image_metadata.csv`.
28
+
1
29
  # Version 2.2.0
2
30
 
3
31
  ## Major changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mirp
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: A package for standardised processing of medical imaging and computation of quantitative features.
5
5
  Author-email: Alex Zwanenburg <alexander.zwanenburg@nct-dresden.de>
6
6
  License: European Union Public Licence
@@ -284,8 +284,6 @@ Project-URL: Changelog, https://github.com/oncoray/mirp/blob/master/NEWS.md
284
284
  Classifier: Programming Language :: Python :: 3
285
285
  Classifier: Programming Language :: Python :: 3.10
286
286
  Classifier: Programming Language :: Python :: 3.11
287
- Classifier: Programming Language :: Python :: 3.12
288
- Classifier: Programming Language :: Python :: 3.13
289
287
  Classifier: License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)
290
288
  Classifier: Operating System :: OS Independent
291
289
  Classifier: Topic :: Scientific/Engineering :: Image Processing
@@ -299,27 +297,51 @@ Requires-Dist: numpy>=1.25
299
297
  Requires-Dist: pandas>=2.0.0
300
298
  Requires-Dist: pydicom>=2.4.0
301
299
  Requires-Dist: pywavelets>=1.4.0
302
- Requires-Dist: ray>=2.7.0
303
300
  Requires-Dist: scikit-image>=0.20.0
304
301
  Requires-Dist: scipy>=1.11
305
302
  Requires-Dist: typing-extensions>=4.10; python_version < "3.11"
303
+ Requires-Dist: ray>=2.10.0; python_version <= "3.11"
306
304
  Provides-Extra: test
307
305
  Requires-Dist: pytest>=7.4.0; extra == "test"
308
306
  Provides-Extra: docs
309
307
  Requires-Dist: sphinx>=5.0.0; extra == "docs"
310
308
  Requires-Dist: sphinx_rtd_theme>=2.0.0; extra == "docs"
309
+ Requires-Dist: nbsphinx; extra == "docs"
311
310
 
312
311
  <img src="https://raw.githubusercontent.com/oncoray/mirp/master/icon/mirp.svg" align="right" width="120"/>
313
312
 
314
313
  # Medical Image Radiomics Processor
315
314
 
316
- Medical Image Radiomics Processor (MIRP) is an IBSI-compliant python package for medical image analysis.
317
- MIRP focuses on radiomics applications and supports computation of features for conventional radiomics
318
- and image processing for deep-learning applications.
315
+ Medical Image Radiomics Processor (MIRP) is a python package for medical image analysis that is compliant with the
316
+ reference standards of the Image Biomarker Standardisation Initiative (IBSI). MIRP focuses on radiomics applications
317
+ and supports computation of features for conventional radiomics and image processing for deep-learning applications.
319
318
 
320
- ## Documentation
319
+ ## Documentation and tutorials
321
320
 
322
- Documentation can be found here: https://oncoray.github.io/mirp/
321
+ Documentation and tutorials can be found here: https://oncoray.github.io/mirp/
322
+
323
+ ## Supported Python and OS
324
+
325
+ MIRP currently supports the following Python versions and operating systems:
326
+
327
+ | Python | Linux | Win | OSX |
328
+ |--------|-----------|-----------|-----------|
329
+ | 3.10 | Supported | Supported | Supported |
330
+ | 3.11 | Supported | Supported | Supported |
331
+
332
+ ## Supported imaging and mask modalities
333
+
334
+ MIRP currently supports the following image modalities:
335
+
336
+ | File format | File type | Supported modality |
337
+ |-------------|-----------|--------------------|
338
+ | DICOM | image | CT, MR, PT, RTDOSE |
339
+ | DICOM | mask | RTSTRUCT, SEG |
340
+ | NIfTI | any | any |
341
+ | NRRD | any | any |
342
+ | numpy | any | any |
343
+
344
+ NIfTI, NRRD, and numpy files support any kind of (single-channel) image. MIRP cannot process RGB or 4D images.
323
345
 
324
346
  ## Installing MIRP
325
347
  MIRP is available from PyPI and can be installed using `pip`, or other installer tools:
@@ -328,39 +350,6 @@ MIRP is available from PyPI and can be installed using `pip`, or other installer
328
350
  pip install mirp
329
351
  ```
330
352
 
331
- ## Transitioning to version 2
332
-
333
- Version 2 is a major refactoring of the previous code base. For users this brings the following noticeable changes:
334
-
335
- - MIRP was previously configured using two `xml` files: [`config_data.xml`](mirp/config_data.xml) for configuring
336
- directories, data to be read, etc., and [`config_settings.xml`](mirp/config_settings.xml) for configuring experiments.
337
- While these two files can still be used, MIRP can now be configured directly, without using these files.
338
- - The main functions of MIRP (`mainFunctions.py`) have all been re-implemented.
339
- - `mainFunctions.extract_features` is now `extract_features` (functional form) or
340
- `extract_features_generator` (generator). The replacements allow for both writing
341
- feature values to a directory and returning them as function output.
342
- - `mainFunctions.extract_images_to_nifti` is now `extract_images` (functional form) or
343
- `extract_images_generator` (generator). The replacements allow for both writing
344
- images to a directory (e.g., in NIfTI or numpy format) and returning them as function output.
345
- - `mainFunctions.extract_images_for_deep_learning` has been replaced by
346
- `deep_learning_preprocessing` (functional form) and
347
- `deep_learning_preprocessing_generator` (generator).
348
- - `mainFunctions.get_file_structure_parameters` and `mainFunctions.parse_file_structure` are deprecated, as the
349
- the file import system used in version 2 no longer requires a rigid directory structure.
350
- - `mainFunctions.get_roi_labels` is now `extract_mask_labels`.
351
- - `mainFunctions.get_image_acquisition_parameters` is now `extract_image_parameters`.
352
-
353
- For advanced users and developers, the following changes are relevant:
354
- - MIRP previously relied on `ImageClass` and `RoiClass` objects. These have been completely replaced by `GenericImage`
355
- (and its subclasses, e.g. `CTImage`) and `BaseMask` objects, respectively. New image modalities can be added as
356
- subclass of `GenericImage` in the `mirp.images` submodule.
357
- - File import, e.g. from DICOM or NIfTI files, in version 1 was implemented in an ad-hoc manner, and required a rigid
358
- directory structure. Since version 2, file import is implemented using an object-oriented approach, and directory
359
- structures are more flexible. File import of new modalities can be implemented as a relevant subclass of `ImageFile`.
360
- - MIRP uses type hinting, and makes use of the `Self` type hint introduced in Python 3.11. MIRP
361
- therefore requires Python 3.11 or later.
362
- - MIRP now uses the `ray` package for parallel processing.
363
-
364
353
  ## Examples - Computing Radiomics Features
365
354
 
366
355
  MIRP can be used to compute quantitative features from regions of interest in images in an IBSI-compliant manner
@@ -466,6 +455,37 @@ mask_labels = extract_mask_labels(
466
455
  )
467
456
  ```
468
457
 
458
+ ## Transitioning to version 2
459
+
460
+ Version 2 is a major refactoring of the previous code base. For users this brings the following noticeable changes:
461
+
462
+ - MIRP was previously configured using two `xml` files: [`config_data.xml`](mirp/config_data.xml) for configuring
463
+ directories, data to be read, etc., and [`config_settings.xml`](mirp/config_settings.xml) for configuring experiments.
464
+ While these two files can still be used, MIRP can now be configured directly, without using these files.
465
+ - The main functions of MIRP (`mainFunctions.py`) have all been re-implemented.
466
+ - `mainFunctions.extract_features` is now `extract_features` (functional form) or
467
+ `extract_features_generator` (generator). The replacements allow for both writing
468
+ feature values to a directory and returning them as function output.
469
+ - `mainFunctions.extract_images_to_nifti` is now `extract_images` (functional form) or
470
+ `extract_images_generator` (generator). The replacements allow for both writing
471
+ images to a directory (e.g., in NIfTI or numpy format) and returning them as function output.
472
+ - `mainFunctions.extract_images_for_deep_learning` has been replaced by
473
+ `deep_learning_preprocessing` (functional form) and
474
+ `deep_learning_preprocessing_generator` (generator).
475
+ - `mainFunctions.get_file_structure_parameters` and `mainFunctions.parse_file_structure` are deprecated, as the
476
+ the file import system used in version 2 no longer requires a rigid directory structure.
477
+ - `mainFunctions.get_roi_labels` is now `extract_mask_labels`.
478
+ - `mainFunctions.get_image_acquisition_parameters` is now `extract_image_parameters`.
479
+
480
+ For advanced users and developers, the following changes are relevant:
481
+ - MIRP previously relied on `ImageClass` and `RoiClass` objects. These have been completely replaced by `GenericImage`
482
+ (and its subclasses, e.g. `CTImage`) and `BaseMask` objects, respectively. New image modalities can be added as
483
+ subclass of `GenericImage` in the `mirp.images` submodule.
484
+ - File import, e.g. from DICOM or NIfTI files, in version 1 was implemented in an ad-hoc manner, and required a rigid
485
+ directory structure. Since version 2, file import is implemented using an object-oriented approach, and directory
486
+ structures are more flexible. File import of new modalities can be implemented as a relevant subclass of `ImageFile`.
487
+ - MIRP now uses the `ray` package for parallel processing.
488
+
469
489
  # Citation info
470
490
  A publication for MIRP is forthcoming. For now, please cite the following work:
471
491
  ```Zwanenburg A, Leger S, Agolli L, Pilz K, Troost EG, Richter C, Löck S. Assessing robustness of radiomic features by image perturbation. Scientific reports. 2019 Jan 24;9(1):614.```
@@ -2,13 +2,36 @@
2
2
 
3
3
  # Medical Image Radiomics Processor
4
4
 
5
- Medical Image Radiomics Processor (MIRP) is an IBSI-compliant python package for medical image analysis.
6
- MIRP focuses on radiomics applications and supports computation of features for conventional radiomics
7
- and image processing for deep-learning applications.
5
+ Medical Image Radiomics Processor (MIRP) is a python package for medical image analysis that is compliant with the
6
+ reference standards of the Image Biomarker Standardisation Initiative (IBSI). MIRP focuses on radiomics applications
7
+ and supports computation of features for conventional radiomics and image processing for deep-learning applications.
8
8
 
9
- ## Documentation
9
+ ## Documentation and tutorials
10
10
 
11
- Documentation can be found here: https://oncoray.github.io/mirp/
11
+ Documentation and tutorials can be found here: https://oncoray.github.io/mirp/
12
+
13
+ ## Supported Python and OS
14
+
15
+ MIRP currently supports the following Python versions and operating systems:
16
+
17
+ | Python | Linux | Win | OSX |
18
+ |--------|-----------|-----------|-----------|
19
+ | 3.10 | Supported | Supported | Supported |
20
+ | 3.11 | Supported | Supported | Supported |
21
+
22
+ ## Supported imaging and mask modalities
23
+
24
+ MIRP currently supports the following image modalities:
25
+
26
+ | File format | File type | Supported modality |
27
+ |-------------|-----------|--------------------|
28
+ | DICOM | image | CT, MR, PT, RTDOSE |
29
+ | DICOM | mask | RTSTRUCT, SEG |
30
+ | NIfTI | any | any |
31
+ | NRRD | any | any |
32
+ | numpy | any | any |
33
+
34
+ NIfTI, NRRD, and numpy files support any kind of (single-channel) image. MIRP cannot process RGB or 4D images.
12
35
 
13
36
  ## Installing MIRP
14
37
  MIRP is available from PyPI and can be installed using `pip`, or other installer tools:
@@ -17,39 +40,6 @@ MIRP is available from PyPI and can be installed using `pip`, or other installer
17
40
  pip install mirp
18
41
  ```
19
42
 
20
- ## Transitioning to version 2
21
-
22
- Version 2 is a major refactoring of the previous code base. For users this brings the following noticeable changes:
23
-
24
- - MIRP was previously configured using two `xml` files: [`config_data.xml`](mirp/config_data.xml) for configuring
25
- directories, data to be read, etc., and [`config_settings.xml`](mirp/config_settings.xml) for configuring experiments.
26
- While these two files can still be used, MIRP can now be configured directly, without using these files.
27
- - The main functions of MIRP (`mainFunctions.py`) have all been re-implemented.
28
- - `mainFunctions.extract_features` is now `extract_features` (functional form) or
29
- `extract_features_generator` (generator). The replacements allow for both writing
30
- feature values to a directory and returning them as function output.
31
- - `mainFunctions.extract_images_to_nifti` is now `extract_images` (functional form) or
32
- `extract_images_generator` (generator). The replacements allow for both writing
33
- images to a directory (e.g., in NIfTI or numpy format) and returning them as function output.
34
- - `mainFunctions.extract_images_for_deep_learning` has been replaced by
35
- `deep_learning_preprocessing` (functional form) and
36
- `deep_learning_preprocessing_generator` (generator).
37
- - `mainFunctions.get_file_structure_parameters` and `mainFunctions.parse_file_structure` are deprecated, as the
38
- the file import system used in version 2 no longer requires a rigid directory structure.
39
- - `mainFunctions.get_roi_labels` is now `extract_mask_labels`.
40
- - `mainFunctions.get_image_acquisition_parameters` is now `extract_image_parameters`.
41
-
42
- For advanced users and developers, the following changes are relevant:
43
- - MIRP previously relied on `ImageClass` and `RoiClass` objects. These have been completely replaced by `GenericImage`
44
- (and its subclasses, e.g. `CTImage`) and `BaseMask` objects, respectively. New image modalities can be added as
45
- subclass of `GenericImage` in the `mirp.images` submodule.
46
- - File import, e.g. from DICOM or NIfTI files, in version 1 was implemented in an ad-hoc manner, and required a rigid
47
- directory structure. Since version 2, file import is implemented using an object-oriented approach, and directory
48
- structures are more flexible. File import of new modalities can be implemented as a relevant subclass of `ImageFile`.
49
- - MIRP uses type hinting, and makes use of the `Self` type hint introduced in Python 3.11. MIRP
50
- therefore requires Python 3.11 or later.
51
- - MIRP now uses the `ray` package for parallel processing.
52
-
53
43
  ## Examples - Computing Radiomics Features
54
44
 
55
45
  MIRP can be used to compute quantitative features from regions of interest in images in an IBSI-compliant manner
@@ -155,6 +145,37 @@ mask_labels = extract_mask_labels(
155
145
  )
156
146
  ```
157
147
 
148
+ ## Transitioning to version 2
149
+
150
+ Version 2 is a major refactoring of the previous code base. For users this brings the following noticeable changes:
151
+
152
+ - MIRP was previously configured using two `xml` files: [`config_data.xml`](mirp/config_data.xml) for configuring
153
+ directories, data to be read, etc., and [`config_settings.xml`](mirp/config_settings.xml) for configuring experiments.
154
+ While these two files can still be used, MIRP can now be configured directly, without using these files.
155
+ - The main functions of MIRP (`mainFunctions.py`) have all been re-implemented.
156
+ - `mainFunctions.extract_features` is now `extract_features` (functional form) or
157
+ `extract_features_generator` (generator). The replacements allow for both writing
158
+ feature values to a directory and returning them as function output.
159
+ - `mainFunctions.extract_images_to_nifti` is now `extract_images` (functional form) or
160
+ `extract_images_generator` (generator). The replacements allow for both writing
161
+ images to a directory (e.g., in NIfTI or numpy format) and returning them as function output.
162
+ - `mainFunctions.extract_images_for_deep_learning` has been replaced by
163
+ `deep_learning_preprocessing` (functional form) and
164
+ `deep_learning_preprocessing_generator` (generator).
165
+ - `mainFunctions.get_file_structure_parameters` and `mainFunctions.parse_file_structure` are deprecated, as the
166
+ the file import system used in version 2 no longer requires a rigid directory structure.
167
+ - `mainFunctions.get_roi_labels` is now `extract_mask_labels`.
168
+ - `mainFunctions.get_image_acquisition_parameters` is now `extract_image_parameters`.
169
+
170
+ For advanced users and developers, the following changes are relevant:
171
+ - MIRP previously relied on `ImageClass` and `RoiClass` objects. These have been completely replaced by `GenericImage`
172
+ (and its subclasses, e.g. `CTImage`) and `BaseMask` objects, respectively. New image modalities can be added as
173
+ subclass of `GenericImage` in the `mirp.images` submodule.
174
+ - File import, e.g. from DICOM or NIfTI files, in version 1 was implemented in an ad-hoc manner, and required a rigid
175
+ directory structure. Since version 2, file import is implemented using an object-oriented approach, and directory
176
+ structures are more flexible. File import of new modalities can be implemented as a relevant subclass of `ImageFile`.
177
+ - MIRP now uses the `ray` package for parallel processing.
178
+
158
179
  # Citation info
159
180
  A publication for MIRP is forthcoming. For now, please cite the following work:
160
181
  ```Zwanenburg A, Leger S, Agolli L, Pilz K, Troost EG, Richter C, Löck S. Assessing robustness of radiomic features by image perturbation. Scientific reports. 2019 Jan 24;9(1):614.```
@@ -1,3 +1,4 @@
1
+ import datetime
1
2
  import os.path
2
3
  import hashlib
3
4
  import numpy as np
@@ -9,7 +10,7 @@ from warnings import warn
9
10
 
10
11
  from mirp._data_import.generic_file import ImageFile, MaskFile
11
12
  from mirp._data_import.utilities import supported_image_modalities, stacking_dicom_image_modalities, \
12
- supported_mask_modalities, get_pydicom_meta_tag
13
+ supported_mask_modalities, get_pydicom_meta_tag, convert_dicom_time
13
14
 
14
15
 
15
16
  class ImageDicomFile(ImageFile):
@@ -87,7 +88,7 @@ class ImageDicomFile(ImageFile):
87
88
  return True
88
89
 
89
90
  # Checks requires metadata.
90
- self.load_metadata()
91
+ self.load_metadata(limited=True)
91
92
 
92
93
  # Perform general checks.
93
94
  if not super().check(raise_error=raise_error):
@@ -164,8 +165,7 @@ class ImageDicomFile(ImageFile):
164
165
  from mirp._data_import.dicom_file_rtdose import ImageDicomFileRTDose
165
166
 
166
167
  # Load metadata so that the modality tag can be read.
167
- self.load_metadata()
168
-
168
+ self.load_metadata(limited=True)
169
169
  modality = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0060), tag_type="str").lower()
170
170
 
171
171
  if modality is None:
@@ -181,9 +181,9 @@ class ImageDicomFile(ImageFile):
181
181
  file_class = ImageDicomFileRTDose
182
182
  else:
183
183
  # This will return a base class, which will fail to pass the modality check.
184
- return self
184
+ return None
185
185
 
186
- return file_class(
186
+ image = file_class(
187
187
  file_path=self.file_path,
188
188
  dir_path=self.dir_path,
189
189
  sample_name=self.sample_name,
@@ -195,28 +195,39 @@ class ImageDicomFile(ImageFile):
195
195
  image_origin=self.image_origin,
196
196
  image_orientation=self.image_orientation,
197
197
  image_spacing=self.image_spacing,
198
- image_dimensions=self.image_dimension
198
+ image_dimensions=self.image_dimension,
199
199
  )
200
200
 
201
+ # Set metadata of image.
202
+ image.image_metadata = self.image_metadata
203
+ image.is_limited_metadata = self.is_limited_metadata
204
+
205
+ return image
206
+
201
207
  def complete(self, remove_metadata=False, force=False):
202
208
 
203
209
  # complete loads metadata.
204
210
  super().complete(remove_metadata=False, force=force)
205
211
 
206
212
  # Set SOP instance UID.
207
- self.sop_instance_uid = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0018), tag_type="str")
213
+ if self.sop_instance_uid is None:
214
+ self.load_metadata(limited=True)
215
+ self.sop_instance_uid = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0018), tag_type="str")
208
216
 
209
217
  # Set Frame of Reference UID (if any)
210
218
  self._complete_frame_of_reference_uid()
211
219
 
212
220
  # Set series UID
213
- self.series_instance_uid = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0020, 0x000E), tag_type="str")
221
+ if self.series_instance_uid is None:
222
+ self.load_metadata(limited=True)
223
+ self.series_instance_uid = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0020, 0x000E), tag_type="str")
214
224
 
215
225
  if remove_metadata:
216
226
  self.remove_metadata()
217
227
 
218
228
  def _complete_modality(self):
219
229
  if self.modality is None:
230
+ self.load_metadata(limited=True)
220
231
  self.modality = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0060), tag_type="str")
221
232
 
222
233
  if self.modality is None:
@@ -229,6 +240,10 @@ class ImageDicomFile(ImageFile):
229
240
  def _complete_sample_name(self):
230
241
  # Set sample name -- note that if sample_name is a (single) string, it is neither replaced nor updated.
231
242
  if self.sample_name is None or isinstance(self.sample_name, list):
243
+
244
+ # Load relevant metadata.
245
+ self.load_metadata(limited=True)
246
+
232
247
  # Consider the following DICOM elements:
233
248
  # patient id, study id, patient name, series description and study description.
234
249
  # These are explicitly ordered by relevance for setting the sample name.
@@ -263,6 +278,9 @@ class ImageDicomFile(ImageFile):
263
278
  if self.modality in stacking_dicom_image_modalities() and not force:
264
279
  return
265
280
 
281
+ # Load relevant metadata.
282
+ self.load_metadata(limited=True)
283
+
266
284
  origin = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0020, 0x0032), tag_type="mult_float")[::-1]
267
285
  self.image_origin = tuple(origin)
268
286
 
@@ -272,6 +290,9 @@ class ImageDicomFile(ImageFile):
272
290
  if self.modality in stacking_dicom_image_modalities() and not force:
273
291
  return
274
292
 
293
+ # Load relevant metadata.
294
+ self.load_metadata(limited=True)
295
+
275
296
  orientation: list[float] = get_pydicom_meta_tag(
276
297
  dcm_seq=self.image_metadata,
277
298
  tag=(0x0020, 0x0037),
@@ -288,6 +309,9 @@ class ImageDicomFile(ImageFile):
288
309
  if self.modality in stacking_dicom_image_modalities() and not force:
289
310
  return
290
311
 
312
+ # Load relevant metadata.
313
+ self.load_metadata(limited=True)
314
+
291
315
  # Get pixel-spacing.
292
316
  spacing = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0028, 0x0030), tag_type="mult_float")
293
317
 
@@ -307,16 +331,20 @@ class ImageDicomFile(ImageFile):
307
331
  if self.modality in stacking_dicom_image_modalities() and not force:
308
332
  return
309
333
 
334
+ # Load relevant metadata.
335
+ self.load_metadata(limited=True)
336
+
310
337
  dimensions = tuple([
311
338
  1,
312
- get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0028, 0x010), tag_type="int"),
313
- get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0028, 0x011), tag_type="int")
339
+ get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0028, 0x0010), tag_type="int"),
340
+ get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0028, 0x0011), tag_type="int")
314
341
  ])
315
342
 
316
343
  self.image_dimension = dimensions
317
344
 
318
345
  def _complete_frame_of_reference_uid(self):
319
346
  if self.frame_of_reference_uid is None:
347
+ self.load_metadata(limited=True)
320
348
  self.frame_of_reference_uid = get_pydicom_meta_tag(
321
349
  dcm_seq=self.image_metadata,
322
350
  tag=(0x0020, 0x0052),
@@ -343,20 +371,38 @@ class ImageDicomFile(ImageFile):
343
371
 
344
372
  return super().associate_with_mask(mask_list=mask_list, association_strategy=association_strategy)
345
373
 
346
- def load_metadata(self):
347
- if self.image_metadata is not None:
374
+ def load_metadata(self, limited=False, include_image=False):
375
+ if include_image:
376
+ limited = False
377
+
378
+ # Limited metadata exists and limited metadata is sufficient.
379
+ if self.image_metadata is not None and self.is_limited_metadata and limited:
380
+ return
381
+
382
+ # A full image metadata set exists.
383
+ if self.image_metadata is not None and not self.is_limited_metadata:
348
384
  return
349
385
 
350
386
  if self.file_path is None or not os.path.exists(self.file_path):
351
387
  raise FileNotFoundError(
352
388
  f"The image file could not be found at the expected location: {self.file_path}")
353
389
 
354
- dcm = dcmread(
355
- self.file_path,
356
- stop_before_pixels=True,
357
- force=True)
390
+ if limited:
391
+ dcm = dcmread(
392
+ self.file_path,
393
+ stop_before_pixels=True,
394
+ force=True,
395
+ specific_tags=self._get_limited_metadata_tags()
396
+ )
397
+ else:
398
+ dcm = dcmread(
399
+ self.file_path,
400
+ stop_before_pixels=not include_image,
401
+ force=True
402
+ )
358
403
 
359
404
  self.image_metadata = dcm
405
+ self.is_limited_metadata = limited
360
406
 
361
407
  def load_data(self, **kwargs):
362
408
  raise NotImplementedError(
@@ -381,19 +427,99 @@ class ImageDicomFile(ImageFile):
381
427
  raise ValueError(f"A path to a file was expected, but not present.")
382
428
 
383
429
  # Load metadata.
384
- self.load_metadata()
385
-
386
- # Read
387
- dcm = dcmread(self.file_path, stop_before_pixels=False, force=True)
388
- image_data = dcm.pixel_array.astype(np.float32)
430
+ self.load_metadata(include_image=True)
431
+ image_data = self.image_metadata.pixel_array.astype(np.float32)
389
432
 
390
433
  # Update data with scale and intercept. These may change per slice.
391
- rescale_intercept = get_pydicom_meta_tag(dcm_seq=dcm, tag=(0x0028, 0x1052), tag_type="float", default=0.0)
392
- rescale_slope = get_pydicom_meta_tag(dcm_seq=dcm, tag=(0x0028, 0x1053), tag_type="float", default=1.0)
434
+ rescale_intercept = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0028, 0x1052), tag_type="float", default=0.0)
435
+ rescale_slope = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0028, 0x1053), tag_type="float", default=1.0)
393
436
  image_data = image_data * rescale_slope + rescale_intercept
394
437
 
395
438
  return image_data
396
439
 
440
+ @staticmethod
441
+ def _get_limited_metadata_tags():
442
+ # Limited tags are read to populate basic
443
+ return [
444
+ (0x0008, 0x0018), # SOP instance UID
445
+ (0x0008, 0x0060), # modality
446
+ (0x0008, 0x1030), # series description
447
+ (0x0008, 0x103E), # study description
448
+ (0x0010, 0x0010), # patient name
449
+ (0x0010, 0x0020), # patient id
450
+ (0x0018, 0x0050), # slice thickness
451
+ (0x0020, 0x000E), # series instance UID
452
+ (0x0020, 0x0010), # study id
453
+ (0x0020, 0x0032), # origin
454
+ (0x0020, 0x0037), # orientation
455
+ (0x0020, 0x0052), # frame of reference UID
456
+ (0x0028, 0x0008), # number of frames
457
+ (0x0028, 0x0010), # pixel rows
458
+ (0x0028, 0x0011), # pixel columns
459
+ (0x0028, 0x0030), # pixel spacing
460
+ (0x3004, 0x000C) # grid frame offset vector
461
+ ]
462
+
463
+ def _get_acquisition_start_time(self) -> datetime.datetime:
464
+ self.load_metadata()
465
+
466
+ # Start of image acquisition. Prefer Acquisition Datetime (0x0008, 0x002A).
467
+ acquisition_ref_time = get_pydicom_meta_tag(
468
+ dcm_seq=self.image_metadata,
469
+ tag=(0x0008, 0x002A),
470
+ tag_type="str"
471
+ )
472
+ acquisition_ref_time = convert_dicom_time(datetime_str=acquisition_ref_time)
473
+
474
+ # Fall back to Acquisition Date (0x0008, 0x002A) and Acquisition Time (0x0008, 0x0032).
475
+ if acquisition_ref_time is None:
476
+ acquisition_start_date = get_pydicom_meta_tag(
477
+ dcm_seq=self.image_metadata,
478
+ tag=(0x0008, 0x0022),
479
+ tag_type="str"
480
+ )
481
+ acquisition_start_time = get_pydicom_meta_tag(
482
+ dcm_seq=self.image_metadata,
483
+ tag=(0x0008, 0x0032),
484
+ tag_type="str"
485
+ )
486
+ acquisition_ref_time = convert_dicom_time(
487
+ date_str=acquisition_start_date,
488
+ time_str=acquisition_start_time
489
+ )
490
+
491
+ # Fall back to Private GE Acquisition DateTime (0x0009, 0x100d).
492
+ if acquisition_ref_time is None:
493
+ acquisition_ref_time = get_pydicom_meta_tag(
494
+ dcm_seq=self.image_metadata,
495
+ tag=(0x0009, 0x100d),
496
+ tag_type="str"
497
+ )
498
+ acquisition_ref_time = convert_dicom_time(datetime_str=acquisition_ref_time)
499
+
500
+ # Fall back to Series Date and Series Time (
501
+ if acquisition_ref_time is None:
502
+ acquisition_start_date = get_pydicom_meta_tag(
503
+ dcm_seq=self.image_metadata,
504
+ tag=(0x0008, 0x0021),
505
+ tag_type="str"
506
+ )
507
+ acquisition_start_time = get_pydicom_meta_tag(
508
+ dcm_seq=self.image_metadata,
509
+ tag=(0x0008, 0x0031),
510
+ tag_type="str"
511
+ )
512
+ acquisition_ref_time = convert_dicom_time(
513
+ date_str=acquisition_start_date,
514
+ time_str=acquisition_start_time
515
+ )
516
+
517
+ # Final check.
518
+ if acquisition_ref_time is None:
519
+ raise ValueError(f"Acquisition start time cannot be determined from DICOM metadata in {self.file_path}.")
520
+
521
+ return acquisition_ref_time
522
+
397
523
 
398
524
  class MaskDicomFile(ImageDicomFile, MaskFile):
399
525
  def __init__(self, **kwargs):
@@ -430,7 +556,7 @@ class MaskDicomFile(ImageDicomFile, MaskFile):
430
556
  from mirp._data_import.dicom_file_seg import MaskDicomFileSEG
431
557
 
432
558
  # Load metadata so that the modality tag can be read.
433
- self.load_metadata()
559
+ self.load_metadata(limited=True)
434
560
 
435
561
  modality = get_pydicom_meta_tag(dcm_seq=self.image_metadata, tag=(0x0008, 0x0060), tag_type="str").lower()
436
562
 
@@ -442,10 +568,9 @@ class MaskDicomFile(ImageDicomFile, MaskFile):
442
568
  elif modality == "seg":
443
569
  file_class = MaskDicomFileSEG
444
570
  else:
445
- # This will return a base class, which will fail to pass the modality check.
446
- return self
571
+ return None
447
572
 
448
- return file_class(
573
+ mask = file_class(
449
574
  file_path=self.file_path,
450
575
  dir_path=self.dir_path,
451
576
  sample_name=self.sample_name,
@@ -460,3 +585,17 @@ class MaskDicomFile(ImageDicomFile, MaskFile):
460
585
  image_dimensions=self.image_dimension,
461
586
  roi_name=self.roi_name
462
587
  )
588
+
589
+ # Set metadata of mask.
590
+ mask.image_metadata = self.image_metadata
591
+ mask.is_limited_metadata = self.is_limited_metadata
592
+
593
+ return mask
594
+
595
+ def _get_limited_metadata_tags(self):
596
+ tags = super()._get_limited_metadata_tags()
597
+
598
+ tags += [
599
+ (0x3006, 0x0020), # Structure set roi sequence
600
+ (0x0028, 0x0008) # number of frames
601
+ ]