0

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

Martin Nemeth
  • 659
  • 3
  • 16
  • 24
  • 1
    It is a binary file that contain ascii string. So you can do it either in Matlab or c#. See following link : http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.2.html#table_6.2-1 and http://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_7.html#figure_7.1-1 – jdweng Jul 13 '18 at 09:13
  • Just google "Read DICOM file in ________ language". Its a common file format, you will find the answer you want ;) – Ander Biguri Jul 13 '18 at 09:18

1 Answers1

2

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);
            }
        }

    }


}
jdweng
  • 33,250
  • 2
  • 15
  • 20