Table of Contents

Class DicomDataset

Namespace
FellowOakDicom
Assembly
fo-dicom.core.dll

A collection of DICOM items.

public class DicomDataset : IEnumerable<DicomItem>, IEnumerable, IEquatable<DicomDataset>
Inheritance
DicomDataset
Implements
Derived
Inherited Members
Extension Methods

Constructors

DicomDataset()

Initializes a new instance of the DicomDataset class with InternalTransferSyntax set to Explicit VR Little Endian (DICOM default transfer syntax).

public DicomDataset()

DicomDataset(params DicomItem[])

Initializes a new instance of the DicomDataset class.

public DicomDataset(params DicomItem[] items)

Parameters

items DicomItem[]

An array of DICOM items.

DicomDataset(DicomTransferSyntax)

Initializes a new instance of the DicomDataset class.

public DicomDataset(DicomTransferSyntax internalTransferSyntax)

Parameters

internalTransferSyntax DicomTransferSyntax

Internal transfer syntax representation of the dataset.

DicomDataset(IEnumerable<DicomItem>)

Initializes a new instance of the DicomDataset class.

public DicomDataset(IEnumerable<DicomItem> items)

Parameters

items IEnumerable<DicomItem>

A collection of DICOM items.

Properties

AutoValidate

Gets or sets if the content of DicomItems shall be validated as soon as they are added to the DicomDataset

[Obsolete("Use this property with care. You can suppress validation, but be aware you might create invalid Datasets if you need to set this property.", false)]
public bool AutoValidate { get; set; }

Property Value

bool

CompareInstancesByContent

Gets or sets how two DicomDatasets are compared if dataset1 == dataset2 is called If this property is true, then all items are iterated and the content is compared. Then two DicomDatasets are equal if the content is equal. If this property is false, then the equalitycheck tests if the DicomDatasets are the same instance.

public static bool CompareInstancesByContent { get; set; }

Property Value

bool

InternalTransferSyntax

Gets the DICOM transfer syntax of this dataset.

public DicomTransferSyntax InternalTransferSyntax { get; }

Property Value

DicomTransferSyntax

Methods

Add(DicomItem)

Adds a DICOM item to the dataset.

public DicomDataset Add(DicomItem item)

Parameters

item DicomItem

DICOM item to add.

Returns

DicomDataset

The dataset instance.

Exceptions

ArgumentException

If tag of added item already exists in dataset.

Add(params DicomItem[])

Add a collection of DICOM items to the dataset.

public DicomDataset Add(params DicomItem[] items)

Parameters

items DicomItem[]

Collection of DICOM items to add.

Returns

DicomDataset

The dataset instance.

Exceptions

ArgumentException

If tag of added item already exists in dataset.

Add(IEnumerable<DicomItem>)

Add a collection of DICOM items to the dataset.

public DicomDataset Add(IEnumerable<DicomItem> items)

Parameters

items IEnumerable<DicomItem>

Collection of DICOM items to add.

Returns

DicomDataset

The dataset instance.

Exceptions

ArgumentException

If tag of added item already exists in dataset.

AddOrUpdate(DicomItem)

Add a DICOM item to the dataset. Update existing items.

public DicomDataset AddOrUpdate(DicomItem item)

Parameters

item DicomItem

DICOM item to add.

Returns

DicomDataset

The dataset instance.

AddOrUpdate(params DicomItem[])

Add a collection of DICOM items to the dataset. Update existing items.

public DicomDataset AddOrUpdate(params DicomItem[] items)

Parameters

items DicomItem[]

Collection of DICOM items to add.

Returns

DicomDataset

The dataset instance.

AddOrUpdate(IEnumerable<DicomItem>)

Add a collection of DICOM items to the dataset. Update existing items.

public DicomDataset AddOrUpdate(IEnumerable<DicomItem> items)

Parameters

items IEnumerable<DicomItem>

Collection of DICOM items to add.

Returns

DicomDataset

The dataset instance.

AddOrUpdate<T>(DicomTag, params T[])

Add or update a single DICOM item given by tag and values.

