Image

Image class. Usable once created, optional are:

  • rescale slope and intercept (default 1:0),
  • photometric interpretation (default MONOCHROME2),
  • planar configuration (default RGBRGB...).

Constructor

new Image(geometry, buffer, imageUidsopt)

Parameters:
NameTypeAttributesDescription
geometryGeometry

The geometry of the image.

bufferTypedArray

The image data as a one dimensional buffer.

imageUidsArray<optional>

An array of Uids indexed to slice number.

Example
// XMLHttpRequest onload callback
const onload = function (event) {
  // parse the dicom buffer
  const dicomParser = new dwv.DicomParser();
  dicomParser.parse(event.target.response);
  // create the image object
  const image = dwv.createImage(dicomParser.getDicomElements());
  // result div
  const div = document.getElementById('dwv');
  // display the image size
  const size = image.getGeometry().getSize();
  div.appendChild(document.createTextNode(
    'Size: ' + size.toString() +
    ' (should be 256,256,1)'));
  // break line
  div.appendChild(document.createElement('br'));
  // display a pixel value
  div.appendChild(document.createTextNode(
    'Pixel @ [128,40,0]: ' +
    image.getRescaledValue(128,40,0) +
    ' (should be 101)'));
};
// DICOM file request
const request = new XMLHttpRequest();
const url = 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm';
request.open('GET', url);
request.responseType = 'arraybuffer';
request.onload = onload;
request.send();

Classes

Image

Methods

addEventListener(type, callback)

Add an event listener to this class.

Parameters:
NameTypeDescription
typestring

The event type.

callbackfunction

The function associated with the provided event type, will be called with the fired event.

appendFrame(time, origin)

Append a frame to the image.

Parameters:
NameTypeDescription
timenumber

The frame time value.

originPoint3D

The origin of the frame.

appendFrameBuffer(frameBuffer, frameIndex)

Append a frame buffer to the image.

Parameters:
NameTypeDescription
frameBufferobject

The frame buffer to append.

frameIndexnumber

The frame index.

appendSlice(rhs)

Append a slice to the image.

Parameters:
NameTypeDescription
rhsImage

The slice to append.

calculateDataRange() → {object}

Calculate the data range of the image. WARNING: for speed reasons, only calculated on the first frame...

Returns:

The range {min, max}.

Type: 
object

calculateHistogram() → {object}

Calculate the histogram of the image.

Returns:

The histogram, data range and rescaled data range.

Type: 
object

calculateRescaledDataRange() → {object}

Calculate the rescaled data range of the image. WARNING: for speed reasons, only calculated on the first frame...

Returns:

The range {min, max}.

Type: 
object

canQuantify() → {boolean}

Can the image values be quantified?

Returns:

True if only one component.

Type: 
boolean

canScroll(viewOrientation) → {boolean}

Can the data be scrolled?

Parameters:
NameTypeDescription
viewOrientationMatrix33

The view orientation.

Returns:

True if the data has a third dimension greater than one after applying the view orientation.

Type: 
boolean

canWindowLevel() → {boolean}

Can window and level be applied to the data?

Returns:

True if the data is monochrome.

Type: 
boolean

clone() → {Image}

Clone the image.

Returns:

A clone of this image.

Type: 
Image

compose(rhs, operator) → {Image}

Compose this image with another one and using a specific operator. WARNING: no size check!

Parameters:
NameTypeDescription
rhsImage

The image to compose with.

operatorfunction

The operator to use when composing.

Returns:

The composed image. Note: Uses the raw buffer values.

Type: 
Image

convolute2D(weights) → {Image}

Convolute the image with a given 2D kernel.

Note: Uses raw buffer values.

Parameters:
NameTypeDescription
weightsArray

The weights of the 2D kernel as a 3x3 matrix.

Returns:

The convoluted image.

Type: 
Image

convoluteBuffer(weights, buffer, startOffset)

Convolute an image buffer with a given 2D kernel.

Note: Uses raw buffer values.

Parameters:
NameTypeDescription
weightsArray

The weights of the 2D kernel as a 3x3 matrix.

bufferTypedArray

The buffer to convolute.

startOffsetnumber

The index to start at.

getBuffer() → {TypedArray}

Get the data buffer of the image.

To Do
  • dangerous...
Returns:

The data buffer of the image.

Type: 
TypedArray

getDataRange() → {object}

Get the data range.

Returns:

The data range.

Type: 
object

getGeometry() → {Geometry}

Get the geometry of the image.

Returns:

The geometry.

Type: 
Geometry

getHistogram() → {Array}

Get the histogram.

Returns:

The histogram.

Type: 
Array

getImageUid(indexopt) → {string}

Get the image UID at a given index.

Parameters:
NameTypeAttributesDescription
indexIndex<optional>

The index at which to get the id.

Returns:

The UID.

Type: 
string

getMeta() → {object}

Get the meta information of the image.

Returns:

The meta information of the image.

Type: 
object

getNumberOfComponents() → {number}

Get the numberOfComponents of the image.

Returns:

The numberOfComponents of the image.

Type: 
number

