如何从原始心电图数据编写DICOM文件

7

我有原始的心电图(ECG)电压样本,格式为csv,例如:

time    voltage (mV)
0.000   9.169110459
0.001   9.144672532
0.002   9.144672532
0.003   9.169110459
0.004   9.169110459
0.005   9.169110459
0.006   9.169110459
0.007   9.144672532
0.008   9.217986315
0.009   9.169110459
0.01    9.169110459
0.011   9.169110459
0.012   9.169110459
0.013   9.144672532
0.014   9.144672532
0.015   9.169110459
0.016   9.169110459
0.017   9.169110459
0.018   9.169110459
0.019   9.169110459
0.02    9.169110459
0.021   9.169110459
0.022   9.144672532
0.023   9.169110459

我想将这个文件转换为DICOM文件,以便我可以在ECG toolkit for c#等心电图查看器中查看:https://sourceforge.net/projects/ecgtoolkit-cs/ 如何进行此转换?我已经搜索了一些内容,但没有找到能够从原始数据编写DICOM文件的工具。
编辑:最终我选择了SCP文件,因为这更容易。我最终使用上面的库创建了一个SCP文件。下面是代码:
using System;
using System.Linq;
using ECGConversion;
using ECGConversion.ECGDemographics;
using ECGConversion.ECGSignals;

namespace SCPWriter
{
    public static class CreateScpEcg
    {
        public static void CreateScpEcgFile(double[] voltages, int sampleRate, string directory, string patientId)
        {
            var rhythm = voltages;

            var filePath = directory + patientId;

            // get an empty ECG format file
            IECGFormat format = ECGConverter.Instance.getFormat("SCP-ECG");
            if (format != null)
            {
                // five required actions for the demographic info.
                format.Demographics.Init();
                format.Demographics.PatientID = patientId;
                format.Demographics.LastName = "";
                format.Demographics.TimeAcquisition = DateTime.Now;
                // make an AcquiringDeviceID object
                AcquiringDeviceID acqID = new AcquiringDeviceID(true);

                // can also specify your own acquiring device info
                Communication.IO.Tools.BytesTool.writeString("MYDEVI", acqID.ModelDescription, 0, acqID.ModelDescription.Length);
                // set the Acquiring Device ID (required)
                format.Demographics.AcqMachineID = acqID;
                // declare the signal part.
                var leadType = new LeadType[] { LeadType.I };
                var rhythmAVM = 1;
                var rhythmSPS = sampleRate;
                Signals sigs = new Signals((byte)leadType.Length);
                sigs.RhythmAVM = rhythmAVM;
                sigs.RhythmSamplesPerSecond = rhythmSPS;

                for (int i = 0; i < sigs.NrLeads; i++)
                {
                    // very important to assign signal.

                    sigs[i] = new Signal();
                    sigs[i].Type = leadType[i];
                    sigs[i].Rhythm = rhythm.Select(Convert.ToInt16).ToArray();
                    sigs[i].RhythmStart = 0;
                    sigs[i].RhythmEnd = rhythm.Length - 1;
                }
                // store signal to the format.
                if (format.Signals.setSignals(sigs) != 0)
                {
                    Console.Error.WriteLine("setSignals failed!");
                    return;
                }
                // write the file
                var outputFile = filePath + ".scp";


                ECGWriter.Write(format, outputFile, true);
                if (ECGWriter.getLastError() != 0)
                {
                    Console.Error.WriteLine("Writing failed: {0}!", ECGWriter.getLastErrorMessage());
                    return;
                }
            }
        }


    }
}

NB: 我只对 "lead I" 感兴趣,但您可以在此行中添加更多线索: var leadType = new LeadType[] { LeadType.I }

NB: 这不是我的代码,而是来自上面链接中的讨论之一。

1个回答

6

我的建议:

  1. 选择一个DICOM工具包 自己实现DICOM数据的二进制编码没有任何意义。
  2. 查看ECG Waveform DICOM信息对象定义 上面的链接定义了12导联波形对象。如果您的数据不是12导联,请选择这个。我提供的链接指向模块表,通过跟随链接,您可以看到此类型对象所必需/允许的属性。
  3. 您不可避免地需要了解一些DICOM术语及在标准中查找信息的基础知识。我强烈推荐这份文档作为起点。对于此任务,请确保了解信息对象定义(IODs)、模块、属性类型(类型1、2、3)和值表示(VRs)

然后就很简单了。按照您选择的IOD(我提到的两个之一)的必填属性进行步骤,并使用您选择的工具包填充它们。然后使用工具包将文件写入磁盘,就完成了。确保将数据写为带有元标头的DICOM文件。一个好的工具包在将数据集写入磁盘时提供了这个选项。

请注意,仅将DICOM文件写入磁盘并不是“官方DICOM接口”。要在不同的DICOM应用程序之间交换数据,您必须使用网络协议(在您的情况下是存储服务类)或创建符合DICOM标准的介质(这会对使用的介质、文件格式、文件名施加一些限制,并需要包括列出介质内容的DICOM目录文件)。

由于您正在寻找一种工具,因此您可能需要查看DCMTK。有不同的方法可以完成任务。dcmdump或dcmodify将是更详细地查看的工具。然而,以这种方式进行操作很麻烦,您可能需要将ECG数据转换为dcmtk可以用来填充波形序列的格式。我不建议您采用这种方式,但这可能是避免编写大量代码的一种方法。


2
好的回答!由于这是一个C#问题,值得注意的是有一些开源的C# DICOM工具包可用,例如fo-dicomEvil DICOMClearCanvas - Anders Gustafsson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接