Article
healthcaremedical-imagingradiologycomputer-visiondicompacs-integrationpydicompynetdicom
Analyze DICOM Images with Medical Imaging Analyzer
Use the Medical Imaging Analyzer to automatically detect and measure anomalies in medical images. This agent integrates with your PACS, analyzes DICOM files from CT, MRI, and X-ray, and flags high-priority cases for radiologist review, streamlining diagnostic workflows.
intermediate30 min4 steps
The play
- Prepare DICOM StudyEnsure your medical imaging study is in the standard DICOM format. The Medical Imaging Analyzer processes raw DICOM data. You can use a library like `pydicom` in Python to inspect and verify the metadata of your files before sending them.
- Send Study to PACSTransfer the DICOM study to your Picture Archiving and Communication System (PACS). The Medical Imaging Analyzer is integrated with your PACS and monitors the worklist for new studies that match its configured profile (e.g., 'CT Chest'). Use a standard DICOM push utility.
- Trigger Automated AnalysisOnce the study is on the PACS, the Medical Imaging Analyzer automatically fetches it for processing. The analysis runs in the background, applying its deep learning models to detect anomalies, measure lesions, and check for other configured findings. No manual action is required.
- Review Structured FindingsOpen the study in your DICOM viewer. The Medical Imaging Analyzer overlays its findings on the original images and generates a structured report. This includes lesion measurements, anomaly flags, and links to the exact slice where a finding was located, prioritizing your worklist.
Starter code
import pydicom
from pydicom.dataset import Dataset, FileMetaDataset
from pydicom.uid import ImplicitVRLittleEndian
import pynetdicom
import numpy as np
import os
# 1. Create a synthetic DICOM file for testing
print("Creating a synthetic DICOM file...")
file_meta = FileMetaDataset()
file_meta.MediaStorageSOPClassUID = pydicom.uid.CTImageStorage
file_meta.MediaStorageSOPInstanceUID = pydicom.uid.generate_uid()
file_meta.ImplementationClassUID = pydicom.uid.PYNETDICOM_IMPLEMENTATION_UID
file_meta.TransferSyntaxUID = ImplicitVRLittleEndian
ds = Dataset()
ds.file_meta = file_meta
ds.PatientName = "Test^Patient"
ds.PatientID = "123456"
ds.Modality = "CT"
ds.StudyInstanceUID = pydicom.uid.generate_uid()
ds.SeriesInstanceUID = pydicom.uid.generate_uid()
ds.SOPInstanceUID = file_meta.MediaStorageSOPInstanceUID
ds.SOPClassUID = file_meta.MediaStorageSOPClassUID
ds.Rows = 128
ds.Columns = 128
ds.SamplesPerPixel = 1
ds.PhotometricInterpretation = "MONOCHROME2"
ds.PixelRepresentation = 0
ds.BitsAllocated = 16
ds.BitsStored = 16
ds.HighBit = 15
# Create a 128x128 numpy array for pixel data
pixel_array = np.arange(128 * 128, dtype=np.uint16).reshape((128, 128))
ds.PixelData = pixel_array.tobytes()
filename = "synthetic_ct.dcm"
ds.save_as(filename, write_like_original=False)
print(f"Saved as {filename}")
# 2. Send the DICOM file to a PACS server (DICOM SCP)
# NOTE: This requires a DICOM SCP (server) running and listening.
# You can use a tool like Orthanc or Conquest for a test environment.
AE = pynetdicom.AE(ae_title=b'MY_CT_SCU')
AE.add_requested_context(pydicom.uid.CTImageStorage)
# Association with the PACS server
# Replace '127.0.0.1' and 11112 with your PACS IP and port
pacs_ip = '127.0.0.1'
pacs_port = 11112
assoc = AE.associate(pacs_ip, pacs_port, ae_title=b'ORTHANC')
if assoc.is_established:
print('Association accepted by the peer')
# Use the C-STORE service to send the dataset
status = assoc.send_c_store(ds)
if status:
# If the send is successful, the status will be returned with `Status` 0x0000
print('C-STORE request status: 0x{0:04x}'.format(status.Status))
else:
print('Connection timed out, was aborted or received invalid response')
# Release the association
assoc.release()
else:
print(f'Association failed: no response from {pacs_ip}:{pacs_port}')
# Clean up the created file
os.remove(filename)