a NVImage encapsulates some images data and provides methods to query and operate on images

Constructors

  • Parameters

    • dataBuffer: ArrayBufferLike | ArrayBuffer[] = null

      an array buffer of image data to load (there are also methods that abstract this more. See loadFromUrl, and loadFromFile)

    • name: string = ''

      a name for this image. Default is an empty string

    • colormap: string = 'gray'

      a color map to use. default is gray

    • opacity: number = 1.0

      the opacity for this image. default is 1

    • pairedImgData: ArrayBuffer = null

      Allows loading formats where header and image are separate files (e.g. nifti.hdr, nifti.img)

    • cal_min: number = NaN

      minimum intensity for color brightness/contrast

    • cal_max: number = NaN

      maximum intensity for color brightness/contrast

    • trustCalMinMax: boolean = true

      whether or not to trust cal_min and cal_max from the nifti header (trusting results in faster loading)

    • percentileFrac: number = 0.02

      the percentile to use for setting the robust range of the display values (smart intensity setting for images with large ranges)

    • ignoreZeroVoxels: boolean = false

      whether or not to ignore zero voxels in setting the robust range of display values

    • useQFormNotSForm: boolean = false

      give precedence to QForm (Quaternion) or SForm (Matrix)

    • colormapNegative: string = ''

      a color map to use for symmetrical negative intensities

    • frame4D: number = 0

      volume displayed, 0 indexed, must be less than nFrame4D

      FIXME the following params are documented but not included in the actual constructor

    • imageType: ImageType = NVIMAGE_TYPE.UNKNOWN

      TODO

    • cal_minNeg: number = NaN

      TODO

    • cal_maxNeg: number = NaN

      TODO

    • colorbarVisible: boolean = true

      TODO

    • colormapLabel: LUT = null

      TODO

    • colormapType: number = 0

    Returns NVImage

Methods

  • Update options for image

    Parameters

    • options: ImageFromUrlOptions

    Returns void

  • set contrast/brightness to robust range (2%..98%)

    Parameters

    • vol: number = Number.POSITIVE_INFINITY

      volume for estimate (use -1 to use estimate on all loaded volumes; use INFINITY for current volume)

    • isBorder: boolean = true

      if true (default) only center of volume used for estimate

    Returns number[]

    volume brightness and returns array [pct2, pct98, mnScale, mxScale]

  • make a clone of a NVImage instance and return a new NVImage

    Returns NVImage

    NVImage instance

    myImage = NVImage.loadFromFile(SomeFileObject) // files can be from dialogs or drag and drop
    clonedImage = myImage.clone()
  • get nifti specific metadata about the image

    Returns ImageMetadata

  • Returns voxel intensity at specific native coordinates. Delegates to VolumeUtils.getValue.

    Parameters

    • x: number

      Native X coordinate (0-indexed)

    • y: number

      Native Y coordinate (0-indexed)

    • z: number

      Native Z coordinate (0-indexed)

    • frame4D: number = 0

      4D frame index (0-indexed)

    • isReadImaginary: boolean = false

      Flag to read from imaginary data array

    Returns number

    Scaled voxel intensity

  • read a 3D slab of voxels from a volume, specified in RAS coordinates. Delegates to VolumeUtils.getVolumeData.

    Parameters

    • voxStart: number[] = ...

      first row, column and slice (RAS order) for selection

    • voxEnd: number[] = ...

      final row, column and slice (RAS order) for selection

    • dataType: string = 'same'

      array data type. Options: 'same' (default), 'uint8', 'float32', 'scaled', 'normalized', 'windowed'

    Returns [TypedVoxelArray, number[]]

    the an array where ret[0] is the voxel values and ret[1] is dimension of selection

  • save image as NIfTI volume and trigger download. Delegates to ImageWriter.saveToDisk.

    Parameters

    • fnm: string = ''

      Filename for download. If empty, returns data without download.

    • drawing8: Uint8Array = null

      Optional Uint8Array drawing overlay

    Returns Promise<Uint8Array>

    Promise

  • Converts NVImage to NIfTI compliant byte array, potentially compressed. Delegates to ImageWriter.saveToUint8Array.

    Parameters

    • fnm: string

      Filename (determines if compression is needed via .gz suffix)

    • drawing8: Uint8Array = null

      Optional Uint8Array drawing overlay

    Returns Promise<Uint8Array>

    Promise

  • write a 3D slab of voxels from a volume, specified in RAS coordinates. Delegates to VolumeUtils.setVolumeData. Input slabData is assumed to be in the correct raw data type for the target image.

    Parameters

    • voxStart: number[] = ...

      first row, column and slice (RAS order) for selection

    • voxEnd: number[] = ...

      final row, column and slice (RAS order) for selection

    • img: TypedVoxelArray = ...

      array of voxel values to insert (RAS order, raw data type)

    Returns void

  • Converts NVImage to NIfTI compliant byte array. Handles potential re-orientation of drawing data. Delegates to ImageWriter.toUint8Array.

    Parameters

    • drawingBytes: Uint8Array = null

      Optional Uint8Array drawing overlay

    Returns Uint8Array

    Uint8Array

  • fill a NVImage instance with zeros for the image data

    Returns void

    myImage = NVImage.loadFromFile(SomeFileObject) // files can be from dialogs or drag and drop
    clonedImageWithZeros = myImage.clone().zeroImage()
  • Creates a Uint8Array representing a NIFTI file (header + optional image data). Delegates to ImageWriter.createNiftiArray.

    Parameters

    • dims: number[] = ...
    • pixDims: number[] = ...
    • affine: number[] = ...
    • datatypeCode: NiiDataType = NiiDataType.DT_UINT8
    • img: TypedVoxelArray = ...

    Returns Uint8Array

  • Creates a NIFTI1 header object with basic properties. Delegates to ImageWriter.createNiftiHeader.

    Parameters

    • dims: number[] = ...
    • pixDims: number[] = ...
    • affine: number[] = ...
    • datatypeCode: NiiDataType = NiiDataType.DT_UINT8

    Returns NIFTI1

  • factory function to load and return a new NVImage instance from a base64 encoded string

    Parameters

    • __namedParameters: ImageFromBase64

    Returns Promise<NVImage>

    NVImage instance

    myImage = NVImage.loadFromBase64('SomeBase64String')
    
  • factory function to load and return a new NVImage instance from a file in the browser

    Parameters

    • __namedParameters: ImageFromFileOptions

    Returns Promise<NVImage>

  • factory function to load and return a new NVImage instance from a given URL

    Parameters

    • __namedParameters: Partial<Omit<ImageFromUrlOptions, "url">> & {
          url?: string | ArrayBuffer | Uint8Array;
      } = {}

    Returns Promise<NVImage>

    NVImage instance

  • a factory function to make a zero filled image given a NVImage as a reference

    Parameters

    • nvImage: NVImage

      an existing NVImage as a reference

    • dataType: string = 'same'

      the output data type. Options: 'same', 'uint8'

    Returns NVImage

    new NVImage filled with zeros for the image data

    myImage = NVImage.loadFromFile(SomeFileObject) // files can be from dialogs or drag and drop
    newZeroImage = NVImage.zerosLike(myImage)