Overview
This tool provides a powerful and flexible solution for reorganizing DICOM files into a BIDS-compliant structure. Leveraging the performance of Rust and the ease of integration with Python, it efficiently handles large DICOM datasets.
Key Features
- BIDS Compliance: Ensures reorganized files adhere to the Brain Imaging Data Structure (BIDS) standard, promoting data sharing and interoperability.
- Rust-Powered Performance: Benefits from Rust's speed and safe memory management for fast reorganization, especially with large datasets.
- Python Integration: Seamlessly integrates into your existing Python analysis workflows using the
pyo3
bridge. - Customization: Supports flexible configuration through the input CSV file, allowing you to map custom DICOM metadata to BIDS elements.
- Parallel Processing: Efficiently reorganizes multiple DICOM files concurrently using Rayon.
Requirements
- Rust: Installation via
rustup
is recommended (https://www.rust-lang.org/tools/install). - Python: A suitable Python environment.
- Dependencies:
pyo3
rayon
csv
anyhow
Installation
-
Clone or download the repository:
git clone https://github.com/NeuroGranberg/dicom_reorganizer.git
-
Install Rust dependencies:
cd dicom-reorganizer cargo install --path .
-
Build the Python package:
maturin develop # or maturin build --release
-
Install the generated Python package:
pip install target/wheels/<wheel_name>.whl
or simply download the weel from this repo target/wheels/ and install it:
pip install dicom_reorganizer-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl # or the name of the downlaoded weel
The tool requires a CSV file containing the following information about your DICOM files:
- subject_name: Subject or patient name.
- session_date: Date of the imaging session.
- dicom_type: Type of DICOM data (e.g., 'anat', 'func', 'dwi', etc.).
- current_path: Current file path of the DICOM file.
You can generate this CSV file using a DICOM metadata extraction tool like Dicom Metadata Extractor.
Usage
import dicom_reorganizer
csv_path = 'path/to/your/dicom_metadata.csv'
root_name = 'path/to/bids/dataset'
columns = {
"subject_name": "SubjectID", # Adjust column names as needed
"session_date": "AcquisitionDate",
"dicom_type": "DicomType",
"current_path": "DicomPath",
}
copy_files = True # Set to False if you want to move files instead of copying
dicom_reorganizer.reorganize_dicoms(csv_path, root_name, columns, copy_files)
Example CSV Structure
subject_name,session_date,dicom_type,current_path
sub-01,2023-11-23,anat,/home/user/dicoms/sub-01/T1.dcm
sub-01,2023-11-23,func,/home/user/dicoms/sub-01/rest_bold.dcm
...
Contributing
I welcome contributions! Feel free to open issues, submit pull requests, or suggest new features.
License
This project is licensed under MIT.