Table of Contents

Class DicomDataset

Namespace
Egami.Formats.Extended.Dicom
Assembly
Egami.Formats.Extended.dll

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

int

this[DicomTag]

Gets the element with a tag, or null when the dataset has none.

public DicomElement? this[DicomTag tag] { get; }

Parameters

tag DicomTag

The 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

index int

The position, from 0.

Property Value

DicomElement

The element.

Exceptions

IndexOutOfRangeException

index is 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

keyword string

The keyword; case matters.

Property Value

DicomElement

The element.

Exceptions

ArgumentNullException

keyword is 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

tag DicomTag

The 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

keyword string

The PS3.6 keyword, such as Rows.

Returns

double?

The number, or null.

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

keyword string

The PS3.6 keyword, such as Modality.

Returns

string

The text, or null.

Exceptions

KeyNotFoundException

PS3.6 has no such keyword.

InvalidOperationException

The element holds bytes or items, not values.