Image
Source: image.js:107
Image class. Usable once created, optional are:
- rescale slope and intercept (default 1:0),
- photometric interpretation (default MONOCHROME2),
- planar configuration (default RGBRGB...).
Example
import {DicomParser, demoCreateImage} from '//esm.sh/dwv';
// XMLHttpRequest onload callback
const onload = function (event) {
// parse the dicom buffer
const dicomParser = new DicomParser();
dicomParser.parse(event.target.response);
// create the image object
const image = demoCreateImage(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();Constructor
new Image(
geometry: Geometry,
buffer: TypedArray,
imageUids?: Array.<string>,
): ImageParameters
geometry(Geometry) — The geometry of the image.buffer(TypedArray) — The image data as a one dimensional buffer.imageUids(Array.<string>, optional) — An array of Uids indexed to slice number.
Instance Methods
setComplete(flag: boolean)
Set the image complete flag.
Parameters
flag(boolean) — True if the data is complete.
getComplete(): boolean
Get the image complete flag.
Returns
boolean— True if the data is complete.
getInitialIndex(): Index
Get the initial index, used as default position by views: the middle of the image (first frame for 4D).
Returns
Index— The index.
getHasOverlap(): boolean
Check whether the image has overlapping segments. Always false for a plain image; MaskImage overrides this with a real check.
Since v0.37, please use `instanceof MaskImage` and `MaskImage#getHasOverlap` instead.
Returns
boolean— False.
getImageUid(index?: Index): string
Get the image UID at a given index.
Parameters
index(Index, optional) — The index at which to get the id.
Returns
string— The UID.
getOriginForImageUid(uid: string): Point3D | undefined
Get the image origin for a image UID.
Parameters
uid(string) — The UID.
Returns
Point3D| undefined— The origin.
includesImageUid(uid: string): boolean
Check if the image includes an UID.
Parameters
uid(string) — The UID.
Returns
boolean— True if present.
containsImageUids(uids: Array.<string>): boolean
Check if this image includes the input uids.
Parameters
uids(Array.<string>) — UIDs to test for presence.
Returns
boolean— True if all uids are in this image uids.
getGeometry(): Geometry
Get the geometry of the image.
Returns
Geometry— The geometry.
getBuffer(): TypedArray
Get the data buffer of the image.
Returns
TypedArray— The data buffer of the image.
- TODO:
- Dangerous...
canQuantify(): boolean
Can the image values be quantified?
Returns
boolean— True if only one component.
canWindowLevel(): boolean
Can window and level be applied to the data?
Since v0.33, please use isMonochrome instead.
Returns
boolean— True if the data is monochrome.
isMonochrome(): boolean
Is the data monochrome.
Returns
boolean— True if the data is monochrome.
isMask(): boolean
Check is the image is a mask.
Since v0.37, please use `instanceof MaskImage` instead.
Returns
boolean— True if mask.
canScroll(viewOrientation: Matrix33): boolean
Can the data be scrolled?
Parameters
viewOrientation(Matrix33) — The view orientation.
Returns
boolean— True if the data has a third dimension greater than one after applying the view orientation.
getSecondaryOffset(index: Index): number
Get the secondary offset: an offset that takes into account the slice and above dimension numbers.
Parameters
index(Index) — The index.
Returns
number— The offset.
getRescaleSlopeAndIntercept(
index?: Index,
): RescaleSlopeAndIntercept
Get the rescale slope and intercept.
Parameters
index(Index, optional) — The index (only needed for non constant rsi).
Returns
RescaleSlopeAndIntercept— The rescale slope and intercept.
setRescaleSlopeAndIntercept(
inRsi: RescaleSlopeAndIntercept,
offset?: number,
)
Set the rescale slope and intercept.
Parameters
inRsi(RescaleSlopeAndIntercept) — The input rescale slope and intercept.offset(number, optional) — The rsi offset (only needed for non constant rsi).
isIdentityRSI(): boolean
Are all the RSIs identity (1,0).
Returns
boolean— True if they are.
isConstantRSI(): boolean
Are all the RSIs equal.
Returns
boolean— True if they are.
getPhotometricInterpretation(): string
Get the photometricInterpretation of the image.
Returns
string— The photometricInterpretation of the image.
setPhotometricInterpretation(interp: string)
Set the photometricInterpretation of the image.
Parameters
interp(string) — The photometricInterpretation of the image.
setPaletteColourMap(map: ColourMap)
Set the palette colour map.
Parameters
map(ColourMap) — The colour map.
getPaletteColourMap(): ColourMap
Get the palette colour map.
Returns
ColourMap— The colour map.
updatePaletteColourMap(index: number, colour: RGB)
Update the palette colour map.
Parameters
index(number) — The index to change the colour of.colour(RGB) — The colour to use at index.
getPlanarConfiguration(): number
Get the planarConfiguration of the image.
Returns
number— The planarConfiguration of the image.
setPlanarConfiguration(config: number)
Set the planarConfiguration of the image.
Parameters
config(number) — The planarConfiguration of the image.
getNumberOfComponents(): number
Get the numberOfComponents of the image.
Returns
number— The numberOfComponents of the image.
getMeta(): Record.<string, any>
Get the meta information of the image.
Returns
Record.<string, any>— The meta information of the image.
setMeta(rhs: Record.<string, any>)
Set the meta information of the image.
Parameters
rhs(Record.<string, any>) — The meta information of the image.
getValueAtOffset(offset: number): number
Get value at offset. Warning: No size check...
Parameters
offset(number) — The desired offset.
Returns
number— The value at offset.
hasValues(values: Array): Array.<boolean>
Check if the input values are in the buffer. Could loop through the whole volume, can get long for big data...
Parameters
values(Array) — The values to check.
Returns
Array.<boolean>— A list of booleans for each input value, set to true if the value is present in the buffer.
clone(): Image
Clone the image.
Returns
Image— A clone of this image.
replaceBuffer(newBuffer: TypedArray)
Replace the inner buffer wholesale (as opposed to editing its content in place). Primarily intended for subclass use, where a private (#) field on this class isn't reachable directly.
Parameters
newBuffer(TypedArray) — The new buffer.
Fires
Image#event:imagecontentchange
canAppendSlice(rhs: Image): BooleanResult
Check if another image can be appended to this one.
Parameters
rhs(Image) — The image to check.
Returns
BooleanResult— Result with success set to true if the image can be appended.
appendSlice(rhs: Image)
Append a slice to the image.
Parameters
rhs(Image) — The slice to append.
Fires
Image#event:imagegeometrychange
appendFrameBuffer(frameBuffer: object, frameIndex: number)
Append a frame buffer to the image.
Parameters
frameBuffer(object) — The frame buffer to append.frameIndex(number) — The frame index.
appendFrame(time: VolumeId, origin: Point3D)
Append a frame to the image.
Parameters
time(VolumeId) — The frame time: a volume id or, without source, a frame index.origin(Point3D) — The origin of the frame.
getDataRange(): NumberRange
Get the data range.
Returns
NumberRange— The data range.
getRescaledDataRange(): NumberRange
Get the rescaled data range.
Returns
NumberRange— The rescaled data range.
getHistogram(): ImageHistogram
Get the histogram.
Returns
ImageHistogram— The histogram.
getValue(i: number, j: number, k: number, f?: number): number
Get the value of the image at a specific coordinate.
Parameters
i(number) — The X index.j(number) — The Y index.k(number) — The Z index.f(number, optional) — Optional frame number.
Returns
number— The value at the desired position. Warning: No size check...
getValueAtIndex(index: Index): number
Get the value of the image at a specific index.
Parameters
index(Index) — The index.
Returns
number— The value at the desired position. Warning: No size check...
getRescaledValue(
i: number,
j: number,
k: number,
f?: number,
): number
Get the rescaled value of the image at a specific position.
Parameters
i(number) — The X index.j(number) — The Y index.k(number) — The Z index.f(number, optional) — Optional frame number.
Returns
number— The rescaled value at the desired position. Warning: No size check...
getRescaledValueAtIndex(index: Index): number
Get the rescaled value of the image at a specific index.
Parameters
index(Index) — The index.
Returns
number— The rescaled value at the desired position. Warning: No size check...
getRescaledValueAtOffset(offset: number): number
Get the rescaled value of the image at a specific offset.
Parameters
offset(number) — The desired offset.
Returns
number— The rescaled value at the desired offset. Warning: No size check...
getRescaledValuesAtPosition(
position: Point,
): Array.<VolumeValue>
Get the rescaled values of all volumes (fourth dimension) at a position.
Parameters
position(Point) — The world position, only its first three dimensions are used.
Returns
Array.<VolumeValue>— The values with their unit and volume id, ordered by volume index, empty if the position is out of bounds or if the image cannot be quantified (more than one component).
calculateDataRange(): object
Calculate the data range of the image. WARNING: for speed reasons, only calculated on the first frame...
Returns
object— The range {min, max}.
calculateRescaledDataRange(): object
Calculate the rescaled data range of the image. WARNING: for speed reasons, only calculated on the first frame...
Returns
object— The range {min, max}.
convolute2D(weights: Array.<number>): Image
Convolute the image with a given 2D kernel.
Note: Uses raw buffer values.
Parameters
weights(Array.<number>) — The weights of the 2D kernel as a 3x3 matrix.
Returns
Image— The convoluted image.
convoluteBuffer(
weights: Array.<number>,
buffer: TypedArray,
startOffset: number,
)
Convolute an image buffer with a given 2D kernel.
Note: Uses raw buffer values.
Parameters
weights(Array.<number>) — The weights of the 2D kernel as a 3x3 matrix.buffer(TypedArray) — The buffer to convolute.startOffset(number) — The index to start at.
transform(operator: function): Image
Transform an image using a specific operator. WARNING: no size check!
Parameters
operator(function) — The operator to use when transforming.
Returns
Image— The transformed image. Note: Uses the raw buffer values.
compose(rhs: Image, operator: function): Image
Compose this image with another one and using a specific operator. WARNING: no size check!
Parameters
rhs(Image) — The image to compose with.operator(function) — The operator to use when composing.
Returns
Image— The composed image. Note: Uses the raw buffer values.
isResampled(): boolean
Return if this image has been resampled.
Returns
boolean— If the image has been resampled.
resample(
orientation: Matrix33,
interpolated: boolean | undefined,
centerOfRotation: Point | undefined,
)
Resample this image to a new orientation.
Parameters
orientation(Matrix33) — The orientation to resample to.interpolated(boolean | undefined) — Default true, if true use bilinear sampling, otherwise use nearest neighbor.centerOfRotation(Point | undefined) — World space center of rotation.
revert()
Revert a resampled image to its original state.
Instance Fields
constructor: ImageConstructor
Events
imagebufferrealloc: CustomEvent
Buffer reallocation event: internal-only signal (not part of imageEventNames) for a subclass to re-point any state aliased to the previous buffer instance, for example MaskImage's segment collection label map.
imagesliceshift: CustomEvent
Buffer slice-shift event: internal-only signal (not part of imageEventNames) for a subclass to replicate the same shift on any of its own buffer-aliased state, for example MaskImage's contour.
Properties
detail(object) — The event detail.
imagegeometrychange: CustomEvent
Image geometry change event.
Properties
detail(object) — The event detail.
appendframe: CustomEvent
Append frame event.
Properties
detail(object) — The event detail.
imagecontentchange: CustomEvent
Image content change event.
Properties
detail(object) — The event detail.