日韩成人免费在线_国产成人一二_精品国产免费人成电影在线观..._日本一区二区三区久久久久久久久不

當(dāng)前位置:首頁 > 科技  > 軟件

Fo-dicom是如何實(shí)現(xiàn)DICOM 的網(wǎng)絡(luò)通信功能

來源: 責(zé)編: 時(shí)間:2024-05-11 09:19:47 176觀看
導(dǎo)讀DICOM3.0標(biāo)準(zhǔn)的通用通信模型下圖顯示了DICOM3.0標(biāo)準(zhǔn)的通用通信模型,該模型跨越了 網(wǎng)絡(luò)(在線)和媒體存儲(chǔ)交換(離線)通信。應(yīng)用程序可利用以下任一傳輸機(jī)制:DICOM 消息服務(wù)和上層服務(wù),它們獨(dú)立于特定的物理網(wǎng)絡(luò)通信支持和協(xié)議(

bP528資訊網(wǎng)——每日最新資訊28at.com

DICOM3.0標(biāo)準(zhǔn)的通用通信模型

下圖顯示了DICOM3.0標(biāo)準(zhǔn)的通用通信模型,該模型跨越了 網(wǎng)絡(luò)(在線)和媒體存儲(chǔ)交換(離線)通信。應(yīng)用程序可利用以下任一傳輸機(jī)制:bP528資訊網(wǎng)——每日最新資訊28at.com

bP528資訊網(wǎng)——每日最新資訊28at.com

  • DICOM 消息服務(wù)和上層服務(wù),它們獨(dú)立于特定的物理網(wǎng)絡(luò)通信支持和協(xié)議(如 TCP/IP)。
  • DICOM Web 服務(wù) API 和 HTTP 服務(wù),允許使用通用超文本和相關(guān)協(xié)議來傳輸 DICOM 服務(wù)
  • 基本 DICOM 文件服務(wù),它提供獨(dú)立于特定媒體存儲(chǔ)格式和文件結(jié)構(gòu)的存儲(chǔ)介質(zhì)訪問
  • DICOM 實(shí)時(shí)通信,提供基于 SMPTE 和 RTP 的 DICOM 元數(shù)據(jù)的實(shí)時(shí)傳輸。

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

DICOM的通用通信模型的重要性和價(jià)值在于其能夠滿足醫(yī)療行業(yè)不同方面的需求,為醫(yī)療圖像和相關(guān)數(shù)據(jù)的傳輸和存儲(chǔ)提供了全面而可靠的解決方案,從而推動(dòng)了醫(yī)療信息技術(shù)的發(fā)展和應(yīng)用。bP528資訊網(wǎng)——每日最新資訊28at.com

fo-dicom基于.NET 平臺(tái)的網(wǎng)絡(luò)通信庫來實(shí)現(xiàn) DICOM 的網(wǎng)絡(luò)通信功能

`fo-dicom` 使用了Socket和TcpClient等底層網(wǎng)絡(luò)通信類來與DICOM服務(wù)器進(jìn)行連接和通信,從而實(shí)現(xiàn) DICOM 的網(wǎng)絡(luò)通信功能。下面是 `fo-dicom` 網(wǎng)絡(luò)通信的實(shí)現(xiàn)基本原理:bP528資訊網(wǎng)——每日最新資訊28at.com

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

bP528資訊網(wǎng)——每日最新資訊28at.com

`fo-dicom` 通過使用 .NET 平臺(tái)的網(wǎng)絡(luò)通信庫來實(shí)現(xiàn)底層的網(wǎng)絡(luò)傳輸,并且遵循 DICOM 標(biāo)準(zhǔn)的數(shù)據(jù)格式和編碼規(guī)則。它提供了一組簡潔而強(qiáng)大的 API,使得用戶可以方便地進(jìn)行 DICOM 數(shù)據(jù)的傳輸和處理。bP528資訊網(wǎng)——每日最新資訊28at.com

案例說明

以下是一個(gè)使用 `fo-dicom` 進(jìn)行C-STORE命令的網(wǎng)絡(luò)通信的簡單案例:bP528資訊網(wǎng)——每日最新資訊28at.com

案例來源于官網(wǎng)的示例:https://github.com/fo-dicom/fo-dicom-samplesbP528資訊網(wǎng)——每日最新資訊28at.com

假設(shè)我們有一個(gè)服務(wù)器端應(yīng)用程序,它監(jiān)聽在本地的端口號(hào) 11112上,等待客戶端的連接請(qǐng)求。一旦接收到來自客戶端的 C-STORE 請(qǐng)求,服務(wù)器將把接收到的 DICOM 圖像數(shù)據(jù)保存到本地磁盤。bP528資訊網(wǎng)——每日最新資訊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));            }        }    }}

