Introducing a new way to review your PRs.

Read the announcement

insightsoftwareconsortium / itk

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.

View on GitHub

19 documents · Updated Nov 23, 2026

docs / image-data-representation

Image data and geometric representation

ITK represents sampled data as images with typed pixel values, indexed regions, and physical-space geometry. Algorithms use this shared model to read or change pixels, work on bounded parts of an image, convert between grid and physical coordinates, and evaluate image-derived values at exact or subpixel positions. This page extends the core data model with the image-specific concepts that connect data access to spatial meaning.

Image data model

Images and pixel values

An image is an n-dimensional grid of samples. Its pixel type can be a scalar, a fixed or variable-length value, a color value, or another type that an algorithm supports. The image keeps the grid geometry separate from the pixel values, so the same access model can serve different kinds of image data. Modules/…/itkImage.h• L34-64 Modules/…/itkImage.h• L87-145

An image exposes direct pixel access and region-based access. Algorithms normally use the image's index type to name a sample and use a pixel container to hold the linear sample buffer. The first index dimension is the fastest moving dimension in that buffer. ImageBase keeps the matching offset table so algorithms can move between an index and its position in the buffered data. Modules/…/itkImage.h• L41-52 Modules/…/itkImageBase.h• L352-365 Modules/…/itkImageHelper.h• L25-45

References: Modules/…/itkImage.h• L34-64 Modules/…/itkImage.h• L87-145 Modules/…/itkImageBase.h• L352-365 Modules/…/itkImageHelper.h• L48-113

Pixel containers

The pixel container provides the storage boundary between an image and its sample buffer. It supports allocation, indexed access, and import of an existing memory block. An imported block can remain owned by the calling application or become owned by the container, so the ownership choice is part of the data contract. Modules/…/itkImportImageContainer.h• L27-42 Modules/…/itkImportImageContainer.h• L66-80

The container reports its size and exposes a buffer pointer for image access tools. Image allocation must match the image region before algorithms use direct pixel access. Modules/…/itkImportImageContainer.h• L82-116 Modules/…/itkImage.h• L187-210

References: Modules/…/itkImportImageContainer.h• L27-42 Modules/…/itkImportImageContainer.h• L66-80 Modules/…/itkImportImageContainer.h• L82-116 Modules/…/itkImage.h• L187-210

Image regions

Structured image regions

An ImageRegion is a rectangular part of an image grid. It is defined by an index at one corner and a size along each dimension. Regions let algorithms name the whole image, a loaded part, or a work area without copying the pixel data. Modules/…/itkImageRegion.h• L55-68 Modules/…/itkImageRegion.h• L154-205

The image model uses three regions with different roles:

RegionMeaning
Largest possible regionThe full dataset extent that the image can represent.
Buffered regionThe part of that extent whose pixels are present in memory.
Requested regionThe part that the pipeline asks an upstream data source to produce.

The pipeline uses these roles to control memory use and work division. A request can be smaller than the full dataset, but an algorithm must only read pixels that are in the buffered region. See pipeline execution for how requested regions guide processing. Modules/…/itkImageBase.h• L78-89 Modules/…/itkImageBase.h• L270-340

References: Modules/…/itkImageRegion.h• L55-68 Modules/…/itkImageRegion.h• L154-205 Modules/…/itkImageBase.h• L78-89 Modules/…/itkImageBase.h• L270-340

Image I/O regions

An ImageIORegion is a run-time sized structured region used to describe a portion of image data for image input and output. It uses an index and size for each dimension, but its index is relative to the I/O extent rather than necessarily matching the image's actual index. Modules/…/itkImageIORegion.h• L28-48 Modules/…/itkImageIORegion.h• L77-89

ImageIORegionAdaptor translates between an ImageIORegion and a typed ImageRegion. The translation uses the largest possible image-region index and fills dimensions that exist in only one representation with defined defaults. This keeps I/O requests compatible with images whose largest region does not start at zero. Modules/…/itkImageIORegion.h• L199-280

References: Modules/…/itkImageIORegion.h• L28-48 Modules/…/itkImageIORegion.h• L77-89 Modules/…/itkImageIORegion.h• L199-280

