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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import type { Types } from '@cornerstonejs/core';
import { pointInShapeCallback } from '../../utilities';
import { triggerSegmentationDataModified } from '../../stateManagement/segmentation/triggerSegmentationEvents';
import { BoundsIJK } from '../../types';
export type ThresholdRangeOptions = {
upper: number;
lower: number;
boundsIJK: BoundsIJK;
overwrite: boolean;
};
/**
* It thresholds a segmentation volume based on a set of threshold values with
* respect to reference volumes.
* @param segmentationVolume - the segmentation volume to be modified
* @param referenceVolumes - the reference volumes to be used for thresholding
* @param options - the options for thresholding
* @returns segmented volume
*/
function thresholdVolumeByRange(
segmentationVolume: Types.IImageVolume,
referenceVolume: Types.IImageVolume,
options: ThresholdRangeOptions
): Types.IImageVolume {
const { scalarData, imageData: segmentationImageData } = segmentationVolume;
const { overwrite, boundsIJK, upper, lower } = options;
const { imageData } = referenceVolume;
const referenceValues = imageData.getPointData().getScalars().getData();
// set the segmentation to all zeros
if (overwrite) {
for (let i = 0; i < scalarData.length; i++) {
scalarData[i] = 0;
}
}
const callback = ({ index, pointIJK }) => {
const offset = imageData.computeOffsetIndex(pointIJK);
const value = referenceValues[offset];
if (value <= lower || value >= upper) {
return;
}
// Todo: make the segmentIndex a parameter
scalarData[index] = 1;
};
pointInShapeCallback(segmentationImageData, () => true, callback, boundsIJK);
triggerSegmentationDataModified(segmentationVolume.volumeId);
return segmentationVolume;
}
export default thresholdVolumeByRange;
|