Click here to Skip to main content
15,896,423 members
Articles / Desktop Programming / WPF

Medical image visualization using WPF

Rate me:
Please Sign up or sign in to vote.
4.96/5 (68 votes)
27 Sep 2012CPOL6 min read 110K   7.7K   121  
The article demonstrates the visualization of medical images (DICOM) using WPF.
using System;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;

namespace DICOMViewer.Helper
{
    // The DICOMParserUtility provides easy access of the DICOM attributes via LINQ queries.

    class DICOMParserUtility
    {
        public static string GetDICOMAttributeAsString(XDocument theXDocument, string theAttribute)
        {
            if (theXDocument == null)
                return "???";

            if (theAttribute == null)
                return "???";

            var aQuery = from Element in theXDocument.Descendants("DataElement")
                         where Element.Attribute("Tag").Value.Equals(theAttribute)
                         select Element;

            if (aQuery.Count() > 0)
                return aQuery.Last().Attribute("Data").Value.Trim();

            return "???";
        }

        public static bool DoesDICOMAttributeExist(XDocument theXDocument, string theAttribute)
        {
            if (theXDocument == null)
                return false;

            if (theAttribute == null)
                return false;

            var aQuery = from Element in theXDocument.Descendants("DataElement")
                         where Element.Attribute("Tag").Value.Equals(theAttribute)
                         select Element;

            return (aQuery.Count() > 0);
        }

        public static Int32 GetDICOMAttributeAsInt(XDocument theXDocument, string theAttribute)
        {
            if (theXDocument == null)
                return -1;

            if (theAttribute == null)
                return -1;

            var aQuery = from Element in theXDocument.Descendants("DataElement").First().ElementsAfterSelf()
                         where Element.Attribute("Tag").Value.Equals(theAttribute)
                         select Element;

            if (aQuery.Count() > 0)
            {
                string s = aQuery.Last().Attribute("Data").Value.Trim();
                string[] split = s.Split(new Char[] { '\\' });

                return Convert.ToInt32(split[split.Length - 1], CultureInfo.InvariantCulture);
            }

            return -1;
        }

        public static double GetDICOMAttributeAsDouble(XDocument theXDocument, string theAttribute)
        {
            if (theXDocument == null)
                return -1;

            if (theAttribute == null)
                return -1;

            var aQuery = from Element in theXDocument.Descendants("DataElement").First().ElementsAfterSelf()
                         where Element.Attribute("Tag").Value.Equals(theAttribute)
                         select Element;

            if (aQuery.Count() > 0)
            {
                string s = aQuery.Last().Attribute("Data").Value.Trim();
                string[] split = s.Split(new Char[] { '\\' });

                return Convert.ToDouble(split[split.Length - 1], CultureInfo.InvariantCulture);
            }

            return -1;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Siemens Healthcare
Germany Germany
Currently working as a Requirement Engineer for Siemens Healthcare in Germany.

Comments and Discussions