public static WindowLevel[] FromDataset(DcmDataset dataset) { List <WindowLevel> settings = new List <WindowLevel>(); if (dataset.Contains(DicomTags.WindowCenter) && dataset.Contains(DicomTags.WindowWidth)) { string[] wc = dataset.GetDS(DicomTags.WindowCenter).GetValues(); string[] ww = dataset.GetDS(DicomTags.WindowWidth).GetValues(); if (wc.Length != ww.Length) { throw new DicomImagingException("Window Center count does not match Window Width count"); } string[] desc = null; if (dataset.Contains(DicomTags.WindowCenterWidthExplanation)) { desc = dataset.GetLO(DicomTags.WindowCenterWidthExplanation).GetValues(); } for (int i = 0; i < wc.Length; i++) { double window; double level; if (!Double.TryParse(ww[i], out window) || !Double.TryParse(wc[i], out level)) { throw new DicomImagingException("Unable to parse Window/Level [wc: {0}; ww: {1}]", wc[i], ww[i]); } string description = String.Empty; if (desc != null && i < desc.Length) { description = desc[i]; } settings.Add(new WindowLevel(description, window, level)); } } return(settings.ToArray()); }