File Exchange

image thumbnail

Dicom Tags Read and Write

version (811 KB) by Dirk-Jan Kroon
Read / Write raw Dicom tags with large dictionary, for small file manipulations, like anonymize


Updated 23 Feb 2011

View Version History

View License

There are two main files, "ReadDicomElementList" which will read all tags of a dicom file into a struct and "WriteDicomElementList" which can write them back to a new file.

A large dicom dictionary is included from GDCM with private tags from Philips, Siemens and Toshiba (See Dictionary-License.txt).

These functions are usable for creation of an anatomize function, or to manipulate data which is not support by Matlab defaults functions (like writing a dicom file with one big volume inside)

Example read output:

>> Elements(4)
name: 'MediaStorageSOPInstanceUID'
data: '1.2.840.113619.'
group: '0002'
number: '0003'
type: 'UI'
length: 46
info: 'Type Included'
explicit: 1
location: 192

Cite As

Dirk-Jan Kroon (2021). Dicom Tags Read and Write (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Joseph Ziminski

excellent, thanks!

Hossam El-Rewaidy

Zhiyan Wang

Thank you!


I have tried to get tag list for DICOM file generated by a Philips Epiq 5 ultrasound scanner and I got an error:

>> elementlist=ReadDicomElementList('IM_0001')
138, element.length, 'uint8')';
Error using fread
Invalid size.
Error in ReadDicomElementList>ReadDicomElement (line 138), element.length, 'uint8')';
Error in ReadDicomElementList (line 65)

Any idea what may be the reason?


I'm running into a situation where the ReadDicomElement function fails to read the PixelData because the defined size is -1 (line 139 of ReadDicomElementList.m). A comment in the calling functionReadDicomElementList says it will "Read all tags until the PixelData is reached" but it proceeds to read until the end of the file is reached. How can one handle the OB-type PixelData element with element.length = -1?

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!