Region splitting

Region splitting divides one image region into smaller rectangular pieces for streaming and parallel work. The splitter first reports how many pieces the region can support, then returns each piece for the source or filter that will process it. This keeps work division within the image's structured bounds and also supports image I/O regions. Modules/…/itkImageRegionSplitterBase.h• L28-49 Modules/…/itkImageRegionSplitterBase.h• L72-117

References: Modules/…/itkImageRegionSplitterBase.h• L28-49 Modules/…/itkImageRegionSplitterBase.h• L72-117

Physical-space geometry

Coordinate systems

An image has two linked coordinate systems. An integer Index identifies a stored sample on the image grid. A ContinuousIndex identifies a subpixel location on that grid. A physical Point identifies a location in the external space described by the image metadata. Modules/…/itkIndex.h• L30-35 Modules/…/itkContinuousIndex.h• L28-45 Modules/…/itkPoint.h• L30-39

The image maps between these systems through three pieces of metadata:

MetadataSpatial meaning
OriginPhysical location of the zero index.
SpacingPhysical distance between samples along each image dimension.
DirectionOrientation of each image dimension in physical space.

The mapping also supports physical vectors and image-local vectors. Algorithms that use distances, derivatives, registration, or sampling must preserve this geometry rather than treat an index as a physical coordinate. Modules/…/itkImageBase.h• L56-101 Modules/…/itkImageBase.h• L156-171 Modules/…/itkImageBase.h• L620-717

References: Modules/…/itkIndex.h• L30-35 Modules/…/itkContinuousIndex.h• L28-45 Modules/…/itkPoint.h• L30-39 Modules/…/itkImageBase.h• L56-101 Modules/…/itkImageBase.h• L156-171 Modules/…/itkImageBase.h• L620-717

Coordinate conversion

Image geometry converts an index to a physical point and converts a physical point back to a continuous index. Conversion to a discrete index rounds the continuous result, while continuous conversion keeps subpixel information. The conversion that checks bounds uses the largest possible region, so callers must also check the buffered region before reading data. Modules/…/itkImageBase.h• L448-459 Modules/…/itkImageBase.h• L500-552 Modules/…/itkImageBase.h• L587-617

This relationship lets an algorithm accept a physical location while using the image grid for data access:

flowchart LR
    P[Physical point] --> C[Continuous index]
    C --> I[Discrete index]
    I --> V[Stored pixel]
    V --> C
    C --> P

References: Modules/…/itkImageBase.h• L448-459 Modules/…/itkImageBase.h• L500-552 Modules/…/itkImageBase.h• L587-617

Image representations

Vector image values

VectorImage represents several measurements at each grid location. Its public pixel value behaves like a variable-length vector, while the image stores the component values in one contiguous buffer. The vector length is image data metadata and must agree with the data supplied to algorithms. Modules/…/itkVectorImage.h• L30-50 Modules/…/itkVectorImage.h• L99-125 Modules/…/itkVectorImage.h• L168-206

This representation is useful for multi-channel or multi-measurement images because it keeps the spatial grid unchanged while adding a component dimension to each sample. Algorithms that use vector pixels access them through the image access API rather than assuming that one buffer element is one complete pixel. Modules/…/itkVectorImage.h• L203-206 Modules/…/itkVectorImage.h• L220-266

References: Modules/…/itkVectorImage.h• L30-50 Modules/…/itkVectorImage.h• L99-125 Modules/…/itkVectorImage.h• L168-206 Modules/…/itkVectorImage.h• L220-266

Image adaptors

An ImageAdaptor presents an existing image through a different pixel view. An accessor defines how the external pixel value is read from or written to the internal pixel value. The adaptor keeps the source image and its spatial regions while allowing a filter to operate on a selected or transformed part of each pixel. Modules/…/itkImageAdaptor.h• L30-45 Modules/…/itkImageAdaptor.h• L55-99 Modules/…/itkImageAdaptor.h• L147-201

For example, a color image can be presented as a luminance image without first making a separate image. This makes adaptors a bridge between a storage representation and the pixel interface expected by an algorithm. Modules/…/itkRGBToLuminanceImageAdaptor.h• L29-36 Modules/…/itkRGBToLuminanceImageAdaptor.h• L67-80

