fo-dicom是一个基于C#开发的库,用于处理DICOM(Digital Imaging and Communications in Medicine)格式的数据。DICOM是一种用于医学影像和相关信息的标准格式,广泛应用于医学领域。fo-dicom提供了多平台支持,可在 Windows、Linux 和 macOS 等操作系统上运行。
fo-dicom库的设计理念是提供一个方便、易用、功能强大的工具,用于处理、读取、写入和修改DICOM文件。该库提供了丰富的API,支持对DICOM文件的标签进行读取和设置,支持对DICOM文件的编码和解码,支持对DICOM文件的传输和存储。
fo-dicom库还提供了对DICOM消息流的封装,使得开发者可以方便地实现自定义的DICOM服务。该库还支持对网络底层的封装,使得开发者可以轻松地实现基于网络的DICOM通信。
开源库地址:https://github.com/fo-dicom/fo-dicom。
fo-dicom库的产生是为了解决医学图像处理和DICOM数据交换的需求。在医学领域,DICOM(Digital Imaging and Communications in Medicine)是一种用于存储、传输和共享医学影像和相关信息的标准。由于医学影像数据的特殊性和复杂性,需要一个专门的库来处理DICOM数据,并提供方便的接口和工具。
背景上来说,DICOM标准的出现是为了解决各种医学设备之间的互操作性问题。在过去,不同厂商的医学设备使用自己的私有格式来存储和传输影像数据,这导致了数据共享和集成的困难。DICOM标准的制定使得不同设备可以使用统一的格式和通信协议,从而实现医学影像的无缝交流和协作。
fo-dicom作为一个开源的DICOM库,旨在提供一个易于使用且功能强大的工具,使得开发者能够处理医学图像和相关数据。它基于DICOM标准,提供了读取、创建、修改和存储DICOM数据的功能,同时支持医学图像的加载、处理和保存。此外,fo-dicom还具备与远程PACS(Picture Archiving and Communication System)或其他DICOM节点的网络通信能力,以及查询和检索功能,方便用户根据条件查询和获取DICOM实例。
阅读官方文档,即可获得安装方法:https://fo-dicom.github.io/stable/v5/index.html。
开箱即用的 fo-dicom 默认为内部类FellowOakDicom.Imaging.IImage 样式的图像渲染。若要切换到桌面样式或 ImageSharp 样式的图像呈现,首先必须添加所需的 nuget 包,然后调用:
new DicomSetupBuilder() .RegisterServices(s => s.AddFellowOakDicom().AddImageManager<WinFormsImageManager>()).Build();
或:
new DicomSetupBuilder() .RegisterServices(s => s.AddFellowOakDicom().AddImageManager<ImageSharpImageManager>()).Build();
然后,在渲染时,可以通过以下方式将 IImage 强制转换为类型。
var image = new DicomImage("filename.dcm");var bitmap = image.RenderImage().As<Bitmap>();
或:
var image = new DicomImage("filename.dcm");var sharpimage = image.RenderImage().AsSharpImage();
Fellow Oak DICOM 使用 ,因此如果您已经在使用它,则 Fellow Oak DICOM 日志记录将自动显示。
Microsoft.Extensions.Logging
过去,Fellow Oak DICOM 有一个用于日志记录的自定义抽象:ILogger 和 ILogManager。 出于向后兼容性的目的,这仍然受支持,但不建议用于新应用程序。
services.AddLogManager<MyLogManager>();
其中 MyLogManager 如下所示:
using FellowOakDicom.Log;public class MyLogManager: ILogManager { public ILogger GetLogger(string name) { ... }}
这里有许多使用 fo-dicom 的简单示例应用程序,它们位于单独的存储库中。这些还包括示例 以前包含在 VS 解决方案的“示例”子文件夹中。
var file = DicomFile.Open(@"test.dcm"); // Alt 1var file = await DicomFile.OpenAsync(@"test.dcm"); // Alt 2var patientid = file.Dataset.GetString(DicomTag.PatientID);file.Dataset.AddOrUpdate(DicomTag.PatientName, "DOE^JOHN");// creates a new instance of DicomFilevar newFile = file.Clone(DicomTransferSyntax.JPEGProcess14SV1);file.Save(@"output.dcm"); // Alt 1await file.SaveAsync(@"output.dcm"); // Alt 2
var image = new DicomImage(@"test.dcm");image.RenderImage().AsBitmap().Save(@"test.jpg"); // Windows Forms
var client = DicomClientFactory.Create("127.0.0.1", 12345, false, "SCU", "ANY-SCP");await client.AddRequestAsync(new DicomCStoreRequest(@"test.dcm"));await client.SendAsync();
var server = new DicomServer<DicomCEchoProvider>(12345);var client = DicomClientFactory.Create("127.0.0.1", 12345, false, "SCU", "ANY-SCP");client.NegotiateAsyncOps();// Optionally negotiate user identityclient.NegotiateUserIdentity(new DicomUserIdentityNegotiation{ UserIdentityType = DicomUserIdentityType.Jwt, PositiveResponseRequested = true, PrimaryField = "JWT_TOKEN"});for (int i = 0; i < 10; i++) await client.AddRequestAsync(new DicomCEchoRequest());await client.SendAsync();
var cfind = DicomCFindRequest.CreateStudyQuery(patientId: "12345");cfind.OnResponseReceived = (DicomCFindRequest rq, DicomCFindResponse rp) => { Console.WriteLine("Study UID: {0}", rp.Dataset.GetString(DicomTag.StudyInstanceUID));};var client = DicomClientFactory.Create("127.0.0.1", 11112, false, "SCU-AE", "SCP-AE");await client.AddRequestAsync(cfind);await client.SendAsync();
var cmove = new DicomCMoveRequest("DEST-AE", studyInstanceUid);var client = DicomClientFactory.Create("127.0.0.1", 11112, false, "SCU-AE", "SCP-AE");await client.AddRequestAsync(cmove);await client.SendAsync();
// It is better to increase 'associationLingerTimeoutInMs' default is 50 ms, which may not be// be sufficientvar dicomClient = DicomClientFactory.Create("127.0.0.1", 12345, false, "SCU-AE", "SCP-AE",DicomClientDefaults.DefaultAssociationRequestTimeoutInMs, DicomClientDefaults.DefaultAssociationReleaseTimeoutInMs,5000);var txnUid = DicomUIDGenerator.GenerateDerivedFromUUID().UID;var nActionDicomDataSet = new DicomDataset{ { DicomTag.TransactionUID, txnUid }};var dicomRefSopSequence = new DicomSequence(DicomTag.ReferencedSOPSequence);var seqItem = new DicomDataset(){ { DicomTag.ReferencedSOPClassUID, "1.2.840.10008.5.1.4.1.1.1" }, { DicomTag.ReferencedSOPInstanceUID, "1.3.46.670589.30.2273540226.4.54" }};dicomRefSopSequence.Items.Add(seqItem);nActionDicomDataSet.Add(dicomRefSopSequence);var nActionRequest = new DicomNActionRequest(DicomUID.StorageCommitmentPushModelSOPClass, DicomUID.StorageCommitmentPushModelSOPInstance, 1){ Dataset = nActionDicomDataSet, OnResponseReceived = (DicomNActionRequest request, DicomNActionResponse response) => { Console.WriteLine("NActionResponseHandler, response status:{0}", response.Status); },};await dicomClient.AddRequestAsync(nActionRequest);dicomClient.OnNEventReportRequest = OnNEventReportRequest;await dicomClient.SendAsync();private static Task<DicomNEventReportResponse> OnNEventReportRequest(DicomNEventReportRequest request){ var refSopSequence = request.Dataset.GetSequence(DicomTag.ReferencedSOPSequence); foreach(var item in refSopSequence.Items) { Console.WriteLine("SOP Class UID: {0}", item.GetString(DicomTag.ReferencedSOPClassUID)); Console.WriteLine("SOP Instance UID: {0}", item.GetString(DicomTag.ReferencedSOPInstanceUID)); } return Task.FromResult(new DicomNEventReportResponse(request, DicomStatus.Success));}
具有高级 DICOM 客户端连接的 C-ECHO:手动控制 TCP 连接和 DICOM 关联。
var cancellationToken = CancellationToken.None;// Alternatively, inject IDicomServerFactory via dependency injection instead of using this static methodusing var server = DicomServerFactory.Create<DicomCEchoProvider>(12345); var connectionRequest = new AdvancedDicomClientConnectionRequest{ NetworkStreamCreationOptions = new NetworkStreamCreationOptions { Host = "127.0.0.1", Port = server.Port, }};// Alternatively, inject IAdvancedDicomClientConnectionFactory via dependency injection instead of using this static methodusing var connection = await AdvancedDicomClientConnectionFactory.OpenConnectionAsync(connectionRequest, cancellationToken);var associationRequest = new AdvancedDicomClientAssociationRequest{ CallingAE = "EchoSCU", CalledAE = "EchoSCP", // Optionally negotiate user identity UserIdentityNegotiation = new DicomUserIdentityNegotiation { UserIdentityType = DicomUserIdentityType.UsernameAndPasscode, PositiveResponseRequested = true, PrimaryField = "USERNAME", SecondaryField = "PASSCODE", }};var cEchoRequest = new DicomCEchoRequest();using var association = await connection.OpenAssociationAsync(associationRequest, cancellationToken);try{ DicomCEchoResponse cEchoResponse = await association.SendCEchoRequestAsync(cEchoRequest, cancellationToken).ConfigureAwait(false); Console.WriteLine(cEchoResponse.Status);}finally{ await association.ReleaseAsync(cancellationToken);}
fo-dicom 有一个活跃的社区,包括众多贡献者和维护者。它在 GitHub 上有一个开放的仓库,用户可以在其中提交问题、提出建议和贡献代码。fo-dicom 的更新频率较高,并得到了广泛的应用和认可。
为了方便新手学习官方构建了样例库:https://github.com/fo-dicom/fo-dicom-samples。
同时支持多个平台的案例开发开发:
fo-dicom 的未来计划包括进一步增强图像处理功能、优化性能、改进网络通信和增加对新版 DICOM 标准的支持。通过不断改进和扩展功能,fo-dicom 将继续满足用户对医学图像处理和数据交互的需求。
今天先介绍到这里,后续我将持续分享关于fo-dicom库的使用经验技巧,欢迎有需要的朋友持续关注。
本文链接://www.dmpip.com//www.dmpip.com/showinfo-26-87004-0.htmlFo-dicom,第一个基于.NET Standard 2.0 开发的DICOM开源库
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。邮件:2376512515@qq.com