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,
  spaceUnit = NULL,
  timeUnit = NULL,
  template = NULL
)

isPackedImage(x)

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

storageType(x)

Arguments

values

A raw vector holding the packed values.

dims, spatial, voxelSize, worldTransform, spaceUnit, timeUnit

Image geometry, as for denseImage().

slope, intercept

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

template

An image to take unspecified geometry from.

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.

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 Sept. 15, 2026, 5:09 p.m.