packedImage: Narrow storage types

packedImageR Documentation

Narrow storage types

Description

R has no single-precision floating-point type, so a large image held as double may cost twice the memory it needs, and potentially roughly twice the time. Raw MRI is commonly 16-bit integer.

Usage

packedImage(
  values,
  storageType,
  dims,
  slope = 1,
  intercept = 0,
  spatial = NULL,
  voxelSize = NULL,
  worldTransform = NULL,
  unit = NULL,
  geometry = NULL,
  layout = NULL
)

isPackedImage(x)

asPacked(x, type = "float32", slope = NULL, intercept = NULL, ...)

storageType(x)

Arguments

values

A raw vector holding the packed values.

dims

The full dimensions of the image.

slope, intercept

Scaling applied to stored values. Chosen automatically when not given.

spatial, voxelSize, worldTransform, unit, geometry

Image geometry, as for denseImage().

layout

How the image's axes map onto the order of values, as described for storageLayout(). The default is the identity, meaning that values are in the image's own axis order.

x

An image or array.

type, storageType

One of "int8", "uint8", "int16", "uint16", "int32" or "float32".

...

Further arguments to denseImage().

Details

Recognising this, a packed image stores its values using a narrow data type, with optional affine scaling, so that an integer type can carry a range it could not otherwise hold: value = stored * slope + intercept. When a scaling is needed it is chosen automatically to map the data across the whole of the type's range.

The values live in a raw vector, so they are garbage-collected, serialise, and survive a save and load like any other R object.

A packed image can be indexed and assigned to like an array, reading and writing only the values concerned. Assigned values are stored under the image's existing type and scaling, and so rounded to its resolution; a value the scaling cannot reach, or a missing value in an integer type, is an error, since rescaling to fit would change every other value too. Use asDense(), or repack with asPacked(), to store such values.

Value

An object of S7 class packedImage representing an image using a narrow, packed data representation, with properties corresponding to the arguments listed above.

Note

Missing values can only be carried by float32; packing data containing NA to an integer type is refused rather than silently losing it. Note that NA and NaN are not distinguished once packed, since the payload that separates them does not survive the narrowing.


imply documentation built on Nov. 20, 2026, 5:12 p.m.