3.1 Dicom Functions

3.1.1 dicomanon

: dicomanon(file_in, file_out)
: dicomanon(___, name, value)

Anonymize a DICOM format file by removing or replacing specific fields.

Inputs

file_in is filename to read from.
file_out is the filename to write to.
name, value optional name/value properties.

Known property names are:

keep

The value is a cell array of names to not remove during the anonymize procedure.

update

A structure of name/values to update rather than remove.

Outputs

None

See also: dicomread, dicomwrite, dicominfo.

3.1.2 dicomdict

: dictionary_name = dicomdict ("get")
: dicomdict ("factory")
: dicomdict ("set", dictionary_name)

Get or set the active dicom data dictionary.

The first usage returns the filename of the dictionary that is currently being used. Using "factory" resets the dictionary to the default. Using "set" allows setting the dictionary for future operations. In this case, the dictionary file dictionary_name can be anywhere in the path.

Inputs

code - string value of ’get’, ’set’ or ’factory’.

dictionary_name’ - name of dictionary file to use

Outputs

dictionary_name’ - name of dictionary file currently set for dictionaty

Examples

Get current dicom dict path:

> f = dicomdict('get')
f = octavedicom.dic

Set a new dictionary:

> dicomdict('set', 'anewdictfile.txt')

See also: dicomread, dicomwrite.

3.1.3 dicomdisp

: dicomdisp (filename)
: dicomdisp (filename, [propertyname, propertvalue ...])

Read and display the metadata from a DICOM file.

Inputs

filename - dicomfilename to display.
propertyname, propertvalue - property pairs for options to the display function.

Currently the only known property is ’dictionary’ to specify a non default dict to use.

Outputs

None

See also: dicomread, dicominfo.

3.1.4 dicomfind

: attrinfo = dicomfind(filename, attribute)
: attrinfo = dicomfind(info, attribute)

Find the location and value of an attribute in a dicom file or info structure.

Inputs

filename - filename to open.

info - dicominfo struct.

attribute - attribute name to find.

Outputs

attrinfo - a table with fields Location and Value for each matched attribute.

The Location value will be the attribute position in dot notation to show its position in dicom info structure.

Examples

 filename = file_in_loadpath("imdata/rtstruct.dcm");

 info = dicomfind(filename, "ROINumber");

3.1.5 dicominfo

: info = dicominfo (filename)
: info = dicominfo (filename, "dictionary", dictionary-name)
: dicominfo (___, options)

Get all metadata from a DICOM file, excluding any actual image. info is a nested struct containing the data.

If the dictionary argument is used, the given dictionary-name is used for this operation, otherwise, the dictionary set by dicomdict is used.

Inputs

filename - name of file to read.

’dictionary’ - string constant of ’dictionary’.

dictionary-name - filename of dictionary to use.

options - a string in format of ’optionname=value’, or property/value pair ’optionname’, value: truncate=n where n is the number of characters to limit the dump output display to n for each value.

Outputs

info - struct of fields read frome the dicom file.

Examples

Read the metadata of a dicomfile:

