James James - 1 year ago 359
C# Question

Evil DICOM list all elements

I would like to list all the tags of a DICOM file in C#.

I would like something like what is shown in the link below


I'm assuming this is an older version as when I paste it into Visual Studio it is not recognised. Any help would be appreciated.

Answer Source

Assuming you could use Evil Dicom:

public class DicomManager
    public List<Tag> ReadAllTags(string dicomFile)
        var dcm = DICOMObject.Read(dicomFile);
        return dcm.AllElements.Select(e => e.Tag).ToList();

UPDATE: As per your comment, let's say you need to show the elements in a component on the UI. I'll give you an example of how you could show all the elements in a console app, but the traversing algorithm is the same in any other presentation technology.

Take a look at how is defined IDICOMElement interface in Evil Dicom:

  public interface IDICOMElement
    Tag Tag { get; set; }

    Type DatType { get; }

    object DData { get; set; }

    ICollection DData_ { get; set; }

It means that an element has all the info you would need to work with it.

Iterate the elements and show the tag name - element value.

var dcm = DICOMObject.Read(dicomFile);    
       .ForEach(element => Console.WriteLine("{0} - {1}", element.Tag, element.DData));

As you can see, if all you want is to show the value - its string representation - the previous snippet should be enough, but in the element you have more info about the real type of the object inside as well as the collection of values - in case of multi-valued elements.

However you need to be careful because some VRs inside a DICOMObject can be very large, so make sure you do the processing using async methods or worker threads in order to keep you UI responsive and don't get a value out unless you specifically need to.

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download