This project was developed with the assistance of Claude, an AI assistant by Anthropic.
This guide provides detailed instructions on how to convert Sectra PACS annotations from DICOM files to QuPath-compatible format and work with them effectively in your pathology workflow.
The workflow consists of two main steps:
pip install pydicom geojson numpy openslide-python Pillow
Save the sectra_dicom_to_qupath.py
script to a convenient location on your computer.
Open a terminal or command prompt and run:
python sectra_dicom_to_qupath.py -i path/to/your/annotations.dcm -o output.geojson
D:\\DigitalPathologyDrafts\\.venv\\Scripts\\python.exe ./sectra-qupath/sectra_dicom_to_qupath.py -i "G:\svss-wsis\annotation\all_annotations_label\ANONHR1KQJ17P_1_1.svs.graphics.2025-02-10_14-04-34.dcm" -o "G:\svss-wsis\annotation\all_annotations_label\ANONHR1KQJ17P_1_1.svs.graphics.2025-02-10_14-04-34.geojson"
For more accurate coordinate mapping, provide the source image file:
python sectra_dicom_to_qupath.py -i path/to/your/annotations.dcm -o output.geojson -s path/to/source.svs
D:\\DigitalPathologyDrafts\\.venv\\Scripts\\python.exe ./sectra-qupath/sectra_dicom_to_qupath.py -i "G:\svss-wsis\annotation\all_annotations_label\ANONHR1KQJ17P_1_1.svs.graphics.2025-02-10_14-04-34.dcm" -o "G:\svss-wsis\annotation\all_annotations_label\ANONHR1KQJ17P_1_1.svs.graphics.2025-02-10_14-04-34.geojson" -s "G:\svss-wsis\annotation\all_annotations_label\ANONHR1KQJ17P_1_1-004.svs"
-i, --input
: Required. Path to the input DICOM file.-o, --output
: Optional. Path to the output GeoJSON file. If not specified, the output file will be created in the same location as the input file with a .geojson extension.-s, --source
: Optional. Path to the source image file. This helps in accurately scaling the coordinates.import_sectra_annotations_enhanced.groovy
into the script editorTo use annotations for tile extraction:
// Example script to extract tiles from annotations
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.regions.RegionRequest
import qupath.lib.images.servers.ImageServer
// Get the image server
def server = getCurrentImageData().getServer()
// Get all annotations
def annotations = getAnnotationObjects()
// Define tile size
int tileWidth = 512
int tileHeight = 512
double downsample = 1.0
// Create tile directory
def path = buildFilePath(PROJECT_BASE_DIR, 'tiles')
mkdirs(path)
// Extract tiles for each annotation
annotations.eachWithIndex { annotation, i ->
def roi = annotation.getROI()
def region = RegionRequest.createInstance(server.getPath(), downsample, roi)
def img = server.readRegion(region)
def tilePath = buildFilePath(path, "tile_${i}.png")
writeImage(img, tilePath)
}
pip install pydicom geojson numpy
dcminfo
command to verify the file: python -c "import pydicom; print(pydicom.dcmread('your_file.dcm'))"
-s path/to/source.svs
extract_graphic_objects
function to handle additional graphic typescreate_geojson_feature
getColorForAnnotation
functionFor processing multiple DICOM files, you can create a simple batch script:
#!/bin/bash
# Batch process multiple DICOM files
for dcm_file in /path/to/dicom/files/*.dcm; do
base_name=$(basename "$dcm_file" .dcm)
svs_file="/path/to/svs/files/${base_name}.svs"
output_file="/path/to/output/folder/${base_name}.geojson"
python sectra_dicom_to_qupath.py -i "$dcm_file" -o "$output_file" -s "$svs_file"
done
In QuPath, you can modify the script to batch process entire projects by iterating through all images in the project.
By following this guide, you can seamlessly integrate Sectra PACS annotations into your QuPath workflow. These tools allow you to preserve all the annotation information including measurements, types, and labels, making them available for further analysis in QuPath.
The provided scripts handle the most common annotation types and measurements, but can be customized to meet specific needs if required.