public DicomDataset AddOrUpdate<T>(DicomTag tag, params T[] values)

Parameters

tag DicomTag

DICOM tag of the added item.

values T[]

Values of the added item.

Returns

DicomDataset

The dataset instance.

Type Parameters

T

Type of added values.

AddOrUpdate<T>(DicomVR, DicomTag, params T[])

Add or update a single DICOM item given by vr, tag and values.

public DicomDataset AddOrUpdate<T>(DicomVR vr, DicomTag tag, params T[] values)

Parameters

vr DicomVR

DICOM vr of the added item. Use when setting a private element.

tag DicomTag

DICOM tag of the added item.

values T[]

Values of the added item.

Returns

DicomDataset

The dataset instance.

Type Parameters

T

Type of added values.

Remarks

No validation is performed on the vr matching the element tag This method is useful when adding a private tag and need to explicitly set the VR of the created element.

Add<T>(DicomTag, params T[])

Add single DICOM item given by tag and values.

public DicomDataset Add<T>(DicomTag tag, params T[] values)

Parameters

tag DicomTag

DICOM tag of the added item.

values T[]

Values of the added item.

Returns

DicomDataset

The dataset instance.

Type Parameters

T

Type of added values.

Exceptions

ArgumentException

If tag already exists in dataset.

Add<T>(DicomVR, DicomTag, params T[])

Add single DICOM item given by vr, tag and values.

public DicomDataset Add<T>(DicomVR vr, DicomTag tag, params T[] values)

Parameters

vr DicomVR

DICOM vr of the added item. Use when setting a private element.

tag DicomTag

DICOM tag of the added item.

values T[]

Values of the added item.

Returns

DicomDataset

The dataset instance.

Type Parameters

T

Type of added values.

Remarks

No validation is performed on the vr matching the element tag This method is useful when adding a private tag and need to explicitly set the VR of the created element.

Exceptions

ArgumentException

If tag already exists in dataset.

Clear()

Removes all items from the dataset.

public DicomDataset Clear()

Returns

DicomDataset

Current Dataset

Contains(DicomTag)

Checks the DICOM dataset to determine if the dataset already contains an item with the specified tag.

public bool Contains(DicomTag tag)

Parameters

tag DicomTag

DICOM tag to test

Returns

bool

True if a DICOM item with the specified tag already exists.

CopyTo(DicomDataset)

Copies all items to the destination dataset.

public DicomDataset CopyTo(DicomDataset destination)

Parameters

destination DicomDataset

Destination Dataset

Returns

DicomDataset

Current Dataset

CopyTo(DicomDataset, DicomMaskedTag)

Copies tags matching mask to the destination dataset.

public DicomDataset CopyTo(DicomDataset destination, DicomMaskedTag mask)

Parameters

destination DicomDataset

Destination Dataset

mask DicomMaskedTag

Tags to copy

Returns

DicomDataset

Current Dataset

CopyTo(DicomDataset, params DicomTag[])

Copies tags to the destination dataset.

public DicomDataset CopyTo(DicomDataset destination, params DicomTag[] tags)

Parameters

destination DicomDataset

Destination Dataset

tags DicomTag[]

Tags to copy

Returns

DicomDataset

Current Dataset

Equals(DicomDataset)

public bool Equals(DicomDataset other)

Parameters

other DicomDataset

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

FunctionalGroupValues(int)

Returns a DicomDataset, that contains all Tags accumulated from the Shared Functional Group Sequence and the Per-Frame Functional Group Sequence.

public DicomDataset FunctionalGroupValues(int frame)

Parameters

frame int

Zero-based frame index.

Returns

DicomDataset

Exceptions

DicomDataException

GetCodeItem(DicomTag)

public DicomCodeItem GetCodeItem(DicomTag tag)

Parameters

tag DicomTag

Returns

DicomCodeItem

GetDicomItem<T>(DicomTag)

Gets the DicomItem of the specified tag.

public T GetDicomItem<T>(DicomTag tag) where T : DicomItem

Parameters

tag DicomTag

