Larvitar Documentation
Home
Guide
API
GitHub
Home
Guide
API
GitHub
  • API

    • Initializing
    • Parsing
    • Loading
    • Rendering
    • Interacting
    • Testing
    • Modules

      • Logger
      • Store
      • Managers

        • Image Manager
        • GSPS Manager
        • File Manager
      • Parsers

        • PDF Parser
        • NRRD Parser
        • ECG Parser
      • Loaders
        • DICOM Loader
        • MultiFrame Loader
        • SingleFrame Loader
        • DSA Image Loader
        • File Loader
        • Nrrd Loader
      • Interaction Tools

        • Initialize and manage Tools
        • Default and Custom Tools
        • Segmentation Tools
        • DvTools
      • Utilities

        • DICOM Anonymization
        • DICOM Customization
        • Tags
        • Utils
        • Memory
      • Post Processing

        • DSA
      • Visualizations

        • Layers
        • ECG
        • Color Maps
        • Greyscale Presentation States
      • Testing
Larvitar

NRRD Parser Module

The NRRD Parser Module provides functionality to parse and decode NRRD (Nearly Raw Raster Data) files. NRRD is a file format commonly used to store volumetric data, particularly in medical imaging applications. This module extracts metadata and image data from NRRD files, enabling seamless integration into visualization and analysis workflows.

Features

  • File Format Validation: Ensures that the input file is a valid NRRD file.
  • Header Parsing: Extracts and processes metadata such as dimensions, spacings, and origins.
  • Data Decoding: Supports various encoding formats (raw, ascii, and gzip) for decoding image data.
  • Error Handling: Detects inconsistencies in the file format and provides meaningful error messages.
  • Integration-Ready: Easily integrates into frameworks like Larvitar as a custom image loader.

API Reference

parse Parses a NRRD file buffer and returns its metadata and image data.

Syntax

parse(nrrdBuffer: ArrayBuffer, options: { headerOnly?: boolean }): { header: object, data: TypedArray | null }

Parameters

ParameterTypeDescription
nrrdBufferArrayBufferThe buffer containing the NRRD file data.
optionsobjectOptional settings. Set headerOnly: true to return only metadata.

Returns

An object containing the NRRD file’s metadata (header) and image data (data).

Example

import { parse } from './parsers/nrrd';

const volume = parse(bufferArray, { headerOnly: false });

How It Works

Supported Encoding Formats

The parser supports the following NRRD encoding formats:

  • raw: Uncompressed binary data.
  • ascii: Text-encoded data.
  • gzip: Compressed binary data.

Unsupported encodings, such as bzip2, will throw an error.

Error Handling

The parser includes robust error detection and messages for:

  • Invalid file formats (e.g., missing magic number).
  • Corrupted or inconsistent headers.
  • Unsupported encoding formats.
  • Mismatched data lengths between header and buffer.

Limitations

  • Only supports raw, ascii, and gzip encodings.
  • Requires strict adherence to the NRRD specification for fields like space directions and kinds.
  • Text-based encoding (ascii) can be slower for large datasets.


D/Vision Lab
Last Updated:
Contributors: Laura Borghesi, Simone "Lateralus" Manini
Prev
PDF Parser
Next
ECG Parser