All files / packages/streaming-image-volume-loader/src/helpers scaleArray.ts

0% Statements 0/10
0% Branches 0/4
0% Functions 0/1
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                                                         
import type { Types } from '@cornerstonejs/core';
 
/**
 * Given a pixel array, rescale the pixel values using the rescale slope and
 * intercept and if modality is PT it uses the suv values to scale the array
 * @param array - The array to be scaled.
 * @param scalingParameters - The scaling parameters
 * @returns The array is being scaled
 */
export default function scaleArray(
  array: Float32Array | Uint8Array | Uint16Array | Int16Array,
  scalingParameters: Types.ScalingParameters
): Float32Array | Uint8Array | Uint16Array | Int16Array {
  const arrayLength = array.length;
  const { rescaleSlope, rescaleIntercept, suvbw } = scalingParameters;
 
  if (scalingParameters.modality === 'PT' && typeof suvbw === 'number') {
    for (let i = 0; i < arrayLength; i++) {
      array[i] = suvbw * (array[i] * rescaleSlope + rescaleIntercept);
    }
  } else {
    for (let i = 0; i < arrayLength; i++) {
      array[i] = array[i] * rescaleSlope + rescaleIntercept;
    }
  }
 
  return array;
}