Requested DICOM tag.

Returns

T

Item corresponding to tag or

null
if the tag is not contained in the instance.

Type Parameters

T

Type of the return value. Must inherit from DicomItem.

GetEnumerator()

Enumerates all DICOM items.

public IEnumerator<DicomItem> GetEnumerator()

Returns

IEnumerator<DicomItem>

Enumeration of DICOM items

GetHashCode()

public override int GetHashCode()

Returns

int

GetMeasuredValue(DicomTag)

public DicomMeasuredValue GetMeasuredValue(DicomTag tag)

Parameters

tag DicomTag

Returns

DicomMeasuredValue

GetPrivateTag(DicomTag)

Converts a dictionary tag to a valid private tag. Creates the private creator tag if needed.

public DicomTag GetPrivateTag(DicomTag tag)

Parameters

tag DicomTag

Dictionary DICOM tag

Returns

DicomTag

Private DICOM tag, or null if all groups are already used.

GetReferencedSOP(DicomTag)

public DicomReferencedSOP GetReferencedSOP(DicomTag tag)

Parameters

tag DicomTag

Returns

DicomReferencedSOP

GetSequence(DicomTag)

Gets the sequence of the specified tag.

public DicomSequence GetSequence(DicomTag tag)

Parameters

tag DicomTag

Requested DICOM tag.

Returns

DicomSequence

Sequence of datasets corresponding to tag.

Exceptions

DicomDataException

If the dataset does not contain tag or this is not a sequence.

GetSingleValueOrDefault<T>(DicomTag, T)

Gets the element value of the specified tag, whose value multiplicity has to be 1, or the provided defaultValue if the element value does not exist.

public T GetSingleValueOrDefault<T>(DicomTag tag, T defaultValue)

Parameters

tag DicomTag

Requested DICOM tag.

defaultValue T

Value that is returned if the requested element value does not exist.

Returns

T

Type Parameters

T

Type of the return value. This cannot be an array type.

GetSingleValue<T>(DicomTag)

Gets the element value of the specified tag, whose value multiplicity has to be 1.

public T GetSingleValue<T>(DicomTag tag)

Parameters

tag DicomTag

Requested DICOM tag.

Returns

T

Element values corresponding to tag.

Type Parameters

T

Type of the return value. This cannot be an array type.

Exceptions

DicomDataException

If the dataset does not contain tag, is empty or is multi-valued.

GetString(DicomTag)

Gets a string representation of the value of the specified tag.

public string GetString(DicomTag tag)

Parameters

tag DicomTag

Requested DICOM tag.

Returns

string

String representing the element value corresponding to tag.

Exceptions

DicomDataException

If the dataset does not contain tag.

GetValueCount(DicomTag)

Returns the number of values in the specified tag.

public int GetValueCount(DicomTag tag)

Parameters

tag DicomTag

Requested DICOM tag.

Returns

int

Exceptions

DicomDataException

If the dataset does not contain tag.

GetValueOrDefault<T>(DicomTag, int, T)

Gets the index-th element value of the specified tag or the provided defaultValue if the requested value is not contained in the dataset.

public T GetValueOrDefault<T>(DicomTag tag, int index, T defaultValue)

Parameters

tag DicomTag

Requested DICOM tag.

index int

Item index (for multi-valued elements).

defaultValue T

Value that is returned if the requested element value does not exist.

Returns

T

Type Parameters

T

Type of the return value. This cannot be an array type.

GetValue<T>(DicomTag, int)

Gets the index-th element value of the specified tag.

public T GetValue<T>(DicomTag tag, int index)

Parameters

tag DicomTag

Requested DICOM tag.

index int

Item index (for multi-valued elements).

Returns

T

Element value corresponding to tag.

Type Parameters

T

Type of the return value. This cannot be an array type.

Exceptions

DicomDataException

If the dataset does not contain tag or if the specified index is out-of-range.

GetValues<T>(DicomTag)

Gets the array of element values of the specified tag.

public T[] GetValues<T>(DicomTag tag)

Parameters

tag DicomTag

Requested DICOM tag.

