AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當前位置:首頁 > 科技  > 軟件

Fo-dicom是如何實現DICOM 的網絡通信功能

來源: 責編: 時間:2024-05-11 09:19:47 154觀看
導讀DICOM3.0標準的通用通信模型下圖顯示了DICOM3.0標準的通用通信模型,該模型跨越了 網絡(在線)和媒體存儲交換(離線)通信。應用程序可利用以下任一傳輸機制:DICOM 消息服務和上層服務,它們獨立于特定的物理網絡通信支持和協議(

vjm28資訊網——每日最新資訊28at.com

DICOM3.0標準的通用通信模型

下圖顯示了DICOM3.0標準的通用通信模型,該模型跨越了 網絡(在線)和媒體存儲交換(離線)通信。應用程序可利用以下任一傳輸機制:vjm28資訊網——每日最新資訊28at.com

vjm28資訊網——每日最新資訊28at.com

  • DICOM 消息服務和上層服務,它們獨立于特定的物理網絡通信支持和協議(如 TCP/IP)。
  • DICOM Web 服務 API 和 HTTP 服務,允許使用通用超文本和相關協議來傳輸 DICOM 服務
  • 基本 DICOM 文件服務,它提供獨立于特定媒體存儲格式和文件結構的存儲介質訪問
  • DICOM 實時通信,提供基于 SMPTE 和 RTP 的 DICOM 元數據的實時傳輸。

DICOM的通用通信模型旨在為醫療圖像和相關數據的傳輸和存儲提供靈活和多樣化的解決方案。DICOM的通用通信模型不僅僅是簡單地傳輸和存儲醫療圖像和相關數據,而是提供了一種多層次、多種方式的靈活解決方案,以滿足不同場景下的需求和要求。這種多樣化的傳輸和存儲機制使得DICOM成為醫療行業中不可或缺的通信標準,為醫療圖像和相關數據的交換和共享提供了可靠和高效的技術支持。vjm28資訊網——每日最新資訊28at.com

DICOM的通用通信模型的重要性和價值在于其能夠滿足醫療行業不同方面的需求,為醫療圖像和相關數據的傳輸和存儲提供了全面而可靠的解決方案,從而推動了醫療信息技術的發展和應用。vjm28資訊網——每日最新資訊28at.com

fo-dicom基于.NET 平臺的網絡通信庫來實現 DICOM 的網絡通信功能

`fo-dicom` 使用了Socket和TcpClient等底層網絡通信類來與DICOM服務器進行連接和通信,從而實現 DICOM 的網絡通信功能。下面是 `fo-dicom` 網絡通信的實現基本原理:vjm28資訊網——每日最新資訊28at.com

  • 傳輸協議選擇:`fo-dicom` 支持多種傳輸協議,如 TCP/IP、UDP 和 WebSocket。用戶可以根據需要選擇適合的傳輸協議。
  • 連接建立:對于服務器端應用程序,使用 `DicomServer` 類監聽指定的端口號,等待客戶端連接請求。一旦有客戶端連接請求到達,服務器將建立一個與客戶端的網絡連接。
  • 數據傳輸:在 DICOM 通信中,數據通過 DIMSE(DICOM Message Service Element)進行傳輸。DIMSE 是基于消息的通信模式,包括 C-STORE(存儲服務)、C-FIND(查詢服務)、C-MOVE(移動服務)等。
  • 數據編碼:`fo-dicom` 使用 DICOM 標準定義的數據格式和編碼規則對數據進行編碼。DICOM 數據集使用一系列的標簽(Tag)來組織和描述不同的信息,例如患者姓名、圖像序列等。`fo-dicom` 將數據集編碼為字節流以進行傳輸。
  • 數據解碼:在接收方,`fo-dicom` 將接收到的字節流解碼為 DICOM 數據集,以便進行后續的處理和分析。
  • 數據處理:根據具體的應用需求,可以對 DICOM 數據集進行查詢、存儲、檢索等操作。`fo-dicom` 提供了一組 API 來處理 DICOM 數據集,以便用戶能夠方便地訪問和操作數據。
  • 響應發送:在服務器端應用程序中,一旦完成對 DICOM 請求的處理,將向客戶端發送一個響應。響應中包含請求的執行結果、狀態信息等。
  • 連接斷開:通信完成后,可以關閉服務器端的監聽或斷開客戶端與服務器的連接。

vjm28資訊網——每日最新資訊28at.com

`fo-dicom` 通過使用 .NET 平臺的網絡通信庫來實現底層的網絡傳輸,并且遵循 DICOM 標準的數據格式和編碼規則。它提供了一組簡潔而強大的 API,使得用戶可以方便地進行 DICOM 數據的傳輸和處理。vjm28資訊網——每日最新資訊28at.com

案例說明

以下是一個使用 `fo-dicom` 進行C-STORE命令的網絡通信的簡單案例:vjm28資訊網——每日最新資訊28at.com

案例來源于官網的示例:https://github.com/fo-dicom/fo-dicom-samplesvjm28資訊網——每日最新資訊28at.com

假設我們有一個服務器端應用程序,它監聽在本地的端口號 11112上,等待客戶端的連接請求。一旦接收到來自客戶端的 C-STORE 請求,服務器將把接收到的 DICOM 圖像數據保存到本地磁盤。vjm28資訊網——每日最新資訊28at.com

using System;using System.IO;using System.Text;using System.Threading.Tasks;using FellowOakDicom.Network;using Microsoft.Extensions.Logging;namespace Samples{    internal class Program    {        private const string _storagePath = @"./DICOM";        private static void Main(string[] args)        {            // start DICOM server on port from command line argument or 11112            var port = args != null && args.Length > 0 && int.TryParse(args[0], out int tmp) ? tmp : 11112;            Console.WriteLine($"Starting C-Store SCP server on port {port}");            using (var server = DicomServerFactory.Create<CStoreSCP>(port))            {                // end process                Console.WriteLine("Press <return> to end...");                Console.ReadLine();            }        }        private class CStoreSCP : DicomService, IDicomServiceProvider, IDicomCStoreProvider, IDicomCEchoProvider        {            private static readonly DicomTransferSyntax[] _acceptedTransferSyntaxes = new DicomTransferSyntax[]            {               DicomTransferSyntax.ExplicitVRLittleEndian,               DicomTransferSyntax.ExplicitVRBigEndian,               DicomTransferSyntax.ImplicitVRLittleEndian            };            private static readonly DicomTransferSyntax[] _acceptedImageTransferSyntaxes = new DicomTransferSyntax[]            {               // Lossless               DicomTransferSyntax.JPEGLSLossless,               DicomTransferSyntax.JPEG2000Lossless,               DicomTransferSyntax.JPEGProcess14SV1,               DicomTransferSyntax.JPEGProcess14,               DicomTransferSyntax.RLELossless,               // Lossy               DicomTransferSyntax.JPEGLSNearLossless,               DicomTransferSyntax.JPEG2000Lossy,               DicomTransferSyntax.JPEGProcess1,               DicomTransferSyntax.JPEGProcess2_4,               // Uncompressed               DicomTransferSyntax.ExplicitVRLittleEndian,               DicomTransferSyntax.ExplicitVRBigEndian,               DicomTransferSyntax.ImplicitVRLittleEndian            };            public CStoreSCP(INetworkStream stream, Encoding fallbackEncoding, ILogger log, DicomServiceDependencies dependencies)                : base(stream, fallbackEncoding, log, dependencies)            {            }            public Task OnReceiveAssociationRequestAsync(DicomAssociation association)            {                if (association.CalledAE != "STORESCP")                {                    return SendAssociationRejectAsync(                        DicomRejectResult.Permanent,                        DicomRejectSource.ServiceUser,                        DicomRejectReason.CalledAENotRecognized);                }                foreach (var pc in association.PresentationContexts)                {                    if (pc.AbstractSyntax == DicomUID.Verification)                    {                        pc.AcceptTransferSyntaxes(_acceptedTransferSyntaxes);                    }                    else if (pc.AbstractSyntax.StorageCategory != DicomStorageCategory.None)                    {                        pc.AcceptTransferSyntaxes(_acceptedImageTransferSyntaxes);                    }                }                return SendAssociationAcceptAsync(association);            }            public Task OnReceiveAssociationReleaseRequestAsync()            {                return SendAssociationReleaseResponseAsync();            }            public void OnReceiveAbort(DicomAbortSource source, DicomAbortReason reason)            {                /* nothing to do here */            }            public void OnConnectionClosed(Exception exception)            {                /* nothing to do here */            }            public async Task<DicomCStoreResponse> OnCStoreRequestAsync(DicomCStoreRequest request)            {                var studyUid = request.Dataset.GetSingleValue<string>(DicomTag.StudyInstanceUID).Trim();                var instUid = request.SOPInstanceUID.UID;                var path = Path.GetFullPath(Program._storagePath);                path = Path.Combine(path, studyUid);                if (!Directory.Exists(path))                {                    Directory.CreateDirectory(path);                }                path = Path.Combine(path, instUid) + ".dcm";                await request.File.SaveAsync(path);                return new DicomCStoreResponse(request, DicomStatus.Success);            }            public Task OnCStoreRequestExceptionAsync(string tempFileName, Exception e)            {                // let library handle logging and error response                return Task.CompletedTask;            }            public Task<DicomCEchoResponse> OnCEchoRequestAsync(DicomCEchoRequest request)            {                return Task.FromResult(new DicomCEchoResponse(request, DicomStatus.Success));            }        }    }}

在上面的代碼中,首先從命令行參數中獲取端口號,然后創建一個 CStoreSCP 對象作為 DICOM 服務器,并將其綁定到指定的端口。在 CStoreSCP 類中,實現了 IDicomServiceProvider、IDicomCStoreProvider 和 IDicomCEchoProvider 接口,分別處理 DICOM 關聯請求、C-Store 請求和 C-Echo 請求。其中,
OnReceiveAssociationRequestAsync() 方法會檢查 Called AE 是否為 STORESCP,如果不是則拒絕關聯請求。OnCStoreRequestAsync() 方法則會將接收到的 DICOM 數據保存到本地文件系統中。其他的方法實現通常為空實現,因為并不需要對其進行特殊處理。vjm28資訊網——每日最新資訊28at.com

對于客戶端應用程序,我們可以使用 `DicomClient` 類來發送 C-STORE 請求到服務器。以下是一個簡單的客戶端示例:vjm28資訊網——每日最新資訊28at.com

using System;using System.IO;using System.Net;using System.Net.Sockets;using System.Threading.Tasks;using FellowOakDicom.Network;using FellowOakDicom.Network.Client;namespace Samples{    internal static class Program    {        private static string _storeServerHost = "127.0.0.1";        private static int _storeServerPort = 11112;        private const string _storeServerAET = "STORESCP";        private const string _aet = "FODICOMSCU";        static async Task Main(string[] args)        {            var storeMore = "";            _storeServerHost = GetServerHost();            _storeServerPort = GetServerPort();            Console.WriteLine("***************************************************");            Console.WriteLine("Server AE Title: " + _storeServerAET);            Console.WriteLine("Server Host Address: " + _storeServerHost);            Console.WriteLine("Server Port: " + _storeServerPort);            Console.WriteLine("Client AE Title: " + _aet);            Console.WriteLine("***************************************************");            var client = DicomClientFactory.Create(_storeServerHost, _storeServerPort, false, _aet, _storeServerAET);            client.NegotiateAsyncOps();            do            {                try                {                    Console.WriteLine();                    Console.WriteLine("Enter the path for a DICOM file:");                    Console.Write(">>>");                    string dicomFile = Console.ReadLine();                    while (!File.Exists(dicomFile))                    {                        Console.WriteLine("Invalid file path, enter the path for a DICOM file or press Enter to Exit:");                        dicomFile = Console.ReadLine();                        if (string.IsNullOrWhiteSpace(dicomFile))                        {                            return;                        }                    }                    var request = new DicomCStoreRequest(dicomFile);                    request.OnResponseReceived += (req, response) => Console.WriteLine("C-Store Response Received, Status: " + response.Status);                    await client.AddRequestAsync(request);                    await client.SendAsync();                }                catch (Exception exception)                {                    Console.WriteLine();                    Console.WriteLine("----------------------------------------------------");                    Console.WriteLine("Error storing file. Exception Details:");                    Console.WriteLine(exception.ToString());                    Console.WriteLine("----------------------------------------------------");                    Console.WriteLine();                }                Console.WriteLine("To store another file, enter /"y/"; Othersie, press enter to exit: ");                Console.Write(">>>");                storeMore = Console.ReadLine().Trim();            } while (storeMore.Length > 0 && storeMore.ToLower()[0] == 'y');        }        private static string GetServerHost()        {            var hostAddress = "";            var localIP = GetLocalIPAddress();            do            {                Console.WriteLine("Your local IP is: " + localIP);                Console.WriteLine("Enter /"1/" to use your local IP Address: " + localIP);                Console.WriteLine("Enter /"2/" to use defult: " + _storeServerHost);                Console.WriteLine("Enter /"3/" to enter custom");                Console.Write(">>>");                string input = Console.ReadLine().Trim().ToLower();                if (input.Length > 0)                {                    if (input[0] == '1')                    {                        hostAddress = localIP;                    }                    else if (input[0] == '2')                    {                        hostAddress = _storeServerHost;                    }                    else if (input[0] == '3')                    {                        Console.WriteLine("Enter Server Host Address:");                        Console.Write(">>>");                        hostAddress = Console.ReadLine();                    }                }            } while (hostAddress.Length == 0);            return hostAddress;        }        private static int GetServerPort()        {            Console.WriteLine("Enter Server port, or /"Enter/" for default /"" + _storeServerPort + "/":");            Console.Write(">>>");            var input = Console.ReadLine().Trim();            return string.IsNullOrEmpty(input) ? _storeServerPort : int.Parse(input);        }        public static string GetLocalIPAddress()        {            var host = Dns.GetHostEntry(Dns.GetHostName());            foreach (var ip in host.AddressList)            {                if (ip.AddressFamily == AddressFamily.InterNetwork)                {                    return ip.ToString();                }            }            return "";        }    }}

首先定義了一些變量,包括存儲服務器的主機地址、端口號,以及客戶端和服務器的 AE(Application Entity)標題。然后,在 Main 方法中創建了一個 DicomClient 對象,并通過調用 NegotiateAsyncOps 方法進行異步操作的協商。接下來,進入一個循環,用戶可以輸入要發送的 DICOM 文件的路徑。程序會檢查路徑是否有效,如果無效則提示用戶重新輸入,直到輸入為空或用戶選擇退出。然后,創建一個 DicomCStoreRequest 對象,傳入要發送的 DICOM 文件路徑作為參數。并通過訂閱 OnResponseReceived 事件來處理響應。最后,調用 AddRequestAsync 方法將請求添加到客戶端的請求隊列中,并調用 SendAsync 方法發送請求。vjm28資訊網——每日最新資訊28at.com

其中GetServerHost 方法用于獲取服務器主機地址,它會提示用戶選擇使用本地 IP 地址、默認地址還是自定義地址。GetServerPort 方法用于獲取服務器端口號,用戶可以輸入自定義端口號,或者直接回車使用默認端口號。GetLocalIPAddress 方法用于獲取本地 IP 地址。vjm28資訊網——每日最新資訊28at.com

這個案例展示了一個簡單的基于 `fo-dicom` 的 DICOM 網絡通信示例,即SCU和SCP對CStore的通信的簡單處理,服務器接收到客戶端發送的 C-STORE 請求并保存圖像到本地磁盤。vjm28資訊網——每日最新資訊28at.com

本文鏈接:http://www.tebozhan.com/showinfo-26-87977-0.htmlFo-dicom是如何實現DICOM 的網絡通信功能

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 瀏覽器調試的30個奇淫技巧

下一篇: Python Argcomplete 自動補全指南

標簽:
  • 熱門焦點
Top