Metadata-Version: 2.4
Name: medicalimageanalysis
Version: 2.1.89
Summary: Reads in medical images and structures them into 3D arrays with associated ROI/POIs if they exist.
Author-email: Caleb OConnor <csoconnor@mdanderson.org>
License: GNU Affero General Public License v3
Project-URL: Homepage, https://github.com/caleb-oconnor/MedicalImageAnalysis
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: asttokens==3.0.0
Requires-Dist: attrs==25.1.0
Requires-Dist: backcall==0.2.0
Requires-Dist: beautifulsoup4==4.13.3
Requires-Dist: bleach==6.2.0
Requires-Dist: certifi==2025.1.31
Requires-Dist: charset-normalizer==3.4.1
Requires-Dist: colorama==0.4.6
Requires-Dist: contourpy>=1.3.1
Requires-Dist: cycler==0.12.1
Requires-Dist: decorator==5.2.1
Requires-Dist: defusedxml==0.7.1
Requires-Dist: docopt==0.6.2
Requires-Dist: executing==2.2.0
Requires-Dist: fastjsonschema==2.21.1
Requires-Dist: fonttools==4.56.0
Requires-Dist: idna==3.10
Requires-Dist: importlib_resources==6.5.2
Requires-Dist: ipython==8.12.3
Requires-Dist: jedi==0.19.2
Requires-Dist: Jinja2==3.1.6
Requires-Dist: jsonschema==4.23.0
Requires-Dist: jsonschema-specifications==2024.10.1
Requires-Dist: jupyter_client==8.6.3
Requires-Dist: jupyter_core==5.9.1
Requires-Dist: jupyterlab_pygments==0.3.0
Requires-Dist: kiwisolver==1.4.8
Requires-Dist: MarkupSafe==3.0.2
Requires-Dist: matplotlib==3.10.1
Requires-Dist: matplotlib-inline==0.1.7
Requires-Dist: mistune==3.1.2
Requires-Dist: nbclient==0.10.2
Requires-Dist: nbconvert==7.16.6
Requires-Dist: nbformat==5.10.4
Requires-Dist: nibabel==5.3.2
Requires-Dist: numpy>=2.2.3
Requires-Dist: open3d==0.19.0
Requires-Dist: opencv-python==4.11.0.86
Requires-Dist: openpyxl==3.1.5
Requires-Dist: packaging==24.2
Requires-Dist: pandas>=2.2.3
Requires-Dist: pandocfilters==1.5.1
Requires-Dist: parso==0.8.4
Requires-Dist: pickleshare==0.7.5
Requires-Dist: pillow==11.1.0
Requires-Dist: pipreqs==0.5.0
Requires-Dist: platformdirs==4.3.6
Requires-Dist: pooch==1.8.2
Requires-Dist: prompt_toolkit==3.0.50
Requires-Dist: psutil==7.0.0
Requires-Dist: pure_eval==0.2.3
Requires-Dist: pyacvd==0.3.1
Requires-Dist: pydicom==3.0.1
Requires-Dist: Pygments==2.19.1
Requires-Dist: pykdtree==1.4.1
Requires-Dist: pylibjpeg==2.0.1
Requires-Dist: pylibjpeg-libjpeg==2.3.0
Requires-Dist: pymeshfix>=0.17.0
Requires-Dist: pyparsing==3.2.1
Requires-Dist: pytetwild==0.1.dev1
Requires-Dist: python-dateutil==2.9.0.post0
Requires-Dist: python-gdcm==3.0.24.1
Requires-Dist: pytz==2025.1
Requires-Dist: pyvista==0.44.2
Requires-Dist: pyzmq==26.2.1
Requires-Dist: referencing==0.36.2
Requires-Dist: requests>=2.32.5
Requires-Dist: rpds-py==0.23.1
Requires-Dist: scikit-image==0.25.0
Requires-Dist: scipy==1.15.2
Requires-Dist: scooby==0.10.0
Requires-Dist: SimpleITK==2.4.1
Requires-Dist: six==1.17.0
Requires-Dist: soupsieve==2.6
Requires-Dist: stack-data==0.6.3
Requires-Dist: tinycss2==1.4.0
Requires-Dist: tornado==6.5.2
Requires-Dist: traitlets==5.14.3
Requires-Dist: typing_extensions==4.12.2
Requires-Dist: tzdata==2025.1
Requires-Dist: urllib3==2.5.0
Requires-Dist: vtk==9.3.1
Requires-Dist: wcwidth==0.2.13
Requires-Dist: webencodings==0.5.1
Requires-Dist: yarg==0.1.9
Dynamic: license-file


