# Read Image Meta-Data Dictionary and Print¶

## Overview¶

Reading an entire image potentially is memory and time intensive operation when the image is large or many files must be read. The image information and meta-data dictionary can be read without the bulk data by using the ImageFilerReader’s object oriented interface, with use of the ImageFileReader::ReadImageInformation method.

While all file formats support loading image information such as size, pixel type, origin, and spacing many image types do not have a meta-data dictionary. The most common case for images with a dictionary is DICOM, but also the fields from TIFF, NIFTI, MetaIO and other file formats maybe loaded into the meta-data dictionary.

For efficiency, the default DICOM reader settings will only load public tags (even group numbers). In the example we explicitly set the reader to also load private tags (odd group numbers). For further information on DICOM data elements see the standard part 5, Data Structures and Encoding.

## Code¶

#!/usr/bin/env python

from __future__ import print_function

import SimpleITK as sitk
import sys

if len(sys.argv) < 2:
print("Usage: DicomImagePrintTags <input_file>")
sys.exit(1)

print("({0}) = = \"{1}\"".format(k, v))

print("Image PixelType: {0}"

# Run with:
#
# Rscript --vanilla DicomImagePrintTags.R input_file
#

library(SimpleITK)

args <- commandArgs( TRUE )

if (length(args) <  1) {
write("Usage arguments: <input_file>", stderr())
quit(1)
}

reader$SetFileName(args[[1]]) reader$LoadPrivateTagsOn()
reader$ReadImageInformation() keys <- reader$GetMetaDataKeys()
print(sprintf("(%s) = \"%s\"", k, reader$GetMetaData(k))) } cat("Image Size: ", reader$GetSize(), '\n')