References: Modules/…/itkImageAdaptor.h• L30-45 Modules/…/itkImageAdaptor.h• L55-99 Modules/…/itkImageAdaptor.h• L147-201 Modules/…/itkRGBToLuminanceImageAdaptor.h• L67-80

Image access

Pixel iterators

Image iterators move through a selected region without requiring an algorithm to manage buffer offsets and region boundaries itself. Region iterators are the general choice for pixel-wise work. Index-aware variants also expose the current grid location, and specialized iterators support lines, slices, reverse order, random sampling, or exclusion regions. Modules/…/itkImageRegionIterator.h• L25-39 Modules/…/itkImageIteratorWithIndex.h• L25-34 Modules/…/itkImageSliceIteratorWithIndex.h• L26-35 Modules/…/itkImageRandomConstIteratorWithIndex.h• L51-67 Modules/…/itkImageRegionReverseConstIterator.h• L27-60

The iterator family separates read-only traversal from write-capable traversal. The shared iterator definition now establishes the image, region, buffer, and pixel-access state used by both forms. A writable iterator can convert to its read-only counterpart without losing its traversal position, while const image types prevent writes. This keeps one region and movement model for reading and writing. Modules/…/itkImageIterator.h• L48-71 Modules/…/itkImageIterator.h• L176-203 Modules/…/itkImageIterator.h• L448-481 Modules/…/itkImageConstIterator.h• L18-23

The main traversal choices are:

Iterator formUse
RegionVisit pixels in a rectangular region.
With indexVisit a region while exposing each grid index.
Linear or scanlineProcess one line at a time. Linear traversal can choose an image direction; scanline traversal follows the fastest axis.
SliceProcess one slice at a time.
ReverseVisit a region in reverse scan order.
RandomTake a requested number of random samples from a region. A position can occur more than once.
Random non-repeatingSelect random positions without visiting the same position twice.
Region exclusionVisit the selected region while excluding another region.

Read-only and write-capable forms make the access contract clear. The direct reference form is fast but does not support image adaptors; the accessor-aware Get and Set path works with adapted pixel views. Linear traversal moves along a selected image axis and uses explicit line transitions. Scanline traversal uses the fastest axis for a compact line-by-line pass. Modules/…/itkImageRegionIterator.h• L114-128 Modules/…/itkImageIteratorWithIndex.h• L108-122 Modules/…/itkImageLinearConstIteratorWithIndex.h• L26-47 Modules/…/itkImageLinearConstIteratorWithIndex.h• L154-230 Modules/…/itkImageScanlineConstIterator.h• L26-53 Modules/…/itkImageScanlineConstIterator.h• L169-243

Random index-aware traversal chooses a new position on each increment or decrement and can reset its random seed. The non-repeating form selects a random permutation of the region, so it visits each selected position at most once. It can limit the sample count and can use a priority image to select lower-priority positions first. Reverse region traversal moves across each row in reverse and wraps to the preceding row. Modules/…/itkImageRandomConstIteratorWithIndex.h• L183-251 Modules/…/itkImageRandomNonRepeatingConstIteratorWithIndex.h• L153-179 Modules/…/itkImageRandomNonRepeatingConstIteratorWithIndex.h• L314-370 Modules/…/itkImageRegionReverseConstIterator.h• L191-231

Modern range types provide a standard C++ range interface for buffered image pixels or selected regions. ImageBufferRange covers the pixels in the image's buffered region and supports forward, reverse, and random access for range-based loops and standard algorithms. It uses direct pixel references when the storage matches the public pixel type, and an accessor-aware proxy when the image presents a different pixel view. Modules/…/itkImageBufferRange.h• L38-70 Modules/…/itkImageBufferRange.h• L89-105 Modules/…/itkImageBufferRange.h• L557-671 Modules/…/itkImageRegionRange.h• L36-68

