Computational Medical File (CMF)

Image format handling in COMEDI

COMEDI provides a flexible data input/output back-end in the shared library, which is used across all applications. This means that all applications in COMEDI can read or write images in all the supported formats - there is no need to explicitly convert the data to a given format prior to processing. Importantly, COMEDI uniquely uses an in-house designed Computational Medical File (CMF) Format for all the supportable data formats.

However, some specialized applications may expect additional information to be present in the input image. The COMEDI .cmf formats with class {cmdata} are both capable of storing such additional information data in their header, and will hence always be supported for such applications. Most image formats however cannot carry additional information in their header (or at least, not easily) - this is in fact one of the main motivations for the development of the COMEDI image formats. In such cases, it would be necessary to use COMEDI format images. Alternatively, it may be necessary to provide the additional information using command-line arguments.

Coordinate system

All COMEDI applications will consistently use the same coordinate system, which is identical to the NIfTI standard.

Multi-file numbered image support

It is possible to access a numbered series of images as a single multi-dimensional dataset, using a syntax specific to COMEDI. For example:

>> cminfo('MRI-volume-*.nii.gz')

will collate all images that match the pattern MRI-volume-<number>.nii.gz, sort them in ascending numerical order, and access them as a single dataset with dimensionality one larger than that contained in the images. In other words, assuming there are 10 MRI-volume-0.nii.gz to MRI-volume-9.nii.gz, and each volume is a 3D image, the result will be a 4D dataset with 10 volumes.

Note that this isn’t limited to one level of numbering:

>> cmconvert('MRI-volume-*-*.nii.gz','MRI-volume.cmf')

will collate all images that match the MRI-volume-*-*.nii.gz pattern and generate a single dataset with dimensionality two larger than its constituents.

Data types

COMEDI applications can read and write data in any of the common data types. Many COMEDI commands also support the datatype option to specify the data type for the output image. For example:

>> cmconvert('MRI-volume-*-*.nii.gz','MRI-volume.cmf',datatype='uint16') ;

Note

Not all image formats support all possible datatypes. The COMEDI image file formats are designed to handle all of the possibilities listed below, while other image formats may only support a subset. When a data type is requested that isn’t supported by the image format, a hopefully suitable alternative data type will be used instead.

Below is a list of the supported data types and their specifiers for use on the command-line. Note that COMEDI is not sensitive to the case of the specifier: uint16le will work just as well as UInt16LE.

Specifier

Description

double

Double-precision arrays

single

Single-precision arrays

int8

8-bit signed integer arrays

int16

16-bit signed integer arrays

int32

32-bit signed integer arrays

int64

64-bit signed integer arrays

uint8

8-bit unsigned integer arrays

uint16

16-bit unsigned integer arrays

uint32

32-bit unsigned integer arrays

uint64

64-bit unsigned integer arrays

The image transfom

The orientation of the image with respect to the scanner axes is determined by the combination of the image axes and the location of the corner voxel. This information is encapsulated in the transformation matrix, commonly referred to simply as the transform. You can view the transform for any image using cminfo, for example:

>> cminfo('dwi.cmf')
************************************************
  Locations:         /User/wuye/Testing/dwi.cmf
  Dimensions:        104 x 104 x 54 x 167
  Voxel size:        2.30769 x 2.30769 x 2.3 x 1
  Data strides:      [ -1 -2 3 4 ]
  Type:              Image
  Data type:         Single
  Intensity scaling: offset = 0, multiplier = 1
  Transform:         0.9999     6.887e-09    -0.01564      -116.1
                     -0.001242  0.9968       -0.07943      -89.44
                     0.01559    0.07944      0.9967        -64.27
  ************************************************

The ‘Transform’ field above shows the first 3 rows of the transformation matrix (technically, this is a 4×4 matrix, but the last row is always set to [ 0 0 0 1 ]). The first 3 columns correspond to the x, y & z image axes respectively, while the last column corresponds to the location in real (scanner/world) space of the corner voxel (i.e. the voxel at index [ 0 0 0 ]).

In COMEDI, the transform shown always corresponds to the transformation from image coordinates in millimeters to scanner coordinates in millimeters - the voxel size is not taken into account, and the image axes are always normalised to unit amplitude. This may differ from other packages.

Furthermore, COMEDI will always present the transform that best matches the real space. If the transform of the image on file represents a large rotation, such that for example the first image axis is closer to the scanner’s z axis, this transform will be modified by permutation or inversion of the axes to bring it in alignment with the expected coordinate system, so that the first axis genuinely can be interpreted as approximately left-right, etc. To achieve this, COMEDI will also modify the image strides to match.

Supported image formats

This lists the various image formats currently supported by COMEDI.

MRtrix image formats (.mih / .mif)

Compressed COMEDI image format (.cmf.gz)

DICOM (folder or .dcm)

NIfTI & NIfTI-2 (.nii)

Compressed NIfTI (.nii.gz)

FreeSurfer formats (.mgh / .mgz)

Analyse format (.img / .hdr)

MRtrix Tracks file format (.tck)

MRtrix Track Scalar File format (.tsf)

Nearly Raw Raster Data (.nrrd/.nhdr)