在上面的代碼中,首先從命令行參數(shù)中獲取端口號(hào),然后創(chuàng)建一個(gè) CStoreSCP 對(duì)象作為 DICOM 服務(wù)器,并將其綁定到指定的端口。在 CStoreSCP 類中,實(shí)現(xiàn)了 IDicomServiceProvider、IDicomCStoreProvider 和 IDicomCEchoProvider 接口,分別處理 DICOM 關(guān)聯(lián)請(qǐng)求、C-Store 請(qǐng)求和 C-Echo 請(qǐng)求。其中,
OnReceiveAssociationRequestAsync() 方法會(huì)檢查 Called AE 是否為 STORESCP,如果不是則拒絕關(guān)聯(lián)請(qǐng)求。OnCStoreRequestAsync() 方法則會(huì)將接收到的 DICOM 數(shù)據(jù)保存到本地文件系統(tǒng)中。其他的方法實(shí)現(xiàn)通常為空實(shí)現(xiàn),因?yàn)椴⒉恍枰獙?duì)其進(jìn)行特殊處理。bP528資訊網(wǎng)——每日最新資訊28at.com

對(duì)于客戶端應(yīng)用程序,我們可以使用 `DicomClient` 類來發(fā)送 C-STORE 請(qǐng)求到服務(wù)器。以下是一個(gè)簡單的客戶端示例:bP528資訊網(wǎng)——每日最新資訊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 "";        }    }}

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

其中GetServerHost 方法用于獲取服務(wù)器主機(jī)地址,它會(huì)提示用戶選擇使用本地 IP 地址、默認(rèn)地址還是自定義地址。GetServerPort 方法用于獲取服務(wù)器端口號(hào),用戶可以輸入自定義端口號(hào),或者直接回車使用默認(rèn)端口號(hào)。GetLocalIPAddress 方法用于獲取本地 IP 地址。bP528資訊網(wǎng)——每日最新資訊28at.com

這個(gè)案例展示了一個(gè)簡單的基于 `fo-dicom` 的 DICOM 網(wǎng)絡(luò)通信示例,即SCU和SCP對(duì)CStore的通信的簡單處理,服務(wù)器接收到客戶端發(fā)送的 C-STORE 請(qǐng)求并保存圖像到本地磁盤。bP528資訊網(wǎng)——每日最新資訊28at.com

本文鏈接:http://www.www897cc.com/showinfo-26-87977-0.htmlFo-dicom是如何實(shí)現(xiàn)DICOM 的網(wǎng)絡(luò)通信功能

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。郵件:2376512515@qq.com

上一篇: 瀏覽器調(diào)試的30個(gè)奇淫技巧

下一篇: Python Argcomplete 自動(dòng)補(bǔ)全指南

標(biāo)簽:
  • 熱門焦點(diǎn)
Top 主站蜘蛛池模板: 九龙坡区| 镇平县| 紫阳县| 太原市| 诸城市| 靖远县| 洪洞县| 梨树县| 中阳县| 荆门市| 庆城县| 柯坪县| 青岛市| 大埔县| 上虞市| 陇西县| 搜索| 开原市| 梨树县| 兖州市| 海晏县| 时尚| 和顺县| 长岛县| 绵竹市| 申扎县| 武清区| 江北区| 张家界市| 西宁市| 衡阳市| 吴川市| 炎陵县| 星座| 邓州市| 建水县| 山西省| 连江县| 安顺市| 清新县| 阿城市|