References: Modules/…/itkImageIterator.h• L48-71 Modules/…/itkImageIterator.h• L176-203 Modules/…/itkImageIterator.h• L320-395 Modules/…/itkImageConstIterator.h• L18-23 Modules/…/itkImageRegionIterator.h• L25-39 Modules/…/itkImageRegionIterator.h• L114-128 Modules/…/itkImageIteratorWithIndex.h• L25-34 Modules/…/itkImageLinearConstIteratorWithIndex.h• L26-47 Modules/…/itkImageLinearConstIteratorWithIndex.h• L154-230 Modules/…/itkImageRandomNonRepeatingConstIteratorWithIndex.h• L153-179 Modules/…/itkImageRandomNonRepeatingConstIteratorWithIndex.h• L314-370 Modules/…/itkImageRandomConstIteratorWithIndex.h• L51-67 Modules/…/itkImageRandomConstIteratorWithIndex.h• L183-251 Modules/…/itkImageRegionReverseConstIterator.h• L27-60 Modules/…/itkImageRegionReverseConstIterator.h• L191-231 Modules/…/itkImageScanlineConstIterator.h• L26-53 Modules/…/itkImageScanlineConstIterator.h• L169-243 Modules/…/itkImageBufferRange.h• L38-70 Modules/…/itkImageBufferRange.h• L89-105 Modules/…/itkImageBufferRange.h• L557-671 Modules/…/itkImageRegionRange.h• L36-68

Neighborhood iterators

A neighborhood iterator moves a local n-dimensional mask across an image. Each position exposes the center sample and its surrounding samples as an indexed neighborhood. This gives localized algorithms a common way to express convolution, derivatives, and morphology. Modules/…/itkNeighborhoodIterator.h• L29-45 Modules/…/itkNeighborhoodIterator.h• L91-100

When the mask reaches an image edge, an ImageBoundaryCondition supplies the value for the outside sample. The boundary object can also state whether it needs a complete neighborhood and can describe the input region needed for an output request. This links edge behavior to pipeline region requests. Modules/…/itkImageBoundaryCondition.h• L27-37 Modules/…/itkImageBoundaryCondition.h• L91-106 Modules/…/itkImageBoundaryCondition.h• L117-143

The iterator keeps its movement constrained to a region of interest. Its movement follows image memory order, not a general physical direction, so geometric operations must still use image metadata when direction or spacing matters. Modules/…/itkNeighborhoodIterator.h• L86-95 Modules/…/itkNeighborhoodIterator.h• L151-165

References: Modules/…/itkNeighborhoodIterator.h• L29-45 Modules/…/itkNeighborhoodIterator.h• L86-100 Modules/…/itkNeighborhoodIterator.h• L151-165 Modules/…/itkImageBoundaryCondition.h• L27-37 Modules/…/itkImageBoundaryCondition.h• L91-106 Modules/…/itkImageBoundaryCondition.h• L117-143

Image functions

Image evaluations

An ImageFunction evaluates a value derived from an input image at a physical point, a discrete index, or a continuous index. It is the common interface for operations that query an image rather than walk every stored sample. Modules/…/itkImageFunction.h• L28-45 Modules/…/itkImageFunction.h• L103-130

Image functions use the input image's geometry to convert physical points to image coordinates. They track buffered bounds so callers can test whether a query can read resident data. After the buffered region changes, the input image must be set again so the function's bounds match the image. Modules/…/itkImageFunction.h• L42-45 Modules/…/itkImageFunction.h• L132-184

References: Modules/…/itkImageFunction.h• L28-45 Modules/…/itkImageFunction.h• L103-130 Modules/…/itkImageFunction.h• L132-184

Interpolation

Interpolation functions turn a continuous index into an image value by combining nearby samples. The base interpolation interface treats a physical point as a coordinate-conversion step and treats a discrete index as direct pixel lookup. Concrete policies can use different sampling neighborhoods, such as nearest-neighbor or linear interpolation. Modules/…/itkInterpolateImageFunction.h• L25-38 Modules/…/itkInterpolateImageFunction.h• L87-136

Interpolation calls assume that the requested location is inside the image buffer. The caller must use the image-function bounds check when the location may be outside the resident data. Vector-valued images use the vector interpolation family rather than the scalar interpolation family. Modules/…/itkInterpolateImageFunction.h• L87-127

References: Modules/…/itkInterpolateImageFunction.h• L25-38 Modules/…/itkInterpolateImageFunction.h• L87-136

