Skip to main content

Reads in medical images and converts them into numpy arrays.

Project description

MedicalImageConverter

MedicalImageConverter is a Python package for working with medical image files. It lets the user read in images or ROIs (regions of interest), and converts them to 3D numpy arrays. It also allows the user to input non-organized datasets (multiple images inside a single folder). Currently, this module only works for Dicom data with the hopes of expanding to other data formats in the future.

The module currently imports 9 different modalites and RTSTRUCT files. The accepted modalites are:

  1. CT
  2. MR
  3. US
  4. PT
  5. MG
  6. DX
  7. NM
  8. XA
  9. CR

The CT and MR modalities have been tested extensively, along with their respective ROIs. The other 7 modalities have been tested but only on a few datasets a piece. For RTSTRUCTS, only those referencing CT and MR have been tested.

The images will be converted to Head-First-Supine (if not so already), and the image position will be updated to reflect the needed rotations.

Disclaimer: All the files will be loaded into memory so be sure you have enough RAM available. Meaning don't select a folder path that contains 10s of different patient folders because you could possibly run out of RAM. Also, this module does not distinguish between patient IDs or patient names.

Installation

Using pip:

pip install MedicalImageConverter

Example

The user sets a path to the folder containing the dicom files. If the user already has each file path then they can continue to DicomReader, however if the user doesn't then use the file_parsar function. file_parsar will look through all the files inside the given file path and output a dictionary containing file paths for these types found:

  1. Dicom (.dcm)
  2. MetaHeader (.mhd)
  3. Raw (.raw)
  4. STL (.stl)

In the example below I used file_parsar, output the results into file_dictionary. Then the Dicom list was selected for the dictionary which was input into DicomReader class. Lastly, the data is then loaded in using load_dicom.

Note: The exclude_files allows the user not to get the file paths for any files inside the list, generally the user will use an empty list. The existing_image_info is required when the user is trying to load in an RTSTRUCT file only, some tags are needed for the image it references to create a 3D volume with the correct spacing.

import MedicalImageConverter as mic

path = r'/path/to/folder'

exclude_files = []
existing_image_info = None
file_dictionary = mic.file_parsar(path, exclude_files)
dicom_reader = mic.DicomReader(file_dictionary['Dicom'], existing_image_info)
dicom_reader.load_dicom()

Retrieve image information:

image_data = dicom_reader.get_image_data()  # Returns a list of 3D arrays containing each image
image_info = dicom_reader.get_image_info()  # Returns a pandas dataframe containing important tag information

Tags in image_info: FilePath, SOPInstanceUID, PatientID, PatientName, Modality, SeriesDescription, SeriesDate, SeriesTime, SeriesInstanceUID, SeriesNumber, AcquisitionNumber, SliceThickness, PixelSpacing, Rows, Columns, PatientPosition, ImagePositionPatient, ImageOrientationPatient, Slices, DefaultWindow, FullWindow

Retrieve ROI information:

roi_data = dicom_reader.get_roi_contour()  # Returns a list of lists containing each ROI contour per image
roi_info = dicom_reader.get_roi_info()  # Returns a pandas dataframe containing important tag information

Tags in roi_info: FilePath, RoiNames

Retrieve Sorted Files

ds_images = dicom_reader.get_ds_images()  # Returns a list of dicom files sorted into each image  

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medicalimageconverter-1.5.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

MedicalImageConverter-1.5-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file medicalimageconverter-1.5.tar.gz.

File metadata

  • Download URL: medicalimageconverter-1.5.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for medicalimageconverter-1.5.tar.gz
Algorithm Hash digest
SHA256 de7d0787e91c52cbd2d54ec0335a4433c125ae32b33f7c8a4a12ab02e1fb5763
MD5 e7ab4319365056c3bdf6430f50a4e624
BLAKE2b-256 91b3d64fd848fcbf181386f6c65bbe4634c6b836008039ae4022cf67d0410e57

See more details on using hashes here.

File details

Details for the file MedicalImageConverter-1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for MedicalImageConverter-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7307c78e85e2197df94b45abc710e21a1a8fe32e3f45687aa7f4456d3a105f56
MD5 db76233dd753409e37760ce472722f68
BLAKE2b-256 f7bf324d6aecc7650f2583b09e08626cacc25764625236d4e60d4ac6de31c64d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page