Returns

T[]

Element values corresponding to tag.

Type Parameters

T

Type of the return value. This cannot be an array type.

Exceptions

DicomDataException

If the dataset does not contain tag.

Remove(params DicomTag[])

Removes items for specified tags.

public DicomDataset Remove(params DicomTag[] tags)

Parameters

tags DicomTag[]

DICOM tags to remove

Returns

DicomDataset

Current Dataset

Remove(Func<DicomItem, bool>)

Removes items where the selector function returns true.

public DicomDataset Remove(Func<DicomItem, bool> selector)

Parameters

selector Func<DicomItem, bool>

Selector function

Returns

DicomDataset

Current Dataset

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

TryGetNonEmptySequence(DicomTag, out DicomSequence)

Gets the sequence of the specified tag if it exists and is not empty.

public bool TryGetNonEmptySequence(DicomTag tag, out DicomSequence sequence)

Parameters

tag DicomTag

Requested DICOM tag.

sequence DicomSequence

Sequence of datasets corresponding to tag.

Returns

bool

Returns

true
if the tag exists and is not empty,
false
otherwise.

TryGetSequence(DicomTag, out DicomSequence)

Gets the sequence of the specified tag.

public bool TryGetSequence(DicomTag tag, out DicomSequence sequence)

Parameters

tag DicomTag

Requested DICOM tag.

sequence DicomSequence

Sequence of datasets corresponding to tag.

Returns

bool

Returns

true
if the tag could be returned as sequence,
false
otherwise.

TryGetSingleValue<T>(DicomTag, out T)

Tries to get the element value of the specified tag, whose value multiplicity has to be 1.

public bool TryGetSingleValue<T>(DicomTag tag, out T value)

Parameters

tag DicomTag

Requested DICOM tag.

value T

Returns

bool

Returns

true
if the element values could be exctracted, otherwise
false
.

Type Parameters

T

Type of the return value. This cannot be an array type.

TryGetString(DicomTag, out string)

Tries to get a string representation of the value of the specified tag.

public bool TryGetString(DicomTag tag, out string stringValue)

Parameters

tag DicomTag

Requested DICOM tag.

stringValue string

String representing the element value corresponding to tag.

Returns

bool

Returns

false
if the dataset does not contain the tag.

TryGetValue<T>(DicomTag, int, out T)

Tries to get the index-th element value of the specified tag.

public bool TryGetValue<T>(DicomTag tag, int index, out T elementValue)

Parameters

tag DicomTag

Requested DICOM tag.

index int

Item index (for multi-valued elements).

elementValue T

Element value corresponding to tag.

Returns

bool

Returns

true
if the element value could be exctracted, otherwise
false
.

Type Parameters

T

Type of the return value. This cannot be an array type.

TryGetValues<T>(DicomTag, out T[])

Tries to get the array of element values of the specified tag.

public bool TryGetValues<T>(DicomTag tag, out T[] values)

Parameters

tag DicomTag

Requested DICOM tag.

values T[]

Element values corresponding to tag.

Returns

bool

Returns

true
if the element values could be extracted, otherwise
false
.

Type Parameters

T

Type of the return value. This cannot be an array type.

Validate()

Performs a validation of all DICOM items that are contained in this DicomDataset. This explicit call for validation ignores the gobal DicomValidation.AutoValidate and DicomDataset.AutoValidate property.

public void Validate()

Exceptions

DicomValidationException

A exception is thrown if one of the items does not pass the valiation

ValidateTag(DicomTag)

Does nothing. Can be overwritten in derived classes to check if the tag is allowed.

protected virtual void ValidateTag(DicomTag tag)

Parameters

tag DicomTag

Operators

operator ==(DicomDataset, DicomDataset)

public static bool operator ==(DicomDataset a, DicomDataset b)

Parameters

a DicomDataset
b DicomDataset

Returns

bool

operator !=(DicomDataset, DicomDataset)

public static bool operator !=(DicomDataset a, DicomDataset b)

Parameters

a DicomDataset
b DicomDataset

Returns

bool