Spatial functions

A SpatialFunction maps an arbitrary n-dimensional point to a value without depending on an image. It provides the image-independent counterpart to an image function and is useful when the rule is defined by space alone. Modules/…/itkSpatialFunction.h• L26-45 Modules/…/itkSpatialFunction.h• L59-71

This distinction matters when an algorithm needs a physical shape or field rather than a sampled image. An image function uses image geometry and buffered data; a spatial function evaluates its rule directly at the supplied point. Modules/…/itkImageFunction.h• L28-45 Modules/…/itkSpatialFunction.h• L26-39

References: Modules/…/itkSpatialFunction.h• L26-45 Modules/…/itkSpatialFunction.h• L59-71 Modules/…/itkImageFunction.h• L28-45

Structured and unstructured regions

The shared Region concept describes a portion of data for memory limits, user-selected work, or parallel processing. An image uses a structured region, which is a rectangle described by an index and size. A mesh uses an unstructured region, which identifies one piece among a set of pieces. Modules/…/itkRegion.h• L36-52 Modules/…/itkMeshRegion.h• L39-50

This difference lets pipeline code reason about a data portion without forcing images and meshes to use the same bounds model. For mesh geometry and object types, see mesh and spatial objects. Modules/…/itkRegion.h• L47-63 Modules/…/itkMeshRegion.h• L70-108

References: Modules/…/itkRegion.h• L36-63 Modules/…/itkMeshRegion.h• L39-50 Modules/…/itkMeshRegion.h• L70-108

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to ImageBase region roles must stay aligned with pipeline requested-region behavior and with adaptors that delegate region state to their source image.
  • Changes to ImageIORegion conversion must preserve zero-based I/O indices, the largest-region index offset, and the defaults for dimensions that do not overlap.
  • Changes to offset-table or index/offset conversion logic must stay aligned with the buffered-region index and with every iterator that uses buffer order.
  • Changes to region splitting must preserve the contract between the reported split count and the pieces returned for streaming, parallel work, and image I/O.
  • Changes to origin, spacing, direction, or coordinate conversion must preserve the agreement between physical-point queries and index-based algorithm access.
  • Changes to pixel access must keep direct, accessor-aware, vector-image, and adaptor paths consistent.
  • Changes to imported-buffer ownership must remain clear for callers that provide external memory.
  • Changes to iterator traversal or writable iterator construction must preserve the matching const traversal state and any image-buffer preparation needed by the image type.
  • Changes to iterator order, random sampling, or region exclusion must preserve the stated visit set and coordinate behavior for each specialized iterator. Random sampling must retain its requested sample count and seed behavior.
  • Changes to linear or scanline traversal must preserve line boundaries, selected direction, and the requirement to stop before incrementing past a line.
  • Changes to boundary-condition input-region logic must remain consistent with neighborhood needs and streamed requested regions.
  • Changes to interpolation bounds or cached buffered-region state must remain safe for images whose resident region changes during pipeline execution.
  • Changes to ImageBufferRange must preserve the distinction between direct pixel references and accessor-aware proxy access, along with its buffered-region size and standard range behavior.

Important failure modes