# MedicalImageAnalysis

*MedicalImageAnalysis* is a comprehensive Python toolkit for managing and analyzing medical imaging data.
It can read unorganized DICOM and RTSTRUCTs files, automatically organizing them into separate image instances.
The platform supports both 2D and 3D modalities, with the ability to convert 2D contours to 3D surface meshes and 
vice versa. It also provides rigid registration between images, along with a variety of standard image processing 
techniques, enabling seamless integration into research and clinical workflows. There are additional reader file
types for stl and 3mf, where a fake image is generated based on the boundary of the input mesh.

The module currently imports 6 different modalities:
1. CT
2. MR
3. US
4. RF
5. DX
6. RTSTRUCT

CT and MR images will be converted to Feet-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 100s of different 
patient folders because you could possibly run out of RAM. Also, this module does 
not distinguish between patient IDs or patient names, it will make an image instance for each image regardless
of patient id/name.


## Reader (Dicom)
The reader works by inputting a file path or a list of files. The files are read and split by modality, series instance 
uid, acquisition number (if it exists), and image orientation matrix. An image class instance is generated for each 
image. If an RTSTRUCT exist, it will match with an existing imported image, right now there is no method for importing
an RTSTRUCT that doesn't have a corresponding image. The match image class contains a ROI dictionary variable that will
create a ROI instance for each imported ROI name (the same process exists for POIs).

## Utils
The utils folder contains useful meshing, image conversion, and registration techniques. It doesn't require the images 
to be read in using the reader class or have image or ROI classes based on the reader, it exists completely independent.


## Installation
Using [pip](https://pip.pypa.io/en/stable/):
```
pip install medicalimageanalysis
```

During install there can be an error with a jupyter dependency file path containing over 260 characters exceeding windows 
limit. This can be resolved by enabling long paths on Windows or simply trying to install again, it will skip the 
package causing the error. 

## Reader Example 1
The user sets a path to the folder containing the dicom files or highest level folder with subfolders containing dicom
files.

```python
import medicalimageanalysis as mia

path = r'/path/to/folder'

mia.read_dicoms(folder_path=path)

```

## Reader Example 2
The user has more options if they are specifics requirements.
1. file_list - if the user already has the files wanted to read in, must be in type list
2. exclude_files - if the user wants to not read certain files
3. only_tags - does not read in the pixel array just the tags
4. only_modality - specify which modalities to read in, if not then all modalities will be read
5. only_load_roi_names - will only load rois with input name

Note: if *folder_path* and *file_list* are both input, then *folder_path* will be used and not both.

```python
import medicalimageanalysis as mia

file_list = ['filepath1.dcm', 'filepath2.dcm', ...]
exclude_files = ['filepath10.dcm', 'filepath11.dcm', ...]

mia.read_dicoms(file_list=file_list, exclude_files=exclude_files, only_tags=True, only_modality=['CT'],
                only_load_roi_names=['Liver', 'Tumor'])

```

## Retrieve image and tags:
The images are stored in a list. Each image instance contains a 3D array (None if *only_tags=True*), all tag information
and popular tags have their own respective variable.

Note: Even 2D images will contain a 3D array, along with a fake slice thickness of 1 mm.

```python
import medicalimageanalysis as mia

path = r'/path/to/folder'

mia.read_dicoms(folder_path=path)

image_list = mia.Data.image_list
image = mia.Data[image_list[0]]

array = image.array
tags = image.tags  # list of all the tags, for 100 slice CT scan the tags list would be 0-99 each containing a dict

name = image.patient_name  # or tags[0].PatientName
spacing = image.spacing  # inplane spacing followed by slice thickness

```

Instance variables:
<span style="font-size:.9em;">base_position, date, dimensions,
filepaths, frame_ref, image_matrix, mrn, orientation, 
origin, patient_name, plane, pois,
rgb, rois, sections, series_uid, skipped_slice, 
sops, spacing, tags, time, unverified</span>

## Retrieve ROI/POIs:
Each image contains a roi and poi dictionary, if a RTSTRUCT file associates with an image then each ROI/POI is added to
respective image dictionary.

```python
import medicalimageanalysis as mia

path = r'/path/to/folder'

reader = mia.Reader(folder_path=path)
reader.read_dicoms()

image_list = mia.Data.image_list
image = mia.Data[image_list[0]]

roi_names = mia.Data.roi_list
roi = image.rois[roi_names[0]]
contour_position = roi.contour_position

poi_names = mia.Data.poi_list
poi = image.rois[poi_names[0]]
point_position = poi.point_position

```
