cornerstonetools-thresholdbrush
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "cornerstonetools-thresholdbrush", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A brush tool that allows you to set a low and high threshold range in HU units while drawing segmentations.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
// This tool extends the default brush tool to allow for a threshold value to be set using hounsfield units with a low and high values. The threshold decides if the brush should paint the pixel or not. | ||
import cornerstoneTools from "cornerstone-tools"; | ||
import cornerstone from "cornerstone-core"; | ||
import cornerstoneTools from "cornerstone-tools" | ||
import cornerstone from "cornerstone-core" | ||
const { drawBrushPixels, getCircle } = cornerstoneTools.import( | ||
"util/segmentationUtils" | ||
); | ||
const segmentationModule = cornerstoneTools.getModule("segmentation"); | ||
const BaseBrushTool = cornerstoneTools.import("base/BaseBrushTool"); | ||
const { drawBrushPixels, getCircle } = cornerstoneTools.import('util/segmentationUtils'); | ||
const segmentationModule = cornerstoneTools.getModule("segmentation") | ||
const BaseBrushTool = cornerstoneTools.import("base/BaseBrushTool") | ||
/** | ||
@@ -23,60 +22,65 @@ * @public | ||
export class ThresholdBrushTool extends BaseBrushTool { | ||
constructor(props = {}) { | ||
const defaultProps = { | ||
name: 'ThresholdBrush', | ||
supportedInteractionTypes: ['Mouse'], | ||
configuration: { | ||
thresholdLow: 200, | ||
thresholdHigh: 1000, | ||
}, | ||
mixins: ['renderBrushMixin'], | ||
}; | ||
constructor(props = {}) { | ||
const defaultProps = { | ||
name: "ThresholdBrush", | ||
supportedInteractionTypes: ["Mouse"], | ||
configuration: { | ||
thresholdLow: 200, | ||
thresholdHigh: 1000, | ||
}, | ||
mixins: ["renderBrushMixin"], | ||
}; | ||
super(props, defaultProps); | ||
super(props, defaultProps); | ||
} | ||
} | ||
/** | ||
* Paints the data to the labelmap if the mouse is down and the pixel is in the threshold low and high values range. | ||
* @protected | ||
* @param {Object} | ||
* @returns {void} | ||
*/ | ||
_paint(evt) { | ||
const { configuration } = segmentationModule; | ||
const toolConfiguration = this.configuration; | ||
const eventData = evt.detail; | ||
const element = eventData.element; | ||
const { rows, columns } = eventData.image; | ||
const { x, y } = eventData.currentPoints.image; | ||
/** | ||
* Paints the data to the labelmap if the mouse is down and the pixel is in the threshold low and high values range. | ||
* @protected | ||
* @param {Object} | ||
* @returns {void} | ||
*/ | ||
_paint(evt) { | ||
const { configuration } = segmentationModule; | ||
const toolConfiguration = this.configuration; | ||
const eventData = evt.detail; | ||
const element = eventData.element; | ||
const { rows, columns } = eventData.image; | ||
const { x, y } = eventData.currentPoints.image; | ||
if (x < 0 || x > columns || y < 0 || y > rows) { | ||
return; | ||
} | ||
// check if the pixel is in the threshold range | ||
const radius = configuration.radius; | ||
const pointerArray = getCircle(radius, rows, columns, x, y); | ||
// loop over the pixels in the circle and eliminate any that are outside the threshold range | ||
const thresholdedPointerArray = pointerArray.filter((pointer) => { | ||
const storedPixel = cornerstone.getStoredPixels(element, pointer[0], pointer[1], 1, 1); | ||
const hounsfieldValue = storedPixel[0] * eventData.image.slope + eventData.image.intercept; | ||
return hounsfieldValue >= toolConfiguration.thresholdLow && hounsfieldValue <= toolConfiguration.thresholdHigh; | ||
}); | ||
const { labelmap2D, labelmap3D, shouldErase } = this.paintEventData; | ||
// Draw / Erase the active color. | ||
drawBrushPixels( | ||
thresholdedPointerArray, | ||
labelmap2D.pixelData, | ||
labelmap3D.activeSegmentIndex, | ||
columns, | ||
shouldErase | ||
); | ||
cornerstone.updateImage(evt.detail.element); | ||
} | ||
if (x < 0 || x > columns || y < 0 || y > rows) { | ||
return; | ||
} | ||
// check if the pixel is in the threshold range | ||
const radius = configuration.radius; | ||
const pointerArray = getCircle(radius, rows, columns, x, y); | ||
// loop over the pixels in the circle and eliminate any that are outside the threshold range | ||
const thresholdedPointerArray = pointerArray.filter((pointer) => { | ||
const storedPixel = cornerstone.getStoredPixels( | ||
element, | ||
pointer[0], | ||
pointer[1], | ||
1, | ||
1 | ||
); | ||
const hounsfieldValue = | ||
storedPixel[0] * eventData.image.slope + eventData.image.intercept; | ||
return ( | ||
hounsfieldValue >= toolConfiguration.thresholdLow && | ||
hounsfieldValue <= toolConfiguration.thresholdHigh | ||
); | ||
}); | ||
const { labelmap2D, labelmap3D, shouldErase } = this.paintEventData; | ||
// Draw / Erase the active color. | ||
drawBrushPixels( | ||
thresholdedPointerArray, | ||
labelmap2D.pixelData, | ||
labelmap3D.activeSegmentIndex, | ||
columns, | ||
shouldErase | ||
); | ||
cornerstone.updateImage(evt.detail.element); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76
4759