TriggerConsequenceGuard
A physical point is converted with stale or incorrect origin, spacing, or direction.The algorithm reads a valid pixel at the wrong physical location.Treat image geometry as part of the image data contract and use the image conversion methods.
A query is inside the largest possible region but outside the buffered region.An image function or interpolator can read data that is not resident.Check IsInsideBuffer before evaluation when the query location is not known to be resident.
An image function keeps cached bounds after its input buffered region changes.Bounds checks use old limits.Call SetInputImage again after the buffered region changes.
An algorithm uses direct iterator Value() access on an image adaptor.It bypasses the adapted pixel view.Use accessor-aware Get and Set operations for adapted or vector-valued images.
A writable iterator or its source image does not prepare mutable buffer access.A write can target unavailable or unsuitable storage.Construct writable iterators from a ready image and preserve the mutable buffer-access path.
A specialized iterator's region, order, or exclusion state is misunderstood.Pixels can be skipped, repeated, or visited in an unexpected order.Choose the iterator that matches the required visit set and treat its traversal contract as part of the algorithm.
A random iterator is treated as if it visits each region position once.A sample set can contain duplicate positions or produce a different sequence after a seed change.Use the non-repeating random iterator when uniqueness is required, and set the seed when repeatable sampling is required.
A non-repeating iterator is given more samples than the region contains.The request is silently reduced to the number of available positions.Treat the iterator's reported sample count as the effective count and use a priority image only when its geometry matches the sampled region.
A line iterator is incremented after it reaches the line end.Traversal can move outside the valid line or produce undefined behavior.Check the line-end state before incrementing and call the line-transition operation.
A splitter requests more pieces than the region can support or uses a mismatched piece count.Work pieces can be invalid or undefined.Use the count returned by GetNumberOfSplits() when requesting each split.
An I/O region is converted without the image's largest-region index.Data is read from or written to the wrong image location when the image index does not start at zero.Convert with ImageIORegionAdaptor and pass the largest possible region index.
A neighborhood reaches an image edge without the intended boundary condition.Edge results use invalid or unintended neighbor values.Configure a boundary condition that supplies the required outside samples and input region.
A vector image has the wrong vector length for its buffer or consumers.Pixel components are misread or incomplete.Set and preserve the vector length as part of the image data contract.
An imported buffer has the wrong ownership setting.The buffer can leak or be freed while the application still uses it.Set ownership to match the lifetime managed by the application and container.
A range is used after its image buffer or buffered region changes.Iteration can use stale storage or a stale range length.Create the range after the image buffer and buffered region are ready, and do not retain it across those changes.

Key files

FileWhy to read it
Modules/…/itkImageBase.hDefines image geometry, the three image regions, coordinate conversion, and buffer offsets.
Modules/…/itkImageHelper.hDefines the shared index-to-buffer-offset and buffer-offset-to-index mapping used by image access.
Modules/…/itkImage.hDefines the typed image view and direct pixel operations.
Modules/…/itkImageRegion.hDefines rectangular image regions used by storage and pipeline work.
Modules/…/itkImageIORegion.hDefines run-time sized regions for image I/O and their conversion to typed image regions.
Modules/…/itkImportImageContainer.hDefines image buffer storage and imported-memory ownership.
Modules/…/itkVectorImage.hDefines multi-component pixels with a contiguous component buffer.
Modules/…/itkImageAdaptor.hDefines alternate pixel views over an existing image.
Modules/…/itkImageRegionSplitterBase.hDefines the contract for dividing image and image-I/O regions into work pieces.
Modules/…/itkImageIterator.hDefines the shared image iterator model, read/write access rules, region traversal state, and const conversion.
Modules/…/itkImageConstIterator.hProvides the read-only image iterator entry point.
Modules/Core/Common/include/itkImageRegionIteratorWithIndex.hxxShows the writable index-aware region traversal path.
Modules/…/itkImageLinearConstIteratorWithIndex.hDefines line traversal along a selected image direction.
Modules/…/itkImageScanlineConstIterator.hDefines fast traversal along the image's fastest axis.
Modules/…/itkImageRandomConstIteratorWithIndex.hDefines random, index-aware sampling over a selected region.
Modules/…/itkImageRandomNonRepeatingConstIteratorWithIndex.hDefines random sampling without repeated positions, optional sample limits, priorities, and seed control.
Modules/…/itkImageRegionReverseConstIterator.hDefines reverse traversal and row wrapping within a selected region.
Modules/…/itkImageBoundaryCondition.hDefines outside-neighborhood values and their effect on input regions.
Modules/…/itkImageBufferRange.hShows the standard range model for buffered image pixels and accessor-aware pixel access.
Modules/…/itkNeighborhoodIterator.hShows the local-neighborhood access model used by spatial algorithms.
Modules/…/itkImageFunction.hDefines image-derived evaluation in index and physical coordinate spaces.
Modules/…/itkInterpolateImageFunction.hDefines continuous image sampling and its bounds assumptions.
Modules/…/itkSpatialFunction.hDefines point-based functions that do not depend on image data.
Modules/…/itkRegion.hConnects structured image regions with unstructured regions used by other spatial data.