快捷搜索: 王者荣耀 脱发

DICOM学习(2)——python实现DICOM文件归档PACS服务器

DICOM是医学图像和相关信息的国际标准。 它定义了放射。心脏。放疗和其他医疗领域中媒体交换的格式和通讯协议。

pynetdicom是一个纯 python 程序,它实现了DICOM网络协议。 使用 ,插件获取地址:

主要用户类是 AE,它用于表示一个DICOM应用程序实体。 创建 AE 之后,通常你将:

    使用 AE.start() 作为SCP启动应用程序,并等待传入的关联请求 通过 AE.associate(addr, port) 方法请求与对等SCP的关联,将应用程序作为SCU使用。

一旦应用程序与对等点关联,就可以通过使用dimse服务(。请参阅DICOM标准 PS3.7, 节 7.5,9和 10 ) 在它们之间发送DICOM数据。

支持SCU服务

当AE充当 SCU,并且与对等SCP建立关联时,下列 dimse c 服务可用:

    c echo: Association.send_c_echo() 用于验证与对等方的end-to-end通信。 c 存储:Association.send_c_store(dataset) 请求对复合SOP实例数据集的存储。 查找:Association.send_c_find(dataset) 请求对等点搜索它的托管SOP实例,以便匹配与数据集中给定的属性相匹配的那些实例。 获取一个 Association.send_c_get(dataset) 实例实例集合,然后将这些匹配的实例返回到数据集,然后将这些匹配实例返回给 SCU。 c 移动: Association.send_c_move(dataset, move_aet) requests对等 search move_aet SOP dataset dataset dataset managed search search search。

支持SCP服务

当作为SCP时,在建立关联之后,下面的dimse c 服务对于对等方可以用。 除了 on_c_echo() 之外,用户还需要通过实现以下 AE 回调来处理所需的操作:

    c echo: AE.on_c_echo() c 存储:AE.on_c_store(dataset) c 查找:AE.on_c_find(dataset) 和 AE.on_c_find_cancel() c 获取:AE.on_c_get(dataset) 和 AE.on_c_get_cancel() c 移动:AE.on_c_move(dataset, move_aet) 和 AE.on_c_move_cancel()

下面的代码的主要工作是连接已有的PACS的AE,并用c_stroe实现CT/MR文件归档:

#coding=utf-8 from pydicom import dcmread

from pynetdicom import AE from pynetdicom.sop_class import CTImageStorage, MRImageStorage # Initialise the Application Entity ae = AE(ae_title=bWHTM-116)

# Add a requested presentation context ae.add_requested_context(CTImageStorage) ae.add_requested_context(MRImageStorage)

# Read in our DICOM CT dataset #ds = dcmread(E:codedicomMR.dcm) ds = dcmread(E:codedicomCT.dcm) # Associate with peer AE at IP 127.0.0.1 and port 11112 assoc = ae.associate(10.3.2.85,3333,ae_title=bUIHPACSSERVER)

if assoc.is_established: # Use the C-STORE service to send the dataset # returns the response status as a pydicom Dataset status = assoc.send_c_store(ds)

# Check the status of the storage request if status: # If the storage request succeeded this will be 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(Association rejected, aborted or never connected)

经验分享 程序员 微信小程序 职场和发展