This project provides Python-based batch image export scripts for PACS servers compliant with the DICOM protocol. It enables efficient extraction and management of medical images, making it ideal for data science projects and AI research that require large-scale medical imaging datasets.
This project is based on the excellent work of pydicom-batch by @therlaup. The original project provided the foundation and inspiration for this implementation. We've adapted and restructured the codebase while maintaining the core functionality and robustness of the original work.
- DICOM C-FIND queries for discovering available images
- DICOM C-MOVE operations for image retrieval
- Configurable batch operations via YAML files
- CSV-based batch request management
- Support for data anonymization
- Flexible directory structure for exported files
- Python 3.12.1
- Access to a DICOM-compliant PACS server
- Network connectivity to the PACS server
- Proper firewall configuration for DICOM communication
- Create and activate a Conda environment:
conda create --name pydicom-batch python=3.12.1
conda activate pydicom-batch- Install required packages:
pip install -r requirements.txtIf not running in a container with port forwarding, configure your firewall to allow communication with the PACS server (example for port 4000).:
# Add TCP port
sudo firewall-cmd --add-port=4000/tcp --permanent
# Add UDP port (if needed)
sudo firewall-cmd --add-port=4000/udp --permanent
# Reload firewall
sudo firewall-cmd --reload
# Verify ports
sudo firewall-cmd --list-ports- Copy the template configuration:
cp config/dicom-template.yml.example config/dicom.yml- Edit
config/dicom.ymlwith your specific PACS server settings:- PACS server hostname/IP
- Port numbers
- Application Entity Titles (AET)
- Query parameters
Run the main script:
python main.pyconfig/- Configuration files and templatesdata/- Storage for exported DICOM files and databasesscu.py- Service Class User implementationscp.py- Service Class Provider implementationmain.py- Main execution scriptcommon.py- Shared utilities and functions
The project is built on top of:
- Pydicom - DICOM file handling
- Pynetdicom - DICOM networking protocol
DICOM communication involves:
- SCU (Service Class User) - Generates requests
- SCP (Service Class Provider) - Responds to requests
- AE (Application Entity) - Unique identifiers for DICOM nodes
- Operations: C-FIND (query), C-MOVE (transfer), C-STORE (storage)
Contributions are welcome! Please feel free to submit pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.