## Overview¶

1. Querying an image for its meta-data without reading the bulk intensity data.

2. Reading a sub-region of an image.

### Querying an image for its meta-data¶

In some cases you may only want to read an image’s meta-data without reading the bulk intensity data into memory. For instance, if you want to read subregions of an image and not the whole image or if you want to display image information (e.g. patient name) to a user in a GUI which then allows them to select a specific image.

In some cases you are only interested in reading a sub-region of an image. This may be due to memory constraints or if it is known that the relevant content is always in a sub region of the image. If the specific image IO used for this operation supports streaming then this will indeed only read the sub-region, otherwise the whole image is read into memory and the sub-region is returned. The IOs that support streaming are: 1. TIFFImageIO (supports a subset of encodings) 2. MetaImageIO 3. NrrdImageIO 4. HDF5ImageIO (supports a subset of encodings) 5. MRCImageIO 6. VTKImageIO (supports a subset of encodings)

## Code¶


import sys

import SimpleITK as sitk
import numpy as np

if len(sys.argv) < 2:
print('Wrong number of arguments.', file=sys.stderr)
print('Usage: ' + __file__ + ' image_file_name', file=sys.stderr)
sys.exit(1)

# Some files have a rich meta-data dictionary (e.g. DICOM)
print('-' * 20)

# When low on memory, we can incrementally work on sub-images. The following
# subtracts two images (ok, the same image) by reading them as multiple'
# sub-images.

image1_file_name = sys.argv[1]
image2_file_name = sys.argv[1]

parts = 5  # Number of sub-regions we use

extract_size[-1] = extract_size[-1] // parts
for i in range(parts):
if i == (parts - 1):
extract_size[-1] = image_size[-1] - current_index[-1]

idx[-1] = current_index[-1]
result_img[idx] =  sub_image1 - sub_image2
current_index[-1] += extract_size[-1]
del sub_image1
del sub_image2

# Check that our iterative approach is equivalent to reading the whole images.
if np.any(sitk.GetArrayViewFromImage(result_img