简体   繁体   English

邪恶的DICOM列出所有元素

[英]Evil DICOM list all elements

I would like to list all the tags of a DICOM file in C#. 我想在C#中列出DICOM文件的所有标签。

I would like something like what is shown in the link below 我想要类似下面链接中所示的内容

https://stackoverflow.com/a/7283042/1014189 https://stackoverflow.com/a/7283042/1014189

I'm assuming this is an older version as when I paste it into Visual Studio it is not recognised. 我假设这是一个较旧的版本,因为当我将其粘贴到Visual Studio中时无法识别。 Any help would be appreciated. 任何帮助,将不胜感激。

Assuming you could use Evil Dicom : 假设您可以使用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. 更新:根据您的评论,假设您需要在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 : 看看如何在Evil Dicom中定义IDICOMElement接口:

  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);    
dcm.AllElements
       .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. 但是,您需要小心,因为DICOMObject中的某些VR可能非常大,因此请确保使用异步方法或辅助线程进行处理,以使UI保持响应状态,并且除非特别需要,否则不要获取价值。 。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM