如何从原始ecg数据写入DICOM文件

时间:2016-10-19 02:36:15

标签: c# .net dicom

我有csv格式的原始ecg电压样本,例如:

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查看器中查看它,例如c#的ECG工具包: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;
                }
            }
        }


    }
}

注意:我只对“引导我”感兴趣,但您可以在此行中添加更多潜在客户: var leadType = new LeadType [] {LeadType.I}

注意:这不是我的代码,这来自上面sourceforge链接中的一个讨论。

1 个答案:

答案 0 :(得分:3)

我的建议:

  1. 选择DICOM工具包 单独实现DICOM数据的二进制编码没有任何意义。
  2. 查看DICOM Information Object Definition for ECG Waveform 上面的链接定义了12-Lead-Waveform对象。如果您的数据不是12导联,请选择this。我提供的链接指向模块表,通过链接,您可以看到此类对象必须/允许的属性。
  3. 您将不可避免地要了解有关DICOM术语的基本知识以及在标准中查找信息的位置。我强烈建议this文件作为起点。对于此任务,请确保了解信息对象定义(IOD),模块,属性类型(类型1,2,3)和值表示(VR)
  4. 然后它非常直接。浏览您选择的IOD的强制属性(我提到的两个中的一个),并使用您选择的工具包填充它们。然后使用工具包将文件写入磁盘,您就完成了。确保将数据写为带有元标题的DICOM文件。一个好的工具包在将数据集写入磁盘时提供了该选项。

    请注意,简单地将DICOM文件写入磁盘不是“官方DICOM接口”。要在不同的DICOM应用程序之间交换数据,您必须使用网络协议(在您的情况下为Storage Service Class)或创建符合DICOM标准的媒体(这会对使用的媒体,文件格式,文件名提出一些限制,并要求包含DICOM目录文件列出媒体内容。)

    当您要求使用工具时,您可能需要查看DCMTK。有不同的方法来完成任务。 dcmdump或dcmodify将成为深入了解的工具。但是,这样做很麻烦,您可能需要将ECG数据转换为dcmtk可用于填充波形序列的格式。我并不建议你这样做,但这可能是一种避免编写大量代码的方法。

相关问题