getOffsets(value) → {Array}

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

Parameters:
NameTypeDescription
valuenumber | object

The value to check.

Returns:

The list of offsets.

Type: 
Array

getPhotometricInterpretation() → {string}

Get the photometricInterpretation of the image.

Returns:

The photometricInterpretation of the image.

Type: 
string

getPlanarConfiguration() → {number}

Get the planarConfiguration of the image.

Returns:

The planarConfiguration of the image.

Type: 
number

getRescaleSlopeAndIntercept(indexopt) → {object}

Get the rescale slope and intercept.

Parameters:
NameTypeAttributesDescription
indexIndex<optional>

The index (only needed for non constant rsi).

Returns:

The rescale slope and intercept.

Type: 
object

getRescaledDataRange() → {object}

Get the rescaled data range.

Returns:

The rescaled data range.

Type: 
object

getRescaledValue(i, j, k, f) → {number}

Get the rescaled value of the image at a specific position.

Parameters:
NameTypeDescription
inumber

The X index.

jnumber

The Y index.

knumber

The Z index.

fnumber

The frame number.

Returns:

The rescaled value at the desired position. Warning: No size check...

Type: 
number

getRescaledValueAtIndex(index) → {number}

Get the rescaled value of the image at a specific index.

Parameters:
NameTypeDescription
indexIndex

The index.

Returns:

The rescaled value at the desired position. Warning: No size check...

Type: 
number

getRescaledValueAtOffset(offset) → {number}

Get the rescaled value of the image at a specific offset.

Parameters:
NameTypeDescription
offsetnumber

The desired offset.

Returns:

The rescaled value at the desired offset. Warning: No size check...

Type: 
number

getSecondaryOffset(index) → {number}

Get the secondary offset: an offset that takes into account the slice and above dimension numbers.

Parameters:
NameTypeDescription
indexIndex

The index.

Returns:

The offset.

Type: 
number

getValue(i, j, k, f) → {number}

Get the value of the image at a specific coordinate.

Parameters:
NameTypeDescription
inumber

The X index.

jnumber

The Y index.

knumber

The Z index.

fnumber

The frame number.

Returns:

The value at the desired position. Warning: No size check...

Type: 
number

getValueAtIndex(index) → {number}

Get the value of the image at a specific index.

Parameters:
NameTypeDescription
indexIndex

The index.

Returns:

The value at the desired position. Warning: No size check...

Type: 
number

getValueAtOffset(offset) → {number}

Get value at offset. Warning: No size check...

Parameters:
NameTypeDescription
offsetnumber

The desired offset.

Returns:

The value at offset.

Type: 
number

hasValues(values) → {Array}

Check if the input values are in the buffer. Could loop through the whole volume, can get long for big data...

Parameters:
NameTypeDescription
valuesArray

The values to check.

Returns:

A list of booleans for each input value, set to true if the value is present in the buffer.

Type: 
Array

isConstantRSI() → {boolean}

Are all the RSIs equal.

Returns:

True if they are.

Type: 
boolean

isIdentityRSI() → {boolean}

Are all the RSIs identity (1,0).

Returns:

True if they are.

Type: 
boolean

removeEventListener(type, callback)

Remove an event listener from this class.

Parameters:
NameTypeDescription
typestring

The event type.

callbackfunction

The function associated with the provided event type.

setAtOffsets(offsets, value)

Set the inner buffer values at given offsets.

Parameters:
NameTypeDescription
offsetsArray

List of offsets where to set the data.

valueobject

The value to set at the given offsets.

setAtOffsetsAndGetOriginals(offsetsLists, value) → {Array}

Set the inner buffer values at given offsets.

Parameters:
NameTypeDescription
offsetsListsArray

List of offset lists where to set the data.

valueobject

The value to set at the given offsets.

Returns:

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

Type: 
Array

setAtOffsetsWithIterator(offsetsLists, value)

Set the inner buffer values at given offsets.

Parameters:
NameTypeDescription
offsetsListsArray

List of offset lists where to set the data.

valueobject | Array

The value to set at the given offsets.

setMeta(rhs)

Set the meta information of the image.

Parameters:
NameTypeDescription
rhsobject

The meta information of the image.

setPhotometricInterpretation(interp)

Set the photometricInterpretation of the image.

Parameters:
NameTypeDescription
interpstring

The photometricInterpretation of the image.

setPlanarConfiguration(config)

Set the planarConfiguration of the image.

Parameters:
NameTypeDescription
confignumber

The planarConfiguration of the image.

setRescaleSlopeAndIntercept(inRsi, offsetopt)

Set the rescale slope and intercept.

Parameters:
NameTypeAttributesDescription
inRsiobject

The input rescale slope and intercept.

offsetnumber<optional>

The rsi offset (only needed for non constant rsi).

transform(operator) → {Image}

Transform an image using a specific operator. WARNING: no size check!

Parameters:
NameTypeDescription
operatorfunction

The operator to use when transforming.

Returns:

The transformed image. Note: Uses the raw buffer values.

Type: 
Image

Events

imagechange

Image change event.

Type:
  • object