项目作者: djib2011

项目描述 :
Thanos' DICOM package
高级语言: Python
项目地址: git://github.com/djib2011/thicom.git
创建时间: 2018-11-22T23:13:15Z
项目社区:https://github.com/djib2011/thicom

开源协议:MIT License

下载


thicom

(thanos’ DICOM package)

Simple manipulation of DICOM images. Wrapper to python’s pydicom package. Intended for self-use.

In order to get the best results please follow the suggested directory structure:

  1. patients
  2. |__patient1
  3. | |__DICOMDIR
  4. | |__random_dicom_folder1
  5. | | |__compressed_image1.dcm
  6. | | |__compressed_image2.dcm
  7. | | |__ ...
  8. | |__random_dicom_folder2
  9. | | |__compressed_imageN.dcm
  10. | | |__ ...
  11. | |__ ...
  12. |
  13. |__patient2
  14. | |__DICOMDIR
  15. | |__random_dicom_folder
  16. | | |__random_dicom_subfolder1
  17. | | | |__image1.dcm
  18. | | | |__ ...
  19. | | |__random_dicom_subfolder2
  20. | | | |__ ...
  21. | | |__ ...
  22. | |__ ...
  23. |__ ...

Quick Start

Import this package:

  1. import thicom
  2. dcm = 'path/to/dicom/image.dcm'
  3. pt = 'path/to/patients/parent/directory/'
  • To view a DICOM image dcm:
    1. thicom.view(dcm)
  • To view all DICOM images in the CWD as an animation:
  1. thicom.view()
  • To decompress compressed all DICOM images under path pt:
  1. pt = 'images/dicom/'
  2. thicom.decompress(pt)
  • To convert all DICOM images under path pt to .png:
  1. thicom.to_png(pt)
  • To anonymize all patients under path pt:
  1. thicom.anonymize(pt)
  • To search for DICOM images, DICOMDIR or both under path pt:
  1. thicom.find_dcm(pt) # looks for DICOM images
  2. thicom.find_dcmdir(pt) # looks for DICOMDIR
  3. thicom.find_all(pt) # looks for all DICOM files
  4. thicom.find_png(pt) # looks for png images
  • To check if files are in DICOM format:
  1. f = 'files/random_file'
  2. thicom.is_dicom(f)
  3. files = ['files/random_file1', 'files/random_file2', 'files/random_file3']
  4. thicom.is_dicom(files)
  5. # Will return True if all files are in DICOM format
  6. thicom.is_dicom(files, same_size=True)
  7. # Will return a list with the same size as files (e.g. [True, True, False])
  • To check if the directory pt satisfies the requirements for processing:
  1. thicom.pre_check(pt)
  • To process all files in the directory pt (will also perform a pre_check):
  1. thicom.preprocess(pt)

By default all functions use the CWD as their default argument.

Requirements:

  • numpy, scipy, matplotlib
  • pydicom
  • tqdm
  • In case of compressed DICOM files:
    a linux distribution and the GDCM package installed (gdcmconv tool)

Module description:

  1. components
    Module containing useful functions required bu multiple other modules in the package.
    E.g. it contains functions that search a directory for dicom files and png images.

  2. anonymizer
    This module handles mapping patients’ real names with aliases and storing the map (called an anonymizer dictionary).
    Has the option of updating a previously created map.

  3. decomp
    Some dicom images are compressed through lossless-JPEG compression and can’t be handled by python’s dicom package.
    This module uses linux’s “gdcmconv” tool for decompressing the images.

  4. converter
    converter handles converting one or more dicom images to png ones.
    It preserves all useful metadata (besides of the patient’s) name which is anonymized (through anonymizer).
    It can handle dicom files storing multiple images and uses decomp to decompress compressed dicom files.
    Besides saving the image, it can also show one or more dicom images to the screen.

  5. preprocess
    Module that handles all necessary preprocessing steps to initialize or update a database of subjects.
    First it performes a compatibility check to see if the directory has the desired structure. It searches for:
    (a) patients with DaT scans in dicom format (with a DICOMDIR)
    (b) patients without MRI DICOMDIRs
    (c) multiple MRI DICOMDIRs for a single patient
    (d) wrong directory structure (e.g NPD/Patient/MRI/DICOMDIR instead of NPD/Patient/DICOMDIR)
    (e) wrong directory name (D.Patient, D1 Patient, D1a Patient, etc.)
    Some of these issues can be fixed automatically. Afterwards it will create and apply an anonymization scheme
    (using anonymizer), convert all DICOM images to png (while generating all necessary log files) with converter,
    structure the directories according to the scheme while removing any obsolete file. Then it searches for all MRIs
    containing T1 in their name and stores them in a separate directory.

  6. augment
    This module is meant to be used for generating a training and test set from a series of Dat scan and MRI images.
    First all MRIs and Dat scans are gathered, separately for positive and negative patients. MRIs from different
    patients are separated by '-------------'. Then a sliding window technique is applied to the MRIs as shown in
    the following example (for a window size of 3):

    1. # Before the application of the window:
    2. MRIs = [1.png, 2.png, 3.png, 4.png, 5.png, 6.png, '-------------', 11.png, 12.png, 13.png, 14.png]
    3. # After the application of the window:
    4. MRIs = [1.png, 2.png, 3.png, 4.png, 2.png, 3.png, 4.png, 3.png, 4.png, 5.png, 4.png, 5.png, 6.png, 11.png, 12.png,
    5. 13.png,12.png, 13.png, 14.png]

    Note that windows do overlap but not over separate patients!

    After applying the window to the MRIs, each of those windows is combined to a different DaT scan. All possible
    combinations are generated; PD and NPD patients are not mixed together.

    Finally the data is split into a training and test set according to a given ratio and shuffled through
    numpy.random.

