inspect_dicom¶
Returns a JSON-serialisable dict with structural metadata for a .dcm file or a series directory. Patient identifiers are stripped from the output by default.
Signature¶
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
file_path |
str or Path |
required | Path to a .dcm file or a directory containing .dcm slices |
include_phi |
bool |
False |
When True, patient identifiers are included in the result. Treat the output as PHI if you enable this. |
Return value¶
PHI fields stripped by default¶
The following tags are removed unless include_phi=True:
PatientName, PatientID, PatientBirthDate, PatientSex, PatientAge, AccessionNumber, ReferringPhysicianName, InstitutionName, StudyDate, StudyTime, and more.
See voxelkit/dicom/phi.py for the full list.
Examples¶
from voxelkit import inspect_dicom
# Single file
result = inspect_dicom("scan.dcm")
print(result["shape"]) # [512, 512]
print(result["modality"]) # "CT"
# Series directory
result = inspect_dicom("./series/")
print(result["source"]) # "series"
print(result["slice_count"]) # 128
# With PHI (handle the result carefully)
result = inspect_dicom("scan.dcm", include_phi=True)
print(result["patient_id"])
You can also call inspect_file on a .dcm path and it routes here automatically. The include_phi parameter is the main reason to call inspect_dicom directly instead.