上篇文件介紹了什么dicomhttps://blog.csdn.net/qq_39569480/article/details/149641920?spm=1001.2014.3001.5502 本篇文章我們來使用fo_dicom接收并解析dicom文件。
文章結尾附源碼。
1.開發環境
visual studio 2019
.netframwork 4.8
2.關鍵知識點
dicom三要素為 AE title、IP、port
AE Title(Application Entity Title,應用實體標題)
是DICOM(醫學數字成像與通信)標準中用于唯一標識網絡中的通信節點的核心參數。它在醫療影像系統(如PACS、影像設備)的互聯互通通過唯一命名和長度限制(≤16字符) 確保設備間精準通信。它在影像傳輸、來源追溯、服務調度中不可或缺,配置錯誤可能引發傳輸失敗或數據混亂。實際應用中需嚴格遵循命名唯一性規則。
首先聲明允許的ae title集合
private static readonly string[] AllowedAEs = { "PACS_SERVER", "MICRODICOM" }; // 允許的AE Title列表
端口號:用于通信端口
private const int Port = 11112; // PACS標準端口
ip: 服務的ip地址
什么是sop類:
SOP類(Service Object Pair,服務對象對)是DICOM(醫學數字成像與通信)標準中的核心概念,定義了如何通過特定服務操作特定類型的醫學數據對象。它是DICOM網絡通信和數據處理的基礎單元,確保不同醫療設備(如CT、MRI、PACS)之間的互操作性。
SOP類的作用與意義:
1.標準化通信
設備通過協商支持的SOP類建立關聯(Association),確保雙方能理解彼此的請求與響應。例如CT設備需聲明支持CT Image Storage SOP Class才能向PACS傳輸圖像5。
2.唯一標識
每個SOP類有唯一的UID(如CT圖像存儲類UID為1.2.840.10008.5.1.4.1.1.2),避免操作歧義45。
3.功能擴展性
新型醫療技術(如眼科層析成像)可定義專屬SOP類,支持復雜數據(如動態多幀圖像)8。
4.常見的sop類舉例
(1).Verification SOP Class
作用:驗證網絡連通性(如C-ECHO命令)15。
UID:1.2.840.10008.1.1。
(2).Storage SOP Class
作用:傳輸圖像(如CT/MR圖像)。
特點:不同設備有專屬UID(如MR圖像類UID為1.2.840.10008.5.1.4.1.1.4)14。
(3).Modality Worklist SOP Class
作用:設備從HIS/RIS系統獲取待檢患者列表(C-FIND查詢)6。
UID:1.2.840.10008.5.1.4.31。
(4).Query/Retrieve SOP Class
作用:分層級查詢數據(如患者級、檢查級)16。
(5).MPPS SOP Class
作用:管理設備執行檢查的進度狀態2。
設置支持的SOP類UID列表
private static readonly string[] SupportedSopClasses ={// 驗證服務類SOP (必須添加)DicomUID.Verification.UID,// 存儲類SOPDicomUID.CTImageStorage.UID,DicomUID.MRImageStorage.UID,DicomUID.ComputedRadiographyImageStorage.UID,DicomUID.DigitalXRayImageStorageForPresentation.UID,DicomUID.UltrasoundImageStorage.UID,DicomUID.SecondaryCaptureImageStorage.UID,DicomUID.NuclearMedicineImageStorageRetiredRETIRED.UID,DicomUID.NuclearMedicineImageStorage.UID,DicomUID.PositronEmissionTomographyImageStorage.UID,DicomUID.RTImageStorage.UID,DicomUID.UltrasoundImageStorageRetiredRETIRED.UID,DicomUID.UltrasoundMultiFrameImageStorage.UID,DicomUID.UltrasoundMultiFrameImageStorageRetiredRETIRED.UID,DicomUID.XRayAngiographicImageStorage.UID,DicomUID.XRayRadiofluoroscopicImageStorage.UID,DicomUID.DigitalXRayImageStorageForPresentation.UID,DicomUID.DigitalXRayImageStorageForProcessing.UID,DicomUID.DigitalMammographyXRayImageStorageForPresentation.UID,DicomUID.DigitalMammographyXRayImageStorageForProcessing.UID,DicomUID.DigitalIntraOralXRayImageStorageForPresentation.UID,DicomUID.DigitalIntraOralXRayImageStorageForProcessing.UID,DicomUID.XRayAngiographicBiPlaneImageStorageRETIRED.UID,DicomUID.VLEndoscopicImageStorage.UID,DicomUID.VLMicroscopicImageStorage.UID,DicomUID.VLSlideCoordinatesMicroscopicImageStorage.UID,DicomUID.VLPhotographicImageStorage.UID,DicomUID.GrayscaleSoftcopyPresentationStateStorage.UID,DicomUID.KeyObjectSelectionDocumentStorage.UID// 添加其他需要的SOP類};
3.環境配置
這里使用的是fo-dicom 4.0.8 大家可根據自己的需求使用對應版本
部分代碼實現
DICOM服務類:
using Dicom;
using Dicom.Imaging;
using Dicom.Network;
using Dicom.Log;
using SixLabors.ImageSharp.Formats.Jpeg;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace DICOMkztDemo
{public class DICOMServer{private const int Port = 11112; // PACS標準端口private static readonly string StoragePath = @"C:\DICOM_Storage\";private static readonly string JpegOutputPath = @"C:\DICOM_Storage\DICOM_JPG\";private static readonly string[] AllowedAEs = { "PACS_SERVER", "MICRODICOM" }; // 允許的AE Title列表private static readonly DicomTransferSyntax[] AcceptedTransferSyntaxes ={DicomTransferSyntax.ExplicitVRLittleEndian,<