Directory structure

Before processing the directories should have the following structure:

  1. parent_directory
  2. |__positive
  3. | |__patient1
  4. | | |__DICOMDIR
  5. | | |__random_dicom_folder1
  6. | | | |__compressed_image1.dcm
  7. | | | |__compressed_image2.dcm
  8. | |__patient2
  9. | |__ ...
  10. |
  11. |__negative
  12. |__patient3
  13. |__patient4
  14. |__ ...

After preprocessing the directory will look like this:

  1. parent_directory
  2. |__positive
  3. | |__subject1
  4. | | |__1.MRI
  5. | | | |__SeriesDescription_InstanceNumber.png
  6. | | | |__SeriesDescription_InstanceNumber.png
  7. | |__subject2
  8. | |__ ...
  9. |
  10. |__negative
  11. | |__subject3
  12. | |__subject4
  13. | |__ ...
  14. |__logs
  15. | |__anonymizer_dictionary.pkl
  16. | |__conversion_log_anon.txt
  17. | |__patient aliases.txt
  18. | |__patient log.txt
  19. | |__ ...
  20. |__selection
  21. |__positive
  22. | |__MRI
  23. | |__T1_MRI_1.png
  24. | |__T1_MRI_2.png
  25. | |__ ...
  26. |__negative
  27. |__MRI
  28. |__T1_MRI_1.png
  29. |__T1_MRI_2.png
  30. |__ ...

Associated publications:

  • Tagaris, A., Kollias, D., Stafylopatis, A., Tagaris, G., & Kollias, S. (2018). Machine Learning for Neurodegenerative Disorder Diagnosis—Survey of Practices and Launch of Benchmark Dataset. International Journal on Artificial Intelligence Tools, 27(03), 1850011.
  • Tagaris, A., Kollias, D., & Stafylopatis, A. (2017, August). Assessment of Parkinson’s disease based on deep neural networks. In International Conference on Engineering Applications of Neural Networks (pp. 391-403). Springer, Cham.
  • Kollias, D., Tagaris, A., Stafylopatis, A., Kollias, S., & Tagaris, G. (2018). Deep neural architectures for prediction in healthcare. Complex & Intelligent Systems, 4(2), 119-131.
  • Kollias, D., Yu, M., Tagaris, A., Leontidis, G., Stafylopatis, A., & Kollias, S. (2017, November). Adaptation and contextualization of deep neural network models. In Computational Intelligence (SSCI), 2017 IEEE Symposium Series on (pp. 1-8). IEEE.
  • Vlachostergiou, A., Tagaris, A., Stafylopatis, A., & Kollias, S. (2018, October). Multi-Task Learning for Predicting Parkinson’s Disease Based on Medical Imaging Information. In 2018 25th IEEE International Conference on Image Processing (ICIP) (pp. 2052-2056). IEEE.
  • Vlachostergiou, A., Tagaris, A., Stafylopatis, A., & Kollias, S. (2018, October). Investigating the Best Performing Task Conditions of a Multi-Tasking Learning Model in Healthcare Using Convolutional Neural Networks: Evidence from a Parkinson’S Disease Database. In 2018 25th IEEE International Conference on Image Processing (ICIP) (pp. 2047-2051). IEEE.