> info = dicominfo(file_in_loadpath('imdata/simple-test.dcm')
info = 
scalar structure containing the fields:
Filename = a.dcm
FileModDate = 04-Feb-2017 02:08:31
FileMetaInformationVersion =
0  1
MediaStorageSOPClassUID = 1.2.840.10008.5.1.4.1.1.7
MediaStorageSOPInstanceUID = 1.2.826.0.1.3680043.2.1143.4379544382488839209812957878553810312
TransferSyntaxUID = 1.2.840.10008.1.2
ImplementationClassUID = 1.2.826.0.1.3680043.2.1143.107.104.103.115.2.6.3
ImplementationVersionName = GDCM 2.6.3
SourceApplicationEntityTitle = GDCM
ImageType = DERIVED \\SECONDARY  
SOPClassUID = 1.2.840.10008.5.1.4.1.1.7
SOPInstanceUID = 1.2.826.0.1.3680043.2.1143.4379544382488839209812957878553810312
StudyDate = 20170203
StudyTime = 210831.360586 
Modality = OT
ConversionType = WSD 
NominalScannedPixelSpacing =
1
1
StudyInstanceUID = 1.2.826.0.1.3680043.2.1143.1282184104726305239898701219563360204
SeriesInstanceUID = 1.2.826.0.1.3680043.2.1143.9385265081744858155080799316976198629
SamplesPerPixel = 1
PhotometricInterpretation = MONOCHROME1 
Rows = 10
Columns = 5
BitsAllocated = 8
BitsStored = 8
HighBit = 7
PixelRepresentation = 0
RescaleIntercept = 0
RescaleSlope =  1
RescaleType = US
PixelData = not assigned

See also: dicomread, dicomdict.

3.1.6 dicomlookup

: keyword = dicomlookup (group, element)
: [group, element] = dicomlookup (keyword)

Lookup an attribute in the DICOM data dictionary.

keyword = dicomlookup (group, element) will look in the current dicom dictionary for a specified group and element tag and returns string name of the attribute.

[group, element] = dicomlookup (keyword) will look in the current dicom dictionary for a specified keyword string and returns the group and element for keyword.

Inputs

keyword - string keyword name to look up a group, element value.
group - group value to look up (string or integer).
element - element value to look up (string or integer).

Outputs

keyword - string keyword name to looked up from a group, element value.
group, element - group and element value looked up from keyword.

Outputs

Look up tag name for 0x10 0x10:

> name = dicomlookup(0x10,0x10)
name = PatientName

Look up tag group and element value:

> [grp, elm] = dicomlookup('TransferSyntaxUID')
grp = 2
elm = 16

See also: dicomdict.

3.1.7 dicomread

: image = dicomread (filename)
: image = dicomread (structure)

Load the image from a DICOM file.

Inputs

filename - a string giving the filename.*

structure - a structure with a field Filename (such as returned by dicominfo).

image - may be two or three dimensional, depending on the content of the file.

Outputs

image - An integer or float matrix will be returned, the number of bits will depend on the file.

Examples

Load the image data of a dcm file:

> image = dicomread(file_in_loadpath('imdata/simple-test.dcm'))
image =
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0
0  0  0  0  0

See also: dicominfo.

3.1.8 dicomuid

: uuid = dicomuid ()

Generate a DICOM unique id .

Inputs

None

Outputs

uuid is a unique id string.

Examples

Get a new uid:

> uid = dicomuid ()
uid = 1.2.826.0.1.3680043.2.1143.3114589836670200378351641061429967573

3.1.9 dicomupdate

: info = dicomupdate(fileinfo, attribute, value)
: info = dicomupdate(info, attrinfo)

Update a dicom struct with new values

Inputs

info - dicominfo struct.

attribute - attribute name to find and change value of.

value - attribute value to set.

attrinfo - a table with fields Location and Value for each matched attribute to change.

Outputs

info - dicominfo struct.

Examples

 filename = file_in_loadpath("imdata/rtstruct.dcm");
 info = dicominfo(filename);

 % update specific values
 finfo = dicomfind(info, "ROINumber");
 finfo.Value{1} = 10;
 info = dicomupdate(info, finfo);

 % update all matching
 info = dicomupdate(info, "ROINumber", 100);

3.1.10 dicomwrite

: dicomwrite(im, filename)
: dicomwrite(im, filename, info)

Write a DICOM format file to filename.

Inputs

im - image data or empty matrix, [], if only metadata save is required

filename - filename to write dicom to. if [], then function runs in verbose trial mode.

info - struct, like that produced by dicominfo

Examples

Create a dicom file using default info, and the supplied data:

> wdata = uint8 (10*rand (10,10));
> dicomwrite (wdata, 'test.dcm');

Create a dicom file using data and meta info:

> wdata = dicomread(file_in_loadpath('imdata/CT-MONO2-16-ankle.dcm');
> info = dicominfo(file_in_loadpath('imdata/CT-MONO2-16-ankle.dcm');
> dicomwrite(wdata, info);

See also: dicomread, dicominfo.

3.1.11 images.dicom.decodeUID

: uidinfo = images.dicom.decodeUID(uid)

Look up information about a uid string

Inputs

uid - dicom uid string.

Outputs

uidinfo - a structure with fields of Value, Name and Type.

Additional fields may be present in the case of a Transfer Syntax type uid.

Examples

 > info = images.dicom.decodeUID("1.2.840.10008.1.1");
 info =
  scalar structure containing the fields:
    Value = 1.2.840.10008.1.1
    Name = Verification SOP Class
    Type = SOP Class

3.1.12 images.dicom.parseDICOMDIR

: info = images.dicom.parseDICOMDIR(filename)

Parse a DICOMDIR file and return the information as a struct.

Inputs

filename - filename to open.

Outputs

info - A struct containing the directory information from a DICOMDIR file

Th info structure will be an array of Patients, with an array of Studies with an array of Series with an array of Images.

Each element will contain a Payload field.

Examples

 filename = file_in_loadpath("imdata/DICOMDIR");

 info = images.dicom.parseDICOMDIR(filename);

3.1.13 isdicom

: yesno = isdicom (filename)

Return true if filename is a valid DICOM file.

Inputs

filename - name of file to read.

Outputs

yesno - logical value of true if filename is a dicom file.

See also: dicomdict, dicominfo, dicomread, dicomwrite.