Class DicomDataset
A DICOM dataset: data elements in file order, read-only, found by tag or by PS3.6 keyword. The file's main dataset, its file meta information and each item of a sequence are datasets.
[Experimental("EGAMIX001", UrlFormat = "https://github.com/inexin/Egami/blob/main/docs/articles/formats/dicom.md")]
public sealed class DicomDataset : IReadOnlyList<DicomElement>, IReadOnlyCollection<DicomElement>, IEnumerable<DicomElement>, IEnumerable
- Inheritance
-
DicomDataset
- Implements
- Inherited Members
Examples
// The dataset of a DICOM file, every element kept; the preview API needs EGAMIX001 suppressed.
DicomFile file = DicomFile.Load("scan.dcm");
Console.WriteLine($"{file.TransferSyntax.Name}, {file.Dataset.Count} elements");
// Elements by PS3.6 keyword or by tag, null when the file has none.
string? modality = file.Dataset.GetString("Modality");
double? rows = file.Dataset.GetNumber("Rows");
DicomElement? name = file.Dataset[new DicomTag(0x0010, 0x0010)];
foreach (EgamiDiagnostic warning in file.Warnings)
{
Console.WriteLine($"{warning.Id}: {warning.Message}");
}
Properties
Count
Gets the number of elements.
public int Count { get; }
Property Value
this[DicomTag]
Gets the element with a tag, or null when the dataset has none.
public DicomElement? this[DicomTag tag] { get; }
Parameters
tagDicomTagThe tag.
Property Value
- DicomElement
The element; the first one when a damaged file repeats a tag.
this[int]
Gets an element by its position in the file.
public DicomElement this[int index] { get; }
Parameters
indexintThe position, from 0.
Property Value
- DicomElement
The element.
Exceptions
- IndexOutOfRangeException
indexis outside the dataset.
this[string]
Gets the element a PS3.6 keyword names, such as PatientName, or null when the dataset has none.
public DicomElement? this[string keyword] { get; }
Parameters
keywordstringThe keyword; case matters.
Property Value
- DicomElement
The element.
Exceptions
- ArgumentNullException
keywordis null.- KeyNotFoundException
PS3.6 has no such keyword.
Methods
Contains(DicomTag)
Returns whether the dataset has an element with a tag.
public bool Contains(DicomTag tag)
Parameters
tagDicomTagThe tag.
Returns
- bool
Whether it is there.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<DicomElement> GetEnumerator()
Returns
- IEnumerator<DicomElement>
An enumerator that can be used to iterate through the collection.
GetNumber(string)
Returns the first number of an element, or null when the dataset has none or it is empty (see GetNumbers()).
public double? GetNumber(string keyword)
Parameters
keywordstringThe PS3.6 keyword, such as
Rows.
Returns
Exceptions
- KeyNotFoundException
PS3.6 has no such keyword.
- InvalidOperationException
The element holds no numbers.
- FormatException
A DS or IS value is not a number.
GetString(string)
Returns the text of an element, or null when the dataset has none (see GetString()).
public string? GetString(string keyword)
Parameters
keywordstringThe PS3.6 keyword, such as
Modality.
Returns
Exceptions
- KeyNotFoundException
PS3.6 has no such keyword.
- InvalidOperationException
The element holds bytes or items, not values.