How to get raw ecg data from DICOM file?

ぃ、小莉子 提交于 2019-12-24 19:43:11

问题


I would like to obtain raw ecg data (time - voltage) from a dcm file I have. I would like to do that in MATLAB, hovever if there is any other way, please let me know. Thank you


回答1:


The following code will get the elements. Not sure if the values are Big Endian or Little Endian so the bytes may need to be swapped.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication51
{

    class Program
    {
        const string FILENAME = @"c:\temp\test.dcm";

        static void Main(string[] args)
        {
           new DataElement(FILENAME);
        }
    }
    public class DataElement
    {
        public static List<DataElement> elements = null;

        public UInt16 groupNumber { get; set; }
        public UInt16 elementNumber { get; set; }
        public string vr { get; set; }
        public byte[] reserved { get; set; }
        public uint length { get; set; }
        public byte[] values { get; set; }

        public DataElement() { }
        public DataElement(string filename)
        {
            elements = new List<DataElement>();

            Stream stream = File.OpenRead(filename);
            BinaryReader bReader = new BinaryReader(stream);

            long length = stream.Length;
            while (stream.Position < length)
            {
                DataElement element = new DataElement();
                elements.Add(element);

                element.groupNumber = bReader.ReadUInt16();
                element.elementNumber = bReader.ReadUInt16();
                element.vr = bReader.ReadChars(2).ToString();
                element.reserved = bReader.ReadBytes(2);
                element.length = bReader.ReadUInt32();
                element.values = bReader.ReadBytes((int)element.length);
            }
        }

    }


}


来源:https://stackoverflow.com/questions/51321476/how-to-get-raw-ecg-data-from-dicom-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!