DWVv0.37.0

MaskImage

Source: maskImage.js:30

Mask (segmentation) image class. Extends Image with a SegmentCollection and the segment-aware behavior built on top of it: per-segment/per-slice bookkeeping, the brush tool's offset-editing methods, and per-segment labeling statistics (volume/centroid/diameter).


Constructor

new MaskImage( geometry: Geometry, buffer: Uint8Array, imageUids?: Array.<string>, segmentCollection?: SegmentCollection, ): MaskImage

Parameters

  • geometry (Geometry) — The geometry of the image.
  • buffer (Uint8Array) — The mask data as a one dimensional buffer: one byte per voxel, 0 for background, the segment number otherwise.
  • imageUids (Array.<string>, optional) — An array of Uids indexed to slice number.
  • segmentCollection (SegmentCollection, optional) — The segment collection, for a mask already parsed from DICOM (its own label map already aliases buffer). When omitted (brush-created masks), a fresh collection is created and its label map is aliased to buffer.

Instance Methods

initializeContour()

Initialize the contour buffer. Should be called on every segmentation image, or any image where contour rendering needs to be supported.

getContour(): ImageContour

Get the image contour. Should only be available for segmentation images, but can be initialized for any Uint8Array image.

Returns

getSegmentCollection(): SegmentCollection

Get the segment collection.

Returns

getHasOverlap(): boolean

Check whether the mask has overlapping segments.

Returns

  • boolean — True if any two segments share at least one voxel.

getMaskReferencedSeriesUID(): string | undefined

Get the UID of the series referenced by the mask, if any.

Returns

  • string | undefined — The UID.

isMask(): boolean

Check is the image is a mask.

Since v0.37, please use `instanceof MaskImage` instead.

Returns

  • boolean — True.

getSegmentNumbersAtIndex(index: Index): Array.<number>

Get the numbers of the segments present at an index. When segments overlap, all the segments at the index are returned, not only the one stored in the buffer (first wins).

Parameters

  • index (Index) — The index, no bounds check.

Returns

  • Array.<number> — The sorted list of segment numbers, empty for background.

getOffsets(value: number | RGB): Array.<number>

Get the offsets where the buffer equals the input value. Loops through the whole volume, can get long for big data...

Parameters

  • value (number | RGB) — The value to check.

Returns

  • Array.<number> — The list of offsets.

setAtOffsets(offsets: Array.<number>, value: number | RGB)

Set the inner buffer values at given offsets.

Parameters

  • offsets (Array.<number>) — List of offsets where to set the data.
  • value (number | RGB) — The value to set at the given offsets.

Fires

  • Image#event:imagecontentchange

setAtOffsetsWithValues( offsets: Array.<number>, values: Array.<number>, )

Set the inner buffer values at given offsets, each to its own value. Used when a single uniform value cannot be used across all offsets, for example restoring the segment still present at a voxel that used to be hidden by an overlapping, now deleted, segment.

Parameters

  • offsets (Array.<number>) — List of offsets where to set the data.
  • values (Array.<number>) — Per-offset values, same length as offsets.

Fires

  • Image#event:imagecontentchange

setAtOffsetsAndGetOriginals( offsetsLists: Array.<Array.<number>>, value: number, ): Array

Set the inner buffer values at given offsets.

Parameters

  • offsetsLists (Array.<Array.<number>>) — List of offset lists where to set the data.
  • value (number) — The value to set at the given offsets.

Returns

  • Array — A list of objects representing the original values before replacing them.

Fires

  • Image#event:imagecontentchange

setAtOffsetsWithIterator( offsetsLists: Array.<Array.<number>>, value: number | Array, )

Set the inner buffer values at given offsets.

Parameters

  • offsetsLists (Array.<Array.<number>>) — List of offset lists where to set the data.
  • value (number | Array) — The value to set at the given offsets.

Fires

  • Image#event:imagecontentchange

getLabels(): Array.<Label> | undefined

Get the labels from the last labeling (see MaskImage#recalculateLabels).

Returns

  • Array.<Label> | undefined — The labels, undefined if not calculated.

recalculateLabels()

Recalculate labels.

Fires

  • Image#event:labelingstart
  • Image#event:labelschanged

clone(): MaskImage

Clone the mask image.

Returns

getHistogramBySegment( image: Image, segmentId: string, ): Array.<SegmentHistogram>

Get per-volume histograms of reference-image intensities for one segment.

For each volume of image, counts how often each intensity appears in voxels belonging to the given segment of this mask. Segmentations are 3D: the same mask is applied to every volume. Raw values are counted per rescale slope and intercept and rescaled when read from the ImageHistogram.

If labels are available (see MaskImage#getLabels), each entry also has labelHistograms: one histogram per label of the segment, made of the segment voxels between the label min and max Z. Since labels of the same segment that share slices cannot be separated this way, labelHistograms is not provided in that case.

Parameters

  • image (Image) — The reference image (intensities).
  • segmentId (string) — Segment tracking UID